struct msghdr msg;
        struct kvec iov;
        sigset_t blocked, oldset;
+       unsigned long pflags = current->flags;
 
        if (unlikely(!sock)) {
                dev_err(disk_to_dev(nbd->disk),
        siginitsetinv(&blocked, sigmask(SIGKILL));
        sigprocmask(SIG_SETMASK, &blocked, &oldset);
 
+       current->flags |= PF_MEMALLOC;
        do {
-               sock->sk->sk_allocation = GFP_NOIO;
+               sock->sk->sk_allocation = GFP_NOIO | __GFP_MEMALLOC;
                iov.iov_base = buf;
                iov.iov_len = size;
                msg.msg_name = NULL;
        } while (size > 0);
 
        sigprocmask(SIG_SETMASK, &oldset, NULL);
+       tsk_restore_flags(current, pflags, PF_MEMALLOC);
 
        return result;
 }
 
        BUG_ON(nbd->magic != NBD_MAGIC);
 
+       sk_set_memalloc(nbd->sock->sk);
        nbd->pid = task_pid_nr(current);
        ret = device_create_file(disk_to_dev(nbd->disk), &pid_attr);
        if (ret) {