Skip to content

Commit eb65b85

Browse files
jtlaytongregkh
authored andcommitted
nfs: skip commit in releasepage if we're freeing memory for fs-related reasons
commit 5cf02d0 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9d0ed6e commit eb65b85

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
@@ -493,8 +493,11 @@ static int nfs_release_page(struct page *page, gfp_t gfp)
493493

494494
dfprintk(PAGECACHE, "NFS: release_page(%p)\n", page);
495495

496-
/* Only do I/O if gfp is a superset of GFP_KERNEL */
497-
if (mapping && (gfp & GFP_KERNEL) == GFP_KERNEL) {
496+
/* Only do I/O if gfp is a superset of GFP_KERNEL, and we're not
497+
* doing this memory reclaim for a fs-related allocation.
498+
*/
499+
if (mapping && (gfp & GFP_KERNEL) == GFP_KERNEL &&
500+
!(current->flags & PF_FSTRANS)) {
498501
int how = FLUSH_SYNC;
499502

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

net/sunrpc/sched.c

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

714714
static void rpc_async_schedule(struct work_struct *work)
715715
{
716+
current->flags |= PF_FSTRANS;
716717
__rpc_execute(container_of(work, struct rpc_task, u.tk_work));
718+
current->flags &= ~PF_FSTRANS;
717719
}
718720

719721
/**

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
@@ -1882,6 +1882,8 @@ static void xs_local_setup_socket(struct work_struct *work)
18821882
if (xprt->shutdown)
18831883
goto out;
18841884

1885+
current->flags |= PF_FSTRANS;
1886+
18851887
clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
18861888
status = __sock_create(xprt->xprt_net, AF_LOCAL,
18871889
SOCK_STREAM, 0, &sock, 1);
@@ -1915,6 +1917,7 @@ static void xs_local_setup_socket(struct work_struct *work)
19151917
out:
19161918
xprt_clear_connecting(xprt);
19171919
xprt_wake_pending_tasks(xprt, status);
1920+
current->flags &= ~PF_FSTRANS;
19181921
}
19191922

19201923
static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
@@ -1957,6 +1960,8 @@ static void xs_udp_setup_socket(struct work_struct *work)
19571960
if (xprt->shutdown)
19581961
goto out;
19591962

1963+
current->flags |= PF_FSTRANS;
1964+
19601965
/* Start by resetting any existing state */
19611966
xs_reset_transport(transport);
19621967
sock = xs_create_sock(xprt, transport,
@@ -1975,6 +1980,7 @@ static void xs_udp_setup_socket(struct work_struct *work)
19751980
out:
19761981
xprt_clear_connecting(xprt);
19771982
xprt_wake_pending_tasks(xprt, status);
1983+
current->flags &= ~PF_FSTRANS;
19781984
}
19791985

19801986
/*
@@ -2100,6 +2106,8 @@ static void xs_tcp_setup_socket(struct work_struct *work)
21002106
if (xprt->shutdown)
21012107
goto out;
21022108

2109+
current->flags |= PF_FSTRANS;
2110+
21032111
if (!sock) {
21042112
clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
21052113
sock = xs_create_sock(xprt, transport,
@@ -2149,6 +2157,7 @@ static void xs_tcp_setup_socket(struct work_struct *work)
21492157
case -EINPROGRESS:
21502158
case -EALREADY:
21512159
xprt_clear_connecting(xprt);
2160+
current->flags &= ~PF_FSTRANS;
21522161
return;
21532162
case -EINVAL:
21542163
/* Happens, for instance, if the user specified a link
@@ -2161,6 +2170,7 @@ static void xs_tcp_setup_socket(struct work_struct *work)
21612170
out:
21622171
xprt_clear_connecting(xprt);
21632172
xprt_wake_pending_tasks(xprt, status);
2173+
current->flags &= ~PF_FSTRANS;
21642174
}
21652175

21662176
/**

0 commit comments

Comments
 (0)