Commit 7f338fe4540b1d0600b02314c7d885fd358e9eca
Committed by
Linus Torvalds
1 parent
381760eadc
Exists in
master
and in
20 other branches
nbd: set SOCK_MEMALLOC for access to PFMEMALLOC reserves
Set SOCK_MEMALLOC on the NBD socket to allow access to PFMEMALLOC reserves so pages backed by NBD, particularly if swap related, can be cleaned to prevent the machine being deadlocked. It is still possible that the PFMEMALLOC reserves get depleted resulting in deadlock but this can be resolved by the administrator by increasing min_free_kbytes. Signed-off-by: Mel Gorman <mgorman@suse.de> Cc: David Miller <davem@davemloft.net> Cc: Neil Brown <neilb@suse.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Christie <michaelc@cs.wisc.edu> Cc: Eric B Munson <emunson@mgebm.net> Cc: Eric Dumazet <eric.dumazet@gmail.com> Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc> Cc: Mel Gorman <mgorman@suse.de> Cc: Christoph Lameter <cl@linux.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 5 additions and 1 deletions Side-by-side Diff
drivers/block/nbd.c
... | ... | @@ -154,6 +154,7 @@ |
154 | 154 | struct msghdr msg; |
155 | 155 | struct kvec iov; |
156 | 156 | sigset_t blocked, oldset; |
157 | + unsigned long pflags = current->flags; | |
157 | 158 | |
158 | 159 | if (unlikely(!sock)) { |
159 | 160 | dev_err(disk_to_dev(nbd->disk), |
160 | 161 | |
... | ... | @@ -167,8 +168,9 @@ |
167 | 168 | siginitsetinv(&blocked, sigmask(SIGKILL)); |
168 | 169 | sigprocmask(SIG_SETMASK, &blocked, &oldset); |
169 | 170 | |
171 | + current->flags |= PF_MEMALLOC; | |
170 | 172 | do { |
171 | - sock->sk->sk_allocation = GFP_NOIO; | |
173 | + sock->sk->sk_allocation = GFP_NOIO | __GFP_MEMALLOC; | |
172 | 174 | iov.iov_base = buf; |
173 | 175 | iov.iov_len = size; |
174 | 176 | msg.msg_name = NULL; |
... | ... | @@ -214,6 +216,7 @@ |
214 | 216 | } while (size > 0); |
215 | 217 | |
216 | 218 | sigprocmask(SIG_SETMASK, &oldset, NULL); |
219 | + tsk_restore_flags(current, pflags, PF_MEMALLOC); | |
217 | 220 | |
218 | 221 | return result; |
219 | 222 | } |
... | ... | @@ -405,6 +408,7 @@ |
405 | 408 | |
406 | 409 | BUG_ON(nbd->magic != NBD_MAGIC); |
407 | 410 | |
411 | + sk_set_memalloc(nbd->sock->sk); | |
408 | 412 | nbd->pid = task_pid_nr(current); |
409 | 413 | ret = device_create_file(disk_to_dev(nbd->disk), &pid_attr); |
410 | 414 | if (ret) { |