Skip to content

Commit a1231fd

Browse files
author
Trond Myklebust
committed
SUNRPC: Set memalloc_nofs_save() on all rpciod/xprtiod jobs
Set memalloc_nofs_save() on all the rpciod/xprtiod jobs so that we ensure memory allocations for asynchronous rpc calls don't ever end up recursing back to the NFS layer for memory reclaim. Signed-off-by: Trond Myklebust <[email protected]>
1 parent e9acf21 commit a1231fd

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

net/sunrpc/sched.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/spinlock.h>
2020
#include <linux/mutex.h>
2121
#include <linux/freezer.h>
22+
#include <linux/sched/mm.h>
2223

2324
#include <linux/sunrpc/clnt.h>
2425

@@ -902,7 +903,10 @@ void rpc_execute(struct rpc_task *task)
902903

903904
static void rpc_async_schedule(struct work_struct *work)
904905
{
906+
unsigned int pflags = memalloc_nofs_save();
907+
905908
__rpc_execute(container_of(work, struct rpc_task, u.tk_work));
909+
memalloc_nofs_restore(pflags);
906910
}
907911

908912
/**
@@ -1067,7 +1071,10 @@ static void rpc_free_task(struct rpc_task *task)
10671071

10681072
static void rpc_async_release(struct work_struct *work)
10691073
{
1074+
unsigned int pflags = memalloc_nofs_save();
1075+
10701076
rpc_free_task(container_of(work, struct rpc_task, u.tk_work));
1077+
memalloc_nofs_restore(pflags);
10711078
}
10721079

10731080
static void rpc_release_resources_task(struct rpc_task *task)

net/sunrpc/xprt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <linux/sunrpc/metrics.h>
5050
#include <linux/sunrpc/bc_xprt.h>
5151
#include <linux/rcupdate.h>
52+
#include <linux/sched/mm.h>
5253

5354
#include <trace/events/sunrpc.h>
5455

@@ -643,11 +644,13 @@ static void xprt_autoclose(struct work_struct *work)
643644
{
644645
struct rpc_xprt *xprt =
645646
container_of(work, struct rpc_xprt, task_cleanup);
647+
unsigned int pflags = memalloc_nofs_save();
646648

647649
clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
648650
xprt->ops->close(xprt);
649651
xprt_release_write(xprt, NULL);
650652
wake_up_bit(&xprt->state, XPRT_LOCKED);
653+
memalloc_nofs_restore(pflags);
651654
}
652655

653656
/**

net/sunrpc/xprtsock.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <linux/bvec.h>
5151
#include <linux/highmem.h>
5252
#include <linux/uio.h>
53+
#include <linux/sched/mm.h>
5354

5455
#include <trace/events/sunrpc.h>
5556

@@ -680,7 +681,10 @@ static void xs_stream_data_receive_workfn(struct work_struct *work)
680681
{
681682
struct sock_xprt *transport =
682683
container_of(work, struct sock_xprt, recv_worker);
684+
unsigned int pflags = memalloc_nofs_save();
685+
683686
xs_stream_data_receive(transport);
687+
memalloc_nofs_restore(pflags);
684688
}
685689

686690
static void
@@ -1378,7 +1382,10 @@ static void xs_udp_data_receive_workfn(struct work_struct *work)
13781382
{
13791383
struct sock_xprt *transport =
13801384
container_of(work, struct sock_xprt, recv_worker);
1385+
unsigned int pflags = memalloc_nofs_save();
1386+
13811387
xs_udp_data_receive(transport);
1388+
memalloc_nofs_restore(pflags);
13821389
}
13831390

13841391
/**
@@ -1869,7 +1876,6 @@ static int xs_local_finish_connecting(struct rpc_xprt *xprt,
18691876
sk->sk_write_space = xs_udp_write_space;
18701877
sock_set_flag(sk, SOCK_FASYNC);
18711878
sk->sk_error_report = xs_error_report;
1872-
sk->sk_allocation = GFP_NOIO;
18731879

18741880
xprt_clear_connected(xprt);
18751881

@@ -2057,7 +2063,6 @@ static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
20572063
sk->sk_data_ready = xs_data_ready;
20582064
sk->sk_write_space = xs_udp_write_space;
20592065
sock_set_flag(sk, SOCK_FASYNC);
2060-
sk->sk_allocation = GFP_NOIO;
20612066

20622067
xprt_set_connected(xprt);
20632068

@@ -2220,7 +2225,6 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
22202225
sk->sk_write_space = xs_tcp_write_space;
22212226
sock_set_flag(sk, SOCK_FASYNC);
22222227
sk->sk_error_report = xs_error_report;
2223-
sk->sk_allocation = GFP_NOIO;
22242228

22252229
/* socket options */
22262230
sock_reset_flag(sk, SOCK_LINGER);

0 commit comments

Comments
 (0)