]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
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)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 27 Apr 2022 09:59:25 +0000 (11:59 +0200)
BugLink: https://bugs.launchpad.net/bugs/1969107
[ Upstream commit c487216bec83b0c5a8803e5c61433d33ad7b104d ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit a19fd1d61797e0a0408537ecb97c57dd70c0045e)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
net/sunrpc/sched.c
net/sunrpc/xprtrdma/transport.c

index c045f63d11fa649bbc317906775faf0dbf56f42f..6e4d476c63248bc3fa4c7a9a55e5c14270ba8e1c 100644 (file)
@@ -1012,8 +1012,10 @@ int rpc_malloc(struct rpc_task *task)
        struct rpc_buffer *buf;
        gfp_t gfp = GFP_NOFS;
 
+       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 16e5696314a4f31cba124612f800d7e5b1daf00c..a522771155002948321708f64e10a113f9caaabc 100644 (file)
@@ -574,8 +574,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))