Commit b670ef77 authored by Peter Osterlund's avatar Peter Osterlund Committed by Linus Torvalds

[PATCH] Avoid excessive stack usage in NFS

Assigning '*wdata' with a dynamic initializer creates a
temporary structure copy on the stack, and then the final
data is initialized with a "memcpy()".

As a result, these NFS functions use more than 800 bytes
of stack-space.

Changing the code to just do a memset followed by explicit
initialization of the non-zero member variables takes the
stack usage down to 36 bytes. 

Here is a patch that does exactly that.
parent 345a8472
......@@ -103,22 +103,16 @@ nfs_readpage_sync(struct file *file, struct inode *inode, struct page *page)
if (!rdata)
return -ENOMEM;
*rdata = (struct nfs_read_data) {
.flags = (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0),
.cred = NULL,
.inode = inode,
.pages = LIST_HEAD_INIT(rdata->pages),
.args = {
.fh = NFS_FH(inode),
.lockowner = current->files,
.pages = &page,
.pgbase = 0UL,
.count = rsize,
},
.res = {
.fattr = &rdata->fattr,
}
};
memset(rdata, 0, sizeof(*rdata));
rdata->flags = (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
rdata->inode = inode;
INIT_LIST_HEAD(&rdata->pages);
rdata->args.fh = NFS_FH(inode);
rdata->args.lockowner = current->files;
rdata->args.pages = &page;
rdata->args.pgbase = 0UL;
rdata->args.count = rsize;
rdata->res.fattr = &rdata->fattr;
dprintk("NFS: nfs_readpage_sync(%p)\n", page);
......
......@@ -185,23 +185,17 @@ static int nfs_writepage_sync(struct file *file, struct inode *inode,
if (!wdata)
return -ENOMEM;
*wdata = (struct nfs_write_data) {
.flags = how,
.cred = NULL,
.inode = inode,
.args = {
.fh = NFS_FH(inode),
.lockowner = current->files,
.pages = &page,
.stable = NFS_FILE_SYNC,
.pgbase = offset,
.count = wsize,
},
.res = {
.fattr = &wdata->fattr,
.verf = &wdata->verf,
},
};
memset(wdata, 0, sizeof(*wdata));
wdata->flags = how;
wdata->inode = inode;
wdata->args.fh = NFS_FH(inode);
wdata->args.lockowner = current->files;
wdata->args.pages = &page;
wdata->args.stable = NFS_FILE_SYNC;
wdata->args.pgbase = offset;
wdata->args.count = wsize;
wdata->res.fattr = &wdata->fattr;
wdata->res.verf = &wdata->verf;
dprintk("NFS: nfs_writepage_sync(%s/%Ld %d@%Ld)\n",
inode->i_sb->s_id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment