xfs
[Top] [All Lists]

[PATCH] vfs: reduce stack usage by shrinking struct kiocb

To: David Chinner <dgc@xxxxxxx>, Benjamin LaHaise <bcrl@xxxxxxxxx>
Subject: [PATCH] vfs: reduce stack usage by shrinking struct kiocb
From: Denys Vlasenko <vda.linux@xxxxxxxxxxxxxx>
Date: Sun, 27 Apr 2008 06:17:36 +0200
Cc: xfs@xxxxxxxxxxx, Eric Sandeen <sandeen@xxxxxxxxxxx>, Adrian Bunk <bunk@xxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, linux-fsdevel@xxxxxxxxxxxxxxx, linux-aio@xxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date:user-agent:cc:mime-version:content-type:message-id; bh=vcncnvh0vCh4m3ow4+Np4epm27zLs1mLtyHNGspy4Lw=; b=VvwtU1XyXnmiKuyJER1trXntVwei+u4f4l1FpNffICOYPKytjTZPlUO51NiIkhVj5fNxvGWN1vye14fryXt07YE+DlCYOcv46AehOofbkCOjYmwMIwd5FjC/jpPE2VpUQmKd3llt9iWmaIeTdN/z7hKYuRz4fMU66cJTslK73Ns=
Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:subject:date:user-agent:cc:mime-version:content-type:message-id; b=XEqf1WUZ/rm4CLkC7kNg1dD9YR4HxO1nQqT+KtWf+yYXZs0PZwx7rsDWyFv99ZOXOUBFruraGs+YAbpJjyfi4DQYB11vphwn8Be3vJHw2Q+DEFCPL++KKV3JAwKRLiDK7UHajGrGiswhvZmEoO+ICBETPiEXNm9PstbHo5/NjOA=
Sender: xfs-bounce@xxxxxxxxxxx
User-agent: KMail/1.8.2
Hi Al, Benjamin, David,

struct kiocb is placed on stack by, for example, do_sync_write().
Eventually it contributes to xfs writeout path's stack usage, among others.
This is *the* path which causes 4k stack overflows on i386 with xfs.

This patch trivially reorders fields of this structure,
and makes some of them smaller.

Reordering helps 64-bit architectures:
int, void*, int, void* - bad,
int, int, void*, void* - better.

These fields are made smaller:
ki_flags: long -> short: possible values are 0,1,2, so short is enough.
ki_nr_segs: ulong -> uint: nobody uses 4 billion element writev's
                           (and it would not work anyway)
ki_cur_seg: same

For 32bit x86, it makes this struct only 4 bytes smaller.
This isn't much, but it helps not only xfs, but all filesystems.

For 64-bit case savings are a bit more significant,
as ulong -> uint actually makes a difference, and reordering
of 64-bit fields eliminates some padding.

Only compile tested. Observed stack reductions on 32 bits:

-sock_recvmsg [vmlinux]:                        196
-sock_sendmsg [vmlinux]:                        196
+sock_recvmsg [vmlinux]:                        192
+sock_sendmsg [vmlinux]:                        192
-do_sync_write [vmlinux]:                       140
-do_sync_read [vmlinux]:                        140
+do_sync_write [vmlinux]:                       136
+do_sync_read [vmlinux]:                        136
-do_sync_readv_writev [vmlinux]:                132
+do_sync_readv_writev [vmlinux]:                128

Signed-off-by: Denys Vlasenko <vda.linux@xxxxxxxxxxxxxx>
--
vda

Attachment: stk4.diff
Description: Text Data

<Prev in Thread] Current Thread [Next in Thread>