SUNRPC/call_alloc: async tasks mustn't block waiting for memory
authorNeilBrown <neilb@suse.de>
Sun, 6 Mar 2022 23:41:44 +0000 (10:41 +1100)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Sun, 13 Mar 2022 16:59:35 +0000 (12:59 -0400)
When memory is short, new worker threads cannot be created and we depend
on the minimum one rpciod thread to be able to handle everything.
So it must not block waiting for memory.

mempools are particularly a problem as memory can only be released back
to the mempool by an async rpc task running.  If all available
workqueue threads are waiting on the mempool, no thread is available to
return anything.

rpc_malloc() can block, and this might cause deadlocks.
So check RPC_IS_ASYNC(), rather than RPC_IS_SWAPPER() to determine if
blocking is acceptable.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
net/sunrpc/sched.c
net/sunrpc/xprtrdma/transport.c

index 52769b883c0a03ee6d913e8492bd933e1eb81281..e5b07562ba45dffeb751bd26bcfeb7db7051ee6e 100644 (file)
@@ -1023,8 +1023,10 @@ int rpc_malloc(struct rpc_task *task)
        struct rpc_buffer *buf;
        gfp_t gfp = GFP_KERNEL;
 
+       if (RPC_IS_ASYNC(task))
+               gfp = GFP_NOWAIT | __GFP_NOWARN;
        if (RPC_IS_SWAPPER(task))
-               gfp = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN;
+               gfp |= __GFP_MEMALLOC;
 
        size += sizeof(struct rpc_buffer);
        if (size <= RPC_BUFFER_MAXSIZE)
index 42e375dbdadb4c1fb6d14fe31f1cb07f83d3e9db..5714bf880e95fa9cf42532c0ee2c76d57dec1ec8 100644 (file)
@@ -570,8 +570,10 @@ xprt_rdma_allocate(struct rpc_task *task)
        gfp_t flags;
 
        flags = RPCRDMA_DEF_GFP;
+       if (RPC_IS_ASYNC(task))
+               flags = GFP_NOWAIT | __GFP_NOWARN;
        if (RPC_IS_SWAPPER(task))
-               flags = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN;
+               flags |= __GFP_MEMALLOC;
 
        if (!rpcrdma_check_regbuf(r_xprt, req->rl_sendbuf, rqst->rq_callsize,
                                  flags))