]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
SUNRPC/xprt: 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>
Fri, 20 May 2022 12:40:56 +0000 (14:40 +0200)
BugLink: https://bugs.launchpad.net/bugs/1969107
[ Upstream commit a721035477fb5fb8abc738fbe410b07c12af3dc5 ]

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.

xprt_dynamic_alloc_slot can block indefinitely.  This can tie up all
workqueue threads and NFS can deadlock.  So when called from a
workqueue, set __GFP_NORETRY.

The rdma alloc_slot already does not block.  However it sets the error
to -EAGAIN suggesting this will trigger a sleep.  It does not.  As we
can see in call_reserveresult(), only -ENOMEM causes a sleep.  -EAGAIN
causes immediate retry.

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 20700aa01bc27428e4c9ffe2a635251444dcdd17)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
net/sunrpc/xprt.c
net/sunrpc/xprtrdma/transport.c

index d95426c0bd3a07230f959282f020a15257dd92bf..61603c2664a604371c4fbf27b0b017a9b76c4454 100644 (file)
@@ -1686,12 +1686,15 @@ out:
 static struct rpc_rqst *xprt_dynamic_alloc_slot(struct rpc_xprt *xprt)
 {
        struct rpc_rqst *req = ERR_PTR(-EAGAIN);
+       gfp_t gfp_mask = GFP_KERNEL;
 
        if (xprt->num_reqs >= xprt->max_reqs)
                goto out;
        ++xprt->num_reqs;
        spin_unlock(&xprt->reserve_lock);
-       req = kzalloc(sizeof(struct rpc_rqst), GFP_NOFS);
+       if (current->flags & PF_WQ_WORKER)
+               gfp_mask |= __GFP_NORETRY | __GFP_NOWARN;
+       req = kzalloc(sizeof(*req), gfp_mask);
        spin_lock(&xprt->reserve_lock);
        if (req != NULL)
                goto out;
index a522771155002948321708f64e10a113f9caaabc..32df23796747260ec3c1a9a2885f4300ed1504b3 100644 (file)
@@ -521,7 +521,7 @@ xprt_rdma_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task)
        return;
 
 out_sleep:
-       task->tk_status = -EAGAIN;
+       task->tk_status = -ENOMEM;
        xprt_add_backlog(xprt, task);
 }