[PATCH] knfsd: Avoid excess stack usage in svc_tcp_recvfrom
authorNeilBrown <neilb@suse.de>
Wed, 4 Oct 2006 09:15:47 +0000 (02:15 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Wed, 4 Oct 2006 14:55:15 +0000 (07:55 -0700)
..  by allocating the array of 'kvec' in 'struct svc_rqst'.

As we plan to increase RPCSVC_MAXPAGES from 8 upto 256, we can no longer
allocate an array of this size on the stack.  So we allocate it in 'struct
svc_rqst'.

However svc_rqst contains (indirectly) an array of the same type and size
(actually several, but they are in a union).  So rather than waste space, we
move those arrays out of the separately allocated union and into svc_rqst to
share with the kvec moved out of svc_tcp_recvfrom (various arrays are used at
different times, so there is no conflict).

Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
fs/nfsd/nfs3proc.c
fs/nfsd/nfs3xdr.c
fs/nfsd/nfs4proc.c
fs/nfsd/nfs4xdr.c
fs/nfsd/nfsproc.c
fs/nfsd/nfsxdr.c
include/linux/nfsd/xdr.h
include/linux/nfsd/xdr3.h
include/linux/nfsd/xdr4.h
include/linux/sunrpc/svc.h
net/sunrpc/svcsock.c

index f61142afea4490f5ebe542fe7ff167bf15a9564b..0c4fab018791e4159a24733e3480432d8b452a90 100644 (file)
@@ -180,7 +180,7 @@ nfsd3_proc_read(struct svc_rqst *rqstp, struct nfsd3_readargs *argp,
        fh_copy(&resp->fh, &argp->fh);
        nfserr = nfsd_read(rqstp, &resp->fh, NULL,
                                  argp->offset,
-                                 argp->vec, argp->vlen,
+                                 rqstp->rq_vec, argp->vlen,
                                  &resp->count);
        if (nfserr == 0) {
                struct inode    *inode = resp->fh.fh_dentry->d_inode;
@@ -210,7 +210,7 @@ nfsd3_proc_write(struct svc_rqst *rqstp, struct nfsd3_writeargs *argp,
        resp->committed = argp->stable;
        nfserr = nfsd_write(rqstp, &resp->fh, NULL,
                                   argp->offset,
-                                  argp->vec, argp->vlen,
+                                  rqstp->rq_vec, argp->vlen,
                                   argp->len,
                                   &resp->committed);
        resp->count = argp->count;
index 20ba728a46426b159f190f1af92958c3d11ec908..4b9aefbcc93c5e857185560c5ed7f0beeadd6f60 100644 (file)
@@ -344,9 +344,9 @@ nfs3svc_decode_readargs(struct svc_rqst *rqstp, u32 *p,
        v=0;
        while (len > 0) {
                pn = rqstp->rq_resused++;
-               args->vec[v].iov_base = page_address(rqstp->rq_respages[pn]);
-               args->vec[v].iov_len = len < PAGE_SIZE? len : PAGE_SIZE;
-               len -= args->vec[v].iov_len;
+               rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_respages[pn]);
+               rqstp->rq_vec[v].iov_len = len < PAGE_SIZE? len : PAGE_SIZE;
+               len -= rqstp->rq_vec[v].iov_len;
                v++;
        }
        args->vlen = v;
@@ -372,22 +372,22 @@ nfs3svc_decode_writeargs(struct svc_rqst *rqstp, u32 *p,
            rqstp->rq_arg.len - hdr < len)
                return 0;
 
-       args->vec[0].iov_base = (void*)p;
-       args->vec[0].iov_len = rqstp->rq_arg.head[0].iov_len - hdr;
+       rqstp->rq_vec[0].iov_base = (void*)p;
+       rqstp->rq_vec[0].iov_len = rqstp->rq_arg.head[0].iov_len - hdr;
 
        if (len > NFSSVC_MAXBLKSIZE)
                len = NFSSVC_MAXBLKSIZE;
        v=  0;
-       while (len > args->vec[v].iov_len) {
-               len -= args->vec[v].iov_len;
+       while (len > rqstp->rq_vec[v].iov_len) {
+               len -= rqstp->rq_vec[v].iov_len;
                v++;
-               args->vec[v].iov_base = page_address(rqstp->rq_pages[v]);
-               args->vec[v].iov_len = PAGE_SIZE;
+               rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_pages[v]);
+               rqstp->rq_vec[v].iov_len = PAGE_SIZE;
        }
-       args->vec[v].iov_len = len;
+       rqstp->rq_vec[v].iov_len = len;
        args->vlen = v+1;
 
-       return args->count == args->len && args->vec[0].iov_len > 0;
+       return args->count == args->len && rqstp->rq_vec[0].iov_len > 0;
 }
 
 int
index 15ded7a30a72dcf4426b0e45c13c6a45395f6505..38b0f91175d0d3a03f7eb3d902d27b45cff9c527 100644 (file)
@@ -646,7 +646,7 @@ nfsd4_write(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_writ
        *p++ = nfssvc_boot.tv_usec;
 
        status =  nfsd_write(rqstp, current_fh, filp, write->wr_offset,
-                       write->wr_vec, write->wr_vlen, write->wr_buflen,
+                       rqstp->rq_vec, write->wr_vlen, write->wr_buflen,
                        &write->wr_how_written);
        if (filp)
                fput(filp);
index 9f30c53ac0ed4e74351f5d332e631c14d849da65..df341956254eabc38fed4ce62f85e1e49e0c8ced 100644 (file)
@@ -926,26 +926,26 @@ nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write)
                printk(KERN_NOTICE "xdr error! (%s:%d)\n", __FILE__, __LINE__); 
                goto xdr_error;
        }
-       write->wr_vec[0].iov_base = p;
-       write->wr_vec[0].iov_len = avail;
+       argp->rqstp->rq_vec[0].iov_base = p;
+       argp->rqstp->rq_vec[0].iov_len = avail;
        v = 0;
        len = write->wr_buflen;
-       while (len > write->wr_vec[v].iov_len) {
-               len -= write->wr_vec[v].iov_len;
+       while (len > argp->rqstp->rq_vec[v].iov_len) {
+               len -= argp->rqstp->rq_vec[v].iov_len;
                v++;
-               write->wr_vec[v].iov_base = page_address(argp->pagelist[0]);
+               argp->rqstp->rq_vec[v].iov_base = page_address(argp->pagelist[0]);
                argp->pagelist++;
                if (argp->pagelen >= PAGE_SIZE) {
-                       write->wr_vec[v].iov_len = PAGE_SIZE;
+                       argp->rqstp->rq_vec[v].iov_len = PAGE_SIZE;
                        argp->pagelen -= PAGE_SIZE;
                } else {
-                       write->wr_vec[v].iov_len = argp->pagelen;
+                       argp->rqstp->rq_vec[v].iov_len = argp->pagelen;
                        argp->pagelen -= len;
                }
        }
-       argp->end = (u32*) (write->wr_vec[v].iov_base + write->wr_vec[v].iov_len);
-       argp->p = (u32*)  (write->wr_vec[v].iov_base + (XDR_QUADLEN(len) << 2));
-       write->wr_vec[v].iov_len = len;
+       argp->end = (u32*) (argp->rqstp->rq_vec[v].iov_base + argp->rqstp->rq_vec[v].iov_len);
+       argp->p = (u32*)  (argp->rqstp->rq_vec[v].iov_base + (XDR_QUADLEN(len) << 2));
+       argp->rqstp->rq_vec[v].iov_len = len;
        write->wr_vlen = v+1;
 
        DECODE_TAIL;
@@ -2063,9 +2063,9 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, int nfserr,
        v = 0;
        while (len > 0) {
                pn = resp->rqstp->rq_resused++;
-               read->rd_iov[v].iov_base =
+               resp->rqstp->rq_vec[v].iov_base =
                        page_address(resp->rqstp->rq_respages[pn]);
-               read->rd_iov[v].iov_len =
+               resp->rqstp->rq_vec[v].iov_len =
                        len < PAGE_SIZE ? len : PAGE_SIZE;
                v++;
                len -= PAGE_SIZE;
@@ -2073,7 +2073,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, int nfserr,
        read->rd_vlen = v;
 
        nfserr = nfsd_read(read->rd_rqstp, read->rd_fhp, read->rd_filp,
-                       read->rd_offset, read->rd_iov, read->rd_vlen,
+                       read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen,
                        &maxcount);
 
        if (nfserr == nfserr_symlink)
index 4e06810b6104a684e69874fc54479ea1e4a7ed22..ca4973150218fba4f282914377efa17d68bd5a6e 100644 (file)
@@ -159,7 +159,7 @@ nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp,
        resp->count = argp->count;
        nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
                                  argp->offset,
-                                 argp->vec, argp->vlen,
+                                 rqstp->rq_vec, argp->vlen,
                                  &resp->count);
 
        if (nfserr) return nfserr;
@@ -185,7 +185,7 @@ nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp,
 
        nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
                                   argp->offset,
-                                  argp->vec, argp->vlen,
+                                  rqstp->rq_vec, argp->vlen,
                                   argp->len,
                                   &stable);
        return nfsd_return_attrs(nfserr, resp);
index ad2fba3c54f8af46e05dfecf7378f4515c45e6ba..ab6745e78d16d4cb6dff67796d8a78e59999cd61 100644 (file)
@@ -263,9 +263,9 @@ nfssvc_decode_readargs(struct svc_rqst *rqstp, u32 *p,
        v=0;
        while (len > 0) {
                pn = rqstp->rq_resused++;
-               args->vec[v].iov_base = page_address(rqstp->rq_respages[pn]);
-               args->vec[v].iov_len = len < PAGE_SIZE?len:PAGE_SIZE;
-               len -= args->vec[v].iov_len;
+               rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_respages[pn]);
+               rqstp->rq_vec[v].iov_len = len < PAGE_SIZE?len:PAGE_SIZE;
+               len -= rqstp->rq_vec[v].iov_len;
                v++;
        }
        args->vlen = v;
@@ -285,21 +285,21 @@ nfssvc_decode_writeargs(struct svc_rqst *rqstp, u32 *p,
        args->offset = ntohl(*p++);     /* offset */
        p++;                            /* totalcount */
        len = args->len = ntohl(*p++);
-       args->vec[0].iov_base = (void*)p;
-       args->vec[0].iov_len = rqstp->rq_arg.head[0].iov_len -
+       rqstp->rq_vec[0].iov_base = (void*)p;
+       rqstp->rq_vec[0].iov_len = rqstp->rq_arg.head[0].iov_len -
                                (((void*)p) - rqstp->rq_arg.head[0].iov_base);
        if (len > NFSSVC_MAXBLKSIZE)
                len = NFSSVC_MAXBLKSIZE;
        v = 0;
-       while (len > args->vec[v].iov_len) {
-               len -= args->vec[v].iov_len;
+       while (len > rqstp->rq_vec[v].iov_len) {
+               len -= rqstp->rq_vec[v].iov_len;
                v++;
-               args->vec[v].iov_base = page_address(rqstp->rq_pages[v]);
-               args->vec[v].iov_len = PAGE_SIZE;
+               rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_pages[v]);
+               rqstp->rq_vec[v].iov_len = PAGE_SIZE;
        }
-       args->vec[v].iov_len = len;
+       rqstp->rq_vec[v].iov_len = len;
        args->vlen = v+1;
-       return args->vec[0].iov_len > 0;
+       return rqstp->rq_vec[0].iov_len > 0;
 }
 
 int
index a38f9d776de9b34c7e19cbd8c2aefb103f4d5f39..0e53de87d886216f4f9478ce8bfde9c581b9c881 100644 (file)
@@ -30,7 +30,6 @@ struct nfsd_readargs {
        struct svc_fh           fh;
        __u32                   offset;
        __u32                   count;
-       struct kvec             vec[RPCSVC_MAXPAGES];
        int                     vlen;
 };
 
@@ -38,7 +37,6 @@ struct nfsd_writeargs {
        svc_fh                  fh;
        __u32                   offset;
        int                     len;
-       struct kvec             vec[RPCSVC_MAXPAGES];
        int                     vlen;
 };
 
index a4322741f8b9d4ec85a80d8bbc69a04d401ba796..474d882dc2f385839a7b1cf869591a2f807a22f7 100644 (file)
@@ -33,7 +33,6 @@ struct nfsd3_readargs {
        struct svc_fh           fh;
        __u64                   offset;
        __u32                   count;
-       struct kvec             vec[RPCSVC_MAXPAGES];
        int                     vlen;
 };
 
@@ -43,7 +42,6 @@ struct nfsd3_writeargs {
        __u32                   count;
        int                     stable;
        __u32                   len;
-       struct kvec             vec[RPCSVC_MAXPAGES];
        int                     vlen;
 };
 
index 77adba7d228105fa1fd0f7fde49720814d92ca55..66e642762a0720e609ef0dcc09a648c511de7c43 100644 (file)
@@ -241,7 +241,6 @@ struct nfsd4_read {
        stateid_t       rd_stateid;         /* request */
        u64             rd_offset;          /* request */
        u32             rd_length;          /* request */
-       struct kvec     rd_iov[RPCSVC_MAXPAGES];
        int             rd_vlen;
        struct file     *rd_filp;
        
@@ -326,7 +325,6 @@ struct nfsd4_write {
        u64             wr_offset;          /* request */
        u32             wr_stable_how;      /* request */
        u32             wr_buflen;          /* request */
-       struct kvec     wr_vec[RPCSVC_MAXPAGES]; /* request */
        int             wr_vlen;
 
        u32             wr_bytes_written;   /* response */
index 3669e91c43b8b45558abd426d138ca4a9e4c73d6..cb0ed9beb22726b92ef623d4831a73c902244035 100644 (file)
@@ -192,6 +192,8 @@ struct svc_rqst {
        struct page *           *rq_respages;   /* points into rq_pages */
        int                     rq_resused;     /* number of pages used for result */
 
+       struct kvec             rq_vec[RPCSVC_MAXPAGES]; /* generally useful.. */
+
        __be32                  rq_xid;         /* transmission id */
        u32                     rq_prog;        /* program number */
        u32                     rq_vers;        /* program version */
index 25096d53667adc8cbb5fe229103de3b19f0ee985..1d512337ccd936676606629523e7145c4cbff378 100644 (file)
@@ -955,7 +955,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
        struct svc_sock *svsk = rqstp->rq_sock;
        struct svc_serv *serv = svsk->sk_server;
        int             len;
-       struct kvec vec[RPCSVC_MAXPAGES];
+       struct kvec *vec;
        int pnum, vlen;
 
        dprintk("svc: tcp_recv %p data %d conn %d close %d\n",
@@ -1053,6 +1053,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
        len = svsk->sk_reclen;
        set_bit(SK_DATA, &svsk->sk_flags);
 
+       vec = rqstp->rq_vec;
        vec[0] = rqstp->rq_arg.head[0];
        vlen = PAGE_SIZE;
        pnum = 1;