SUNRPC: Avoid digging into the ATOMIC pool
Subsystems (3)
RFC PATCH 1/1 SUNRPC: Avoid digging into the ATOMIC pool
Page allocation requests made when the SPARSE_PAGES flag is set are allowed to fail, and are not critical. No need to spend a rare resource.
--- net/sunrpc/socklib.c | 2 +- net/sunrpc/xprtrdma/rpc_rdma.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/sunrpc/socklib.c +1 -1
@@ -106,7 +106,7 @@ static size_t xdr_skb_read_and_csum_bits(struct xdr_skb_reader *desc, void *to,/* ACL likes to be lazy in allocating pages - ACLs * are small by default but can get huge. */ if ((xdr->flags &XDRBUF_SPARSE_PAGES ) && *ppage ==NULL ) { - *ppage =alloc_page (GFP_ATOMIC ); + *ppage =alloc_page (GFP_NOWAIT | __GFP_NOWARN);if (unlikely (*ppage ==NULL )) {if (copied ==0 ) copied = -ENOMEM ;
net/sunrpc/xprtrdma/rpc_rdma.c +1 -1
@@ -238,7 +238,7 @@ static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,*/ if (unlikely (xdrbuf->flags &XDRBUF_SPARSE_PAGES )) {if (!*ppages) - *ppages =alloc_page (GFP_ATOMIC ); + *ppages =alloc_page (GFP_NOWAIT | __GFP_NOWARN);if (!*ppages)return -ENOBUFS ; }
Quoted 23 lines · Chuck Lever
Page allocation requests made when the
SPARSE_PAGESflag is set are allowed to fail, and are not critical. No need to spend a rare resource.Signed-off-by Chuck Lever <[email protected]>--- net/sunrpc/socklib.c | 2 +- net/sunrpc/xprtrdma/rpc_rdma.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)net/sunrpc/socklib.c +1
-1@@ -106,7 +106,7 @@ static size_t xdr_skb_read_and_csum_bits(struct xdr_skb_reader *desc, void *to,/* ACL likes to be lazy in allocating pages - ACLs * are small by default but can get huge. */ if ((xdr->flags & XDRBUF_SPARSE_PAGES) && *ppage == NULL) { - *ppage =alloc_page (GFP_ATOMIC ); + *ppage =alloc_page (GFP_NOWAIT | __GFP_NOWARN);if (unlikely (*ppage ==NULL )) {
net/sunrpc/socklib.c static size_t xdr_skb_read_and_csum_bits(struct xdr_skb_reader *desc, void *to, · line 112
Quoted 2 lines
net/sunrpc/socklib.c +0
-0if (copied ==0 ) copied = -ENOMEM ;
Hmm... Can't we make this GFP_KERNEL? I can't see that we're holding any locks here. It does look like svc_udp_recvfrom() is wrapping the call to csum_partial_copy_to_xdr() in a local_bh_disable()/enable() pair, but is that actually needed? If so, for what?
Quoted 15 lines
net/sunrpc/xprtrdma/rpc_rdma.c +1
-1@@ -238,7 +238,7 @@ static bool rpcrdma_results_inline(structrpcrdma_xprt *r_xprt, */ if (unlikely (xdrbuf->flags &XDRBUF_SPARSE_PAGES )) {if (!*ppages) - *ppages =alloc_page (GFP_ATOMIC ); + *ppages =alloc_page (GFP_NOWAIT | __GFP_NOWARN);if (!*ppages)
net/sunrpc/xprtrdma/rpc_rdma.c static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, · line 244
Quoted 2 lines
net/sunrpc/xprtrdma/rpc_rdma.c +0
-0return -ENOBUFS ; }
Cheers
Trond
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 25 lines · Trond Myklebust
Quoted 20 lines · Chuck Lever
Page allocation requests made when the
SPARSE_PAGESflag is set are allowed to fail, and are not critical. No need to spend a rare resource.Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/socklib.c | 2 +- net/sunrpc/xprtrdma/rpc_rdma.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)net/sunrpc/socklib.c +0
-0@@ -106,7 +106,7 @@ static size_t xdr_skb_read_and_csum_bits(struct xdr_skb_reader *desc, void *to,/* ACL likes to be lazy in allocating pages - ACLs * are small by default but can get huge. */ if ((xdr->flags & XDRBUF_SPARSE_PAGES) && *ppage == NULL) {
Quoted 8 lines
Quoted 5 lines
net/sunrpc/socklib.c +1
-1- *ppage =alloc_page (GFP_ATOMIC ); + *ppage =alloc_page (GFP_NOWAIT | __GFP_NOWARN);if (unlikely (*ppage ==NULL )) {if (copied == 0) copied = -ENOMEM;Hmm... Can't we make this
GFP_KERNEL? I can't see that we're holding any locks here.
We're holding the transport send lock. Since this is an order 0 allocation it's unlikely to fail even with a less aggressive request like NOWAIT.
Quoted 16 lines
It does look like
svc_udp_recvfrom()is wrapping the call tocsum_partial_copy_to_xdr()in a local_bh_disable()/enable() pair, but is that actually needed? If so, for what?Quoted 12 lines
net/sunrpc/xprtrdma/rpc_rdma.c +1
-1@@ -238,7 +238,7 @@ static bool rpcrdma_results_inline(structrpcrdma_xprt *r_xprt, */ if (unlikely (xdrbuf->flags &XDRBUF_SPARSE_PAGES )) {if (!*ppages) - *ppages =alloc_page (GFP_ATOMIC ); + *ppages = alloc_page(GFP_NOWAIT |
Quoted 12 lines
Quoted 5 lines
net/sunrpc/xprtrdma/rpc_rdma.c +0
-0__GFP_NOWARN);if (!*ppages)return -ENOBUFS; }Cheers
TrondSignature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
--
Chuck Lever
Quoted 36 lines · Chuck Lever
Quoted 27 lines
On Mar 4, 2019, at 11:02 AM, Trond Myklebust <
[email protected]> wrote:Quoted 23 lines · Chuck Lever
Page allocation requests made when the
SPARSE_PAGESflag is set are
allowed to fail, and are not critical. No need to spend a rare resource.Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/socklib.c | 2 +- net/sunrpc/xprtrdma/rpc_rdma.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)net/sunrpc/socklib.c +0
-0@@ -106,7 +106,7 @@ static size_txdr_skb_read_and_csum_bits(struct
xdr_skb_reader*desc, void *to,/* ACL likes to be lazy in allocating pages - ACLs * are small by default but can get huge. */ if ((xdr->flags & XDRBUF_SPARSE_PAGES) && *ppage ==NULL) {
net/sunrpc/socklib.c +0
-1- *ppage =alloc_page (GFP_ATOMIC );Quoted 8 lines
Quoted 4 lines
net/sunrpc/socklib.c +1
-0+ *ppage =alloc_page (GFP_NOWAIT | __GFP_NOWARN);if (unlikely(*ppage == NULL)) { if (copied == 0) copied = -ENOMEM;Hmm... Can't we make this
GFP_KERNEL? I can't see that we're holding
any locks here.
Quoted 4 lines
We're holding the transport send lock. Since this is an order 0 allocation
it's unlikely to fail even with a less aggressive request like NOWAIT.
We should only be holding the receive mutex. That prevents others from closing the socket (or starting a second receive worker) but that's all.
OTOH, the only thing using this mechanism on UDP should be the NFSv2/v3 ACL receive code, so I'm not really sure anyone cares.
Quoted 34 lines
Quoted 16 lines
It does look like
svc_udp_recvfrom()is wrapping the call tocsum_partial_copy_to_xdr()in a local_bh_disable()/enable() pair, but is that actually needed? If so, for what?Quoted 12 lines
net/sunrpc/xprtrdma/rpc_rdma.c +1
-1@@ -238,7 +238,7 @@ static bool rpcrdma_results_inline(structrpcrdma_xprt *r_xprt, */ if (unlikely (xdrbuf->flags &XDRBUF_SPARSE_PAGES )) {if (!*ppages) - *ppages =alloc_page (GFP_ATOMIC ); + *ppages = alloc_page(GFP_NOWAIT |Quoted 12 lines
Quoted 5 lines
net/sunrpc/xprtrdma/rpc_rdma.c +0
-0__GFP_NOWARN);if (!*ppages)return -ENOBUFS; }Cheers
TrondSignature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]--
Chuck Lever
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 41 lines · Trond Myklebust
Quoted 36 lines · Chuck Lever
Quoted 35 lines
On Mar 4, 2019, at 11:02 AM, Trond Myklebust <
[email protected]> wrote:Quoted 24 lines · Chuck Lever
Page allocation requests made when the
SPARSE_PAGESflag is set are
allowed to fail, and are not critical. No need to spend a rare resource.Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/socklib.c | 2 +- net/sunrpc/xprtrdma/rpc_rdma.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)net/sunrpc/socklib.c +0
-0@@ -106,7 +106,7 @@ static size_txdr_skb_read_and_csum_bits(struct
xdr_skb_reader*desc, void *to,/* ACL likes to be lazy in allocating pages - ACLs * are small by default but can get huge. */ if ((xdr->flags & XDRBUF_SPARSE_PAGES) && *ppage ==NULL) {
net/sunrpc/socklib.c +1
-1- *ppage =alloc_page (GFP_ATOMIC ); + *ppage =alloc_page (GFP_NOWAIT | __GFP_NOWARN);Quoted 3 lines
if (unlikely(*ppage == NULL)) { if (copied == 0) copied = -ENOMEM;Hmm... Can't we make this
GFP_KERNEL? I can't see that we're holding
any locks here.
Quoted 8 lines
Quoted 4 lines
We're holding the transport send lock. Since this is an order 0 allocation
it's unlikely to fail even with a less aggressive request like NOWAIT.We should only be holding the receive mutex. That prevents others from closing the socket (or starting a second receive worker) but that's all.
OK, I guess the UDP and RPC-over-RDMA cases are different. For RDMA, this allocation is done in ->send_request.
Quoted 2 lines
OTOH, the only thing using this mechanism on UDP should be the NFSv2/v3 ACL receive code, so I'm not really sure anyone cares.
True. However, as I've said before, the right fix for this is to get rid of SPARSE_PAGES and ensure that NFS always allocates enough receive buffer space during Call encoding. But it's not clear anyone cares enough.
Will the current patch be acceptable, or do you want me to use a sharper stick when allocating?
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
It does look like
svc_udp_recvfrom()is wrapping the call tocsum_partial_copy_to_xdr()in a local_bh_disable()/enable() pair, but is that actually needed? If so, for what?Quoted 14 lines
net/sunrpc/xprtrdma/rpc_rdma.c +1
-1@@ -238,7 +238,7 @@ static bool rpcrdma_results_inline(structrpcrdma_xprt *r_xprt, */ if (unlikely (xdrbuf->flags &XDRBUF_SPARSE_PAGES )) {if (!*ppages) - *ppages =alloc_page (GFP_ATOMIC ); + *ppages =alloc_page (GFP_NOWAIT | __GFP_NOWARN);if (!*ppages)Quoted 3 lines
return -ENOBUFS; }Cheers
TrondSignature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 9 lines
Quoted 5 lines
--
Chuck LeverSignature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
--
Chuck Lever
Quoted 50 lines · Chuck Lever
Quoted 50 lines
On Mar 4, 2019, at 11:09 AM, Trond Myklebust <
[email protected]> wrote:Quoted 45 lines · Chuck Lever
Quoted 32 lines
On Mar 4, 2019, at 11:02 AM, Trond Myklebust <
[email protected]> wrote:Quoted 28 lines · Chuck Lever
Page allocation requests made when the
SPARSE_PAGESflag is set
are
allowed to fail, and are not critical. No need to spend a rare
resource.Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/socklib.c | 2 +- net/sunrpc/xprtrdma/rpc_rdma.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)net/sunrpc/socklib.c +0
-0@@ -106,7 +106,7 @@ static size_txdr_skb_read_and_csum_bits(struct
xdr_skb_reader*desc, void *to,/* ACL likes to be lazy in allocating pages - ACLs * are small by default but can get huge. */ if ((xdr->flags & XDRBUF_SPARSE_PAGES) &&*ppage ==
NULL) {net/sunrpc/socklib.c +1
-1- *ppage =alloc_page (GFP_ATOMIC ); + *ppage = alloc_page(GFP_NOWAIT |Quoted 8 lines
Quoted 4 lines
__GFP_NOWARN); if (unlikely(*ppage == NULL)) { if (copied == 0) copied = -ENOMEM;Hmm... Can't we make this
GFP_KERNEL? I can't see that we're holding
any locks here.We're holding the transport send lock. Since this is an order 0 allocation
it's unlikely to fail even with a less aggressive request like NOWAIT.
Quoted 7 lines
Quoted 4 lines
We should only be holding the receive mutex. That prevents others from
closing the socket (or starting a second receive worker) but that's all.OK, I guess the UDP and RPC-over-RDMA cases are different. For RDMA, this allocation is done in ->send_request.
Right. My comment was only intended to apply to the UDP case.
Quoted 11 lines
Quoted 3 lines
OTOH, the only thing using this mechanism on UDP should be the NFSv2/v3
ACL receive code, so I'm not really sure anyone cares.True. However, as I've said before, the right fix for this is to get rid of
SPARSE_PAGESand ensure that NFS always allocates enough receive buffer space during Call encoding. But it's not clear anyone cares enough.Will the current patch be acceptable, or do you want me to use a sharper stick when allocating?
It should be fine.
Quoted 49 lines
Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
It does look like
svc_udp_recvfrom()is wrapping the call tocsum_partial_copy_to_xdr()in a local_bh_disable()/enable()
pair, but is that actually needed? If so, for what?Quoted 15 lines
net/sunrpc/xprtrdma/rpc_rdma.c +1
-1@@ -238,7 +238,7 @@ static bool rpcrdma_results_inline(structrpcrdma_xprt *r_xprt, */ if (unlikely (xdrbuf->flags &XDRBUF_SPARSE_PAGES )) {if (!*ppages) - *ppages =alloc_page (GFP_ATOMIC ); + *ppages = alloc_page(GFP_NOWAIT|
Quoted 5 lines
__GFP_NOWARN); if (!*ppages) return -ENOBUFS; }Cheers
TrondSignature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]Quoted 9 lines
Quoted 5 lines
--
Chuck LeverSignature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]--
Chuck Lever
Signature · 5 lines
Trond Myklebust CTO, Hammerspace Inc 4300 El Camino Real, Suite 105 Los Altos, CA 94022 www.hammer.space