* [patch] v2.5.31 nfsctl.c stack usage reduction
@ 2002-08-15 21:31 Benjamin LaHaise
2002-08-19 0:49 ` Rusty Russell
0 siblings, 1 reply; 2+ messages in thread
From: Benjamin LaHaise @ 2002-08-15 21:31 UTC (permalink / raw)
To: Linus Torvalds, Linux Kernel, trond.myklebust
Heyo,
The patch below (which depends on the copy_from_user_kmalloc addition)
reduces the stack usage in nfsctl.c, which was allocating structures that
were 2KB or more on the stack.
-ben
:r ~/patches/v2.5/v2.5.31-stack-nfs.diff
diff -urN foo-v2.5.31/fs/nfsd/nfsctl.c bar-v2.5.31/fs/nfsd/nfsctl.c
--- foo-v2.5.31/fs/nfsd/nfsctl.c Tue Jul 30 10:24:17 2002
+++ bar-v2.5.31/fs/nfsd/nfsctl.c Thu Aug 15 17:26:09 2002
@@ -155,56 +155,47 @@
* payload - write methods
*/
+/* Rather than duplicate this many times, just use a funky macro. */
+#define WRITE_METHOD(type, fn) \
+ type *data; \
+ ssize_t ret; \
+ if (size < sizeof(*data)) \
+ return -EINVAL; \
+ data = copy_from_user_kmalloc(buf, size);\
+ if (IS_ERR(data)) \
+ return PTR_ERR(data); \
+ ret = fn; \
+ kfree(data); \
+ return ret;
+
static ssize_t write_svc(struct file *file, const char *buf, size_t size)
{
- struct nfsctl_svc data;
- if (size < sizeof(data))
- return -EINVAL;
- if (copy_from_user(&data, buf, size))
- return -EFAULT;
- return nfsd_svc(data.svc_port, data.svc_nthreads);
+ WRITE_METHOD(struct nfsctl_svc,
+ nfsd_svc(data->svc_port, data->svc_nthreads));
}
static ssize_t write_add(struct file *file, const char *buf, size_t size)
{
- struct nfsctl_client data;
- if (size < sizeof(data))
- return -EINVAL;
- if (copy_from_user(&data, buf, size))
- return -EFAULT;
- return exp_addclient(&data);
+ WRITE_METHOD(struct nfsctl_client, exp_addclient(data));
}
static ssize_t write_del(struct file *file, const char *buf, size_t size)
{
- struct nfsctl_client data;
- if (size < sizeof(data))
- return -EINVAL;
- if (copy_from_user(&data, buf, size))
- return -EFAULT;
- return exp_delclient(&data);
+ WRITE_METHOD(struct nfsctl_client, exp_delclient(data));
}
static ssize_t write_export(struct file *file, const char *buf, size_t size)
{
- struct nfsctl_export data;
- if (size < sizeof(data))
- return -EINVAL;
- if (copy_from_user(&data, buf, size))
- return -EFAULT;
- return exp_export(&data);
+ WRITE_METHOD(struct nfsctl_export, exp_export(data));
}
static ssize_t write_unexport(struct file *file, const char *buf, size_t size)
{
- struct nfsctl_export data;
- if (size < sizeof(data))
- return -EINVAL;
- if (copy_from_user(&data, buf, size))
- return -EFAULT;
- return exp_unexport(&data);
+ WRITE_METHOD(struct nfsctl_export, exp_unexport(data));
}
+#undef WRITE_METHOD
+
static ssize_t write_getfs(struct file *file, const char *buf, size_t size)
{
struct nfsctl_fsparm data;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] v2.5.31 nfsctl.c stack usage reduction
2002-08-15 21:31 [patch] v2.5.31 nfsctl.c stack usage reduction Benjamin LaHaise
@ 2002-08-19 0:49 ` Rusty Russell
0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2002-08-19 0:49 UTC (permalink / raw)
To: Benjamin LaHaise; +Cc: torvalds, linux-kernel, trond.myklebust
On Thu, 15 Aug 2002 17:31:36 -0400
Benjamin LaHaise <bcrl@redhat.com> wrote:
> Heyo,
>
> The patch below (which depends on the copy_from_user_kmalloc addition)
> reduces the stack usage in nfsctl.c, which was allocating structures that
> were 2KB or more on the stack.
>
> -ben
>
> :r ~/patches/v2.5/v2.5.31-stack-nfs.diff
> diff -urN foo-v2.5.31/fs/nfsd/nfsctl.c bar-v2.5.31/fs/nfsd/nfsctl.c
> --- foo-v2.5.31/fs/nfsd/nfsctl.c Tue Jul 30 10:24:17 2002
> +++ bar-v2.5.31/fs/nfsd/nfsctl.c Thu Aug 15 17:26:09 2002
> @@ -155,56 +155,47 @@
> * payload - write methods
> */
>
> +/* Rather than duplicate this many times, just use a funky macro. */
> +#define WRITE_METHOD(type, fn) \
> + type *data; \
> + ssize_t ret; \
> + if (size < sizeof(*data)) \
> + return -EINVAL; \
> + data = copy_from_user_kmalloc(buf, size);\
> + if (IS_ERR(data)) \
> + return PTR_ERR(data); \
> + ret = fn; \
> + kfree(data); \
> + return ret;
> +
One tiny request: make the macro an expression statement, and then use it
as "return WRITE_METHOD(xxx, yyy)".
Or even an inline function taking void * and a size.
Let's not encourage people to do returns in macros 8)
Thanks!
Rusty.
--
there are those who do and those who hang on and you don't see too
many doers quoting their contemporaries. -- Larry McVoy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-08-19 3:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-15 21:31 [patch] v2.5.31 nfsctl.c stack usage reduction Benjamin LaHaise
2002-08-19 0:49 ` Rusty Russell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).