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) ...@@ -103,22 +103,16 @@ nfs_readpage_sync(struct file *file, struct inode *inode, struct page *page)
if (!rdata) if (!rdata)
return -ENOMEM; return -ENOMEM;
*rdata = (struct nfs_read_data) { memset(rdata, 0, sizeof(*rdata));
.flags = (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0), rdata->flags = (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
.cred = NULL, rdata->inode = inode;
.inode = inode, INIT_LIST_HEAD(&rdata->pages);
.pages = LIST_HEAD_INIT(rdata->pages), rdata->args.fh = NFS_FH(inode);
.args = { rdata->args.lockowner = current->files;
.fh = NFS_FH(inode), rdata->args.pages = &page;
.lockowner = current->files, rdata->args.pgbase = 0UL;
.pages = &page, rdata->args.count = rsize;
.pgbase = 0UL, rdata->res.fattr = &rdata->fattr;
.count = rsize,
},
.res = {
.fattr = &rdata->fattr,
}
};
dprintk("NFS: nfs_readpage_sync(%p)\n", page); dprintk("NFS: nfs_readpage_sync(%p)\n", page);
......
...@@ -185,23 +185,17 @@ static int nfs_writepage_sync(struct file *file, struct inode *inode, ...@@ -185,23 +185,17 @@ static int nfs_writepage_sync(struct file *file, struct inode *inode,
if (!wdata) if (!wdata)
return -ENOMEM; return -ENOMEM;
*wdata = (struct nfs_write_data) { memset(wdata, 0, sizeof(*wdata));
.flags = how, wdata->flags = how;
.cred = NULL, wdata->inode = inode;
.inode = inode, wdata->args.fh = NFS_FH(inode);
.args = { wdata->args.lockowner = current->files;
.fh = NFS_FH(inode), wdata->args.pages = &page;
.lockowner = current->files, wdata->args.stable = NFS_FILE_SYNC;
.pages = &page, wdata->args.pgbase = offset;
.stable = NFS_FILE_SYNC, wdata->args.count = wsize;
.pgbase = offset, wdata->res.fattr = &wdata->fattr;
.count = wsize, wdata->res.verf = &wdata->verf;
},
.res = {
.fattr = &wdata->fattr,
.verf = &wdata->verf,
},
};
dprintk("NFS: nfs_writepage_sync(%s/%Ld %d@%Ld)\n", dprintk("NFS: nfs_writepage_sync(%s/%Ld %d@%Ld)\n",
inode->i_sb->s_id, 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