Commit a1231fda authored by Trond Myklebust's avatar Trond Myklebust

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: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
parent e9acf210
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/freezer.h> #include <linux/freezer.h>
#include <linux/sched/mm.h>
#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/clnt.h>
...@@ -902,7 +903,10 @@ void rpc_execute(struct rpc_task *task) ...@@ -902,7 +903,10 @@ void rpc_execute(struct rpc_task *task)
static void rpc_async_schedule(struct work_struct *work) static void rpc_async_schedule(struct work_struct *work)
{ {
unsigned int pflags = memalloc_nofs_save();
__rpc_execute(container_of(work, struct rpc_task, u.tk_work)); __rpc_execute(container_of(work, struct rpc_task, u.tk_work));
memalloc_nofs_restore(pflags);
} }
/** /**
...@@ -1067,7 +1071,10 @@ static void rpc_free_task(struct rpc_task *task) ...@@ -1067,7 +1071,10 @@ static void rpc_free_task(struct rpc_task *task)
static void rpc_async_release(struct work_struct *work) static void rpc_async_release(struct work_struct *work)
{ {
unsigned int pflags = memalloc_nofs_save();
rpc_free_task(container_of(work, struct rpc_task, u.tk_work)); rpc_free_task(container_of(work, struct rpc_task, u.tk_work));
memalloc_nofs_restore(pflags);
} }
static void rpc_release_resources_task(struct rpc_task *task) static void rpc_release_resources_task(struct rpc_task *task)
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <linux/sunrpc/metrics.h> #include <linux/sunrpc/metrics.h>
#include <linux/sunrpc/bc_xprt.h> #include <linux/sunrpc/bc_xprt.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/sched/mm.h>
#include <trace/events/sunrpc.h> #include <trace/events/sunrpc.h>
...@@ -643,11 +644,13 @@ static void xprt_autoclose(struct work_struct *work) ...@@ -643,11 +644,13 @@ static void xprt_autoclose(struct work_struct *work)
{ {
struct rpc_xprt *xprt = struct rpc_xprt *xprt =
container_of(work, struct rpc_xprt, task_cleanup); container_of(work, struct rpc_xprt, task_cleanup);
unsigned int pflags = memalloc_nofs_save();
clear_bit(XPRT_CLOSE_WAIT, &xprt->state); clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
xprt->ops->close(xprt); xprt->ops->close(xprt);
xprt_release_write(xprt, NULL); xprt_release_write(xprt, NULL);
wake_up_bit(&xprt->state, XPRT_LOCKED); wake_up_bit(&xprt->state, XPRT_LOCKED);
memalloc_nofs_restore(pflags);
} }
/** /**
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include <linux/bvec.h> #include <linux/bvec.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/uio.h> #include <linux/uio.h>
#include <linux/sched/mm.h>
#include <trace/events/sunrpc.h> #include <trace/events/sunrpc.h>
...@@ -680,7 +681,10 @@ static void xs_stream_data_receive_workfn(struct work_struct *work) ...@@ -680,7 +681,10 @@ static void xs_stream_data_receive_workfn(struct work_struct *work)
{ {
struct sock_xprt *transport = struct sock_xprt *transport =
container_of(work, struct sock_xprt, recv_worker); container_of(work, struct sock_xprt, recv_worker);
unsigned int pflags = memalloc_nofs_save();
xs_stream_data_receive(transport); xs_stream_data_receive(transport);
memalloc_nofs_restore(pflags);
} }
static void static void
...@@ -1378,7 +1382,10 @@ static void xs_udp_data_receive_workfn(struct work_struct *work) ...@@ -1378,7 +1382,10 @@ static void xs_udp_data_receive_workfn(struct work_struct *work)
{ {
struct sock_xprt *transport = struct sock_xprt *transport =
container_of(work, struct sock_xprt, recv_worker); container_of(work, struct sock_xprt, recv_worker);
unsigned int pflags = memalloc_nofs_save();
xs_udp_data_receive(transport); xs_udp_data_receive(transport);
memalloc_nofs_restore(pflags);
} }
/** /**
...@@ -1869,7 +1876,6 @@ static int xs_local_finish_connecting(struct rpc_xprt *xprt, ...@@ -1869,7 +1876,6 @@ static int xs_local_finish_connecting(struct rpc_xprt *xprt,
sk->sk_write_space = xs_udp_write_space; sk->sk_write_space = xs_udp_write_space;
sock_set_flag(sk, SOCK_FASYNC); sock_set_flag(sk, SOCK_FASYNC);
sk->sk_error_report = xs_error_report; sk->sk_error_report = xs_error_report;
sk->sk_allocation = GFP_NOIO;
xprt_clear_connected(xprt); xprt_clear_connected(xprt);
...@@ -2057,7 +2063,6 @@ static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) ...@@ -2057,7 +2063,6 @@ static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
sk->sk_data_ready = xs_data_ready; sk->sk_data_ready = xs_data_ready;
sk->sk_write_space = xs_udp_write_space; sk->sk_write_space = xs_udp_write_space;
sock_set_flag(sk, SOCK_FASYNC); sock_set_flag(sk, SOCK_FASYNC);
sk->sk_allocation = GFP_NOIO;
xprt_set_connected(xprt); xprt_set_connected(xprt);
...@@ -2220,7 +2225,6 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) ...@@ -2220,7 +2225,6 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
sk->sk_write_space = xs_tcp_write_space; sk->sk_write_space = xs_tcp_write_space;
sock_set_flag(sk, SOCK_FASYNC); sock_set_flag(sk, SOCK_FASYNC);
sk->sk_error_report = xs_error_report; sk->sk_error_report = xs_error_report;
sk->sk_allocation = GFP_NOIO;
/* socket options */ /* socket options */
sock_reset_flag(sk, SOCK_LINGER); sock_reset_flag(sk, SOCK_LINGER);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment