Skip to content

Commit 5cf02d0

Browse files
jtlaytonTrond Myklebust
authored and
Trond Myklebust
committed
nfs: skip commit in releasepage if we're freeing memory for fs-related reasons
We've had some reports of a deadlock where rpciod ends up with a stack trace like this: PID: 2507 TASK: ffff88103691ab40 CPU: 14 COMMAND: "rpciod/14" #0 [ffff8810343bf2f0] schedule at ffffffff814dabd9 linux-sunxi#1 [ffff8810343bf3b8] nfs_wait_bit_killable at ffffffffa038fc04 [nfs] linux-sunxi#2 [ffff8810343bf3c8] __wait_on_bit at ffffffff814dbc2f linux-sunxi#3 [ffff8810343bf418] out_of_line_wait_on_bit at ffffffff814dbcd8 linux-sunxi#4 [ffff8810343bf488] nfs_commit_inode at ffffffffa039e0c1 [nfs] linux-sunxi#5 [ffff8810343bf4f8] nfs_release_page at ffffffffa038bef6 [nfs] linux-sunxi#6 [ffff8810343bf528] try_to_release_page at ffffffff8110c670 linux-sunxi#7 [ffff8810343bf538] shrink_page_list.clone.0 at ffffffff81126271 linux-sunxi#8 [ffff8810343bf668] shrink_inactive_list at ffffffff81126638 linux-sunxi#9 [ffff8810343bf818] shrink_zone at ffffffff8112788f linux-sunxi#10 [ffff8810343bf8c8] do_try_to_free_pages at ffffffff81127b1e linux-sunxi#11 [ffff8810343bf958] try_to_free_pages at ffffffff8112812f linux-sunxi#12 [ffff8810343bfa08] __alloc_pages_nodemask at ffffffff8111fdad linux-sunxi#13 [ffff8810343bfb28] kmem_getpages at ffffffff81159942 linux-sunxi#14 [ffff8810343bfb58] fallback_alloc at ffffffff8115a55a linux-sunxi#15 [ffff8810343bfbd8] ____cache_alloc_node at ffffffff8115a2d9 linux-sunxi#16 [ffff8810343bfc38] kmem_cache_alloc at ffffffff8115b09b linux-sunxi#17 [ffff8810343bfc78] sk_prot_alloc at ffffffff81411808 linux-sunxi#18 [ffff8810343bfcb8] sk_alloc at ffffffff8141197c linux-sunxi#19 [ffff8810343bfce8] inet_create at ffffffff81483ba6 linux-sunxi#20 [ffff8810343bfd38] __sock_create at ffffffff8140b4a7 linux-sunxi#21 [ffff8810343bfd98] xs_create_sock at ffffffffa01f649b [sunrpc] linux-sunxi#22 [ffff8810343bfdd8] xs_tcp_setup_socket at ffffffffa01f6965 [sunrpc] linux-sunxi#23 [ffff8810343bfe38] worker_thread at ffffffff810887d0 linux-sunxi#24 [ffff8810343bfee8] kthread at ffffffff8108dd96 linux-sunxi#25 [ffff8810343bff48] kernel_thread at ffffffff8100c1ca rpciod is trying to allocate memory for a new socket to talk to the server. The VM ends up calling ->releasepage to get more memory, and it tries to do a blocking commit. That commit can't succeed however without a connected socket, so we deadlock. Fix this by setting PF_FSTRANS on the workqueue task prior to doing the socket allocation, and having nfs_release_page check for that flag when deciding whether to do a commit call. Also, set PF_FSTRANS unconditionally in rpc_async_schedule since that function can also do allocations sometimes. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com> Cc: stable@vger.kernel.org
1 parent 506026c commit 5cf02d0

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

fs/nfs/file.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,11 @@ static int nfs_release_page(struct page *page, gfp_t gfp)
447447

448448
dfprintk(PAGECACHE, "NFS: release_page(%p)\n", page);
449449

450-
/* Only do I/O if gfp is a superset of GFP_KERNEL */
451-
if (mapping && (gfp & GFP_KERNEL) == GFP_KERNEL) {
450+
/* Only do I/O if gfp is a superset of GFP_KERNEL, and we're not
451+
* doing this memory reclaim for a fs-related allocation.
452+
*/
453+
if (mapping && (gfp & GFP_KERNEL) == GFP_KERNEL &&
454+
!(current->flags & PF_FSTRANS)) {
452455
int how = FLUSH_SYNC;
453456

454457
/* Don't let kswapd deadlock waiting for OOM RPC calls */

net/sunrpc/sched.c

+2
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,9 @@ void rpc_execute(struct rpc_task *task)
791791

792792
static void rpc_async_schedule(struct work_struct *work)
793793
{
794+
current->flags |= PF_FSTRANS;
794795
__rpc_execute(container_of(work, struct rpc_task, u.tk_work));
796+
current->flags &= ~PF_FSTRANS;
795797
}
796798

797799
/**

net/sunrpc/xprtrdma/transport.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ xprt_rdma_connect_worker(struct work_struct *work)
200200
int rc = 0;
201201

202202
if (!xprt->shutdown) {
203+
current->flags |= PF_FSTRANS;
203204
xprt_clear_connected(xprt);
204205

205206
dprintk("RPC: %s: %sconnect\n", __func__,
@@ -212,10 +213,10 @@ xprt_rdma_connect_worker(struct work_struct *work)
212213

213214
out:
214215
xprt_wake_pending_tasks(xprt, rc);
215-
216216
out_clear:
217217
dprintk("RPC: %s: exit\n", __func__);
218218
xprt_clear_connecting(xprt);
219+
current->flags &= ~PF_FSTRANS;
219220
}
220221

221222
/*

net/sunrpc/xprtsock.c

+10
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,8 @@ static void xs_local_setup_socket(struct work_struct *work)
18951895
if (xprt->shutdown)
18961896
goto out;
18971897

1898+
current->flags |= PF_FSTRANS;
1899+
18981900
clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
18991901
status = __sock_create(xprt->xprt_net, AF_LOCAL,
19001902
SOCK_STREAM, 0, &sock, 1);
@@ -1928,6 +1930,7 @@ static void xs_local_setup_socket(struct work_struct *work)
19281930
out:
19291931
xprt_clear_connecting(xprt);
19301932
xprt_wake_pending_tasks(xprt, status);
1933+
current->flags &= ~PF_FSTRANS;
19311934
}
19321935

19331936
static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
@@ -1970,6 +1973,8 @@ static void xs_udp_setup_socket(struct work_struct *work)
19701973
if (xprt->shutdown)
19711974
goto out;
19721975

1976+
current->flags |= PF_FSTRANS;
1977+
19731978
/* Start by resetting any existing state */
19741979
xs_reset_transport(transport);
19751980
sock = xs_create_sock(xprt, transport,
@@ -1988,6 +1993,7 @@ static void xs_udp_setup_socket(struct work_struct *work)
19881993
out:
19891994
xprt_clear_connecting(xprt);
19901995
xprt_wake_pending_tasks(xprt, status);
1996+
current->flags &= ~PF_FSTRANS;
19911997
}
19921998

19931999
/*
@@ -2113,6 +2119,8 @@ static void xs_tcp_setup_socket(struct work_struct *work)
21132119
if (xprt->shutdown)
21142120
goto out;
21152121

2122+
current->flags |= PF_FSTRANS;
2123+
21162124
if (!sock) {
21172125
clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
21182126
sock = xs_create_sock(xprt, transport,
@@ -2162,6 +2170,7 @@ static void xs_tcp_setup_socket(struct work_struct *work)
21622170
case -EINPROGRESS:
21632171
case -EALREADY:
21642172
xprt_clear_connecting(xprt);
2173+
current->flags &= ~PF_FSTRANS;
21652174
return;
21662175
case -EINVAL:
21672176
/* Happens, for instance, if the user specified a link
@@ -2174,6 +2183,7 @@ static void xs_tcp_setup_socket(struct work_struct *work)
21742183
out:
21752184
xprt_clear_connecting(xprt);
21762185
xprt_wake_pending_tasks(xprt, status);
2186+
current->flags &= ~PF_FSTRANS;
21772187
}
21782188

21792189
/**

0 commit comments

Comments
 (0)