Skip to content

Commit 05258a0

Browse files
committed
SUNRPC: Fix a slow server-side memory leak with RPC-over-TCP
Jan Schunk reports that his small NFS servers suffer from memory exhaustion after just a few days. A bisect shows that commit e18e157 ("SUNRPC: Send RPC message on TCP with a single sock_sendmsg() call") is the first bad commit. That commit assumed that sock_sendmsg() releases all the pages in the underlying bio_vec array, but the reality is that it doesn't. svc_xprt_release() releases the rqst's response pages, but the record marker page fragment isn't one of those, so it is never released. This is a narrow fix that can be applied to stable kernels. A more extensive fix is in the works. Reported-by: Jan Schunk <[email protected]> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218671 Fixes: e18e157 ("SUNRPC: Send RPC message on TCP with a single sock_sendmsg() call") Cc: Alexander Duyck <[email protected]> Cc: Jakub Kacinski <[email protected]> Cc: David Howells <[email protected]> Reviewed-by: David Howells <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 99dc2ef commit 05258a0

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

net/sunrpc/svcsock.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,15 +1206,6 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
12061206
* MSG_SPLICE_PAGES is used exclusively to reduce the number of
12071207
* copy operations in this path. Therefore the caller must ensure
12081208
* that the pages backing @xdr are unchanging.
1209-
*
1210-
* Note that the send is non-blocking. The caller has incremented
1211-
* the reference count on each page backing the RPC message, and
1212-
* the network layer will "put" these pages when transmission is
1213-
* complete.
1214-
*
1215-
* This is safe for our RPC services because the memory backing
1216-
* the head and tail components is never kmalloc'd. These always
1217-
* come from pages in the svc_rqst::rq_pages array.
12181209
*/
12191210
static int svc_tcp_sendmsg(struct svc_sock *svsk, struct svc_rqst *rqstp,
12201211
rpc_fraghdr marker, unsigned int *sentp)
@@ -1244,6 +1235,7 @@ static int svc_tcp_sendmsg(struct svc_sock *svsk, struct svc_rqst *rqstp,
12441235
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, rqstp->rq_bvec,
12451236
1 + count, sizeof(marker) + rqstp->rq_res.len);
12461237
ret = sock_sendmsg(svsk->sk_sock, &msg);
1238+
page_frag_free(buf);
12471239
if (ret < 0)
12481240
return ret;
12491241
*sentp += ret;

0 commit comments

Comments
 (0)