All of lore.kernel.org
 help / color / mirror / Atom feed
From: "NeilBrown" <neilb@suse.de>
To: trondmy@kernel.org
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH] NFS: Fix memory allocation in rpc_malloc()
Date: Wed, 16 Mar 2022 12:53:04 +1100	[thread overview]
Message-ID: <164739558440.9764.6759307849718646101@noble.neil.brown.name> (raw)
In-Reply-To: <20220315162052.570677-1-trondmy@kernel.org>

On Wed, 16 Mar 2022, trondmy@kernel.org wrote:
> From: Trond Myklebust <trond.myklebust@hammerspace.com>
> 
> When allocating memory, it should be safe to always use GFP_KERNEL,
> since both swap tasks and asynchronous tasks will regulate the
> allocation mode through the struct task flags.

'struct task_struct' flags can only enforce NOFS, NOIO, or MEMALLOC.
They cannot prevent waiting altogether.
We need rpciod task to not block waiting for memory.  If they all do,
then there will be no thread free to handle the replies to WRITE which
would allow swapped-out memory to be freed.

As the very least the rescuer thread mustn't block, so the use of
GFP_NOWAIT could depend on current_is_workqueue_rescuer().

Was there some problem you saw caused by the use of GFP_NOWAIT ??

Thanks,
NeilBrown

> 
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> ---
>  net/sunrpc/sched.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
> index 7c8f87ebdbc0..c62fcacf7366 100644
> --- a/net/sunrpc/sched.c
> +++ b/net/sunrpc/sched.c
> @@ -1030,16 +1030,12 @@ int rpc_malloc(struct rpc_task *task)
>  	struct rpc_rqst *rqst = task->tk_rqstp;
>  	size_t size = rqst->rq_callsize + rqst->rq_rcvsize;
>  	struct rpc_buffer *buf;
> -	gfp_t gfp = GFP_KERNEL;
> -
> -	if (RPC_IS_ASYNC(task))
> -		gfp = GFP_NOWAIT | __GFP_NOWARN;
>  
>  	size += sizeof(struct rpc_buffer);
>  	if (size <= RPC_BUFFER_MAXSIZE)
> -		buf = mempool_alloc(rpc_buffer_mempool, gfp);
> +		buf = mempool_alloc(rpc_buffer_mempool, GFP_KERNEL);
>  	else
> -		buf = kmalloc(size, gfp);
> +		buf = kmalloc(size, GFP_KERNEL);
>  
>  	if (!buf)
>  		return -ENOMEM;
> -- 
> 2.35.1
> 
> 

  parent reply	other threads:[~2022-03-16  1:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 16:20 [PATCH] NFS: Fix memory allocation in rpc_malloc() trondmy
2022-03-15 16:50 ` Chuck Lever III
2022-03-15 17:00   ` Trond Myklebust
2022-03-16  1:53 ` NeilBrown [this message]
2022-03-16 13:47   ` Trond Myklebust
2022-03-18  5:04     ` NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=164739558440.9764.6759307849718646101@noble.neil.brown.name \
    --to=neilb@suse.de \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trondmy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.