Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3072375ybt; Mon, 29 Jun 2020 14:34:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnXQPMmJM0e+8urud1Auh0g92GgX1uSHJXlwss3KK8dXcEAanTeRZTeA4pP1CPslBbSS8J X-Received: by 2002:a17:906:4f16:: with SMTP id t22mr15402225eju.179.1593466456363; Mon, 29 Jun 2020 14:34:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593466456; cv=none; d=google.com; s=arc-20160816; b=J+IBvMFQVNn12TiV+EvmpsgcHhv2tPmkGT2aEccwbiaT+ilQo+Nfw1Dz+7BTYOR4ko WepCT60l0qiPT3kERZz3LEGTGXov6KtyjjXEaB4fDE/54Od0aDA9zC5nZPQ7MZ/4T1Dd fvdm3IXqbLki/nnQTBKy44H4SR//3OmAOOh7mVNWqnBOeeLyFLqR0Zxsn+bhsoBzL9E+ 7VE4mg2rIJL4rH4XExDepevoi/Mds8eI1lKnjk8DODZr4KUJ64n7PLS3t5+n3gyLNZGE bXkLPnhGg5cnXnvPS5k+ADYWi9hrybShx/hVs8aB2GddlP2AeOh31TmWIPAHlrO8hw4p Sj0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=pJSYSabtjQXLThabzZvo4prke7aK1X9ZtRqi8GDltVc=; b=RG6rS+rfOm5k6Z61Gk572MYbbeONxdGF+HTBNiQ5TKdaT2siq3/esWPTiE2Yb2tA+C aCfX8X2/36IJnhXd+radda5wILJe2H12gV2MAfcszFYNW77FetqkRYRs94jfpOV9Aock p/39qyVtuhhjlBzp+xsNo9SHMf/Ce8QVuaSdKtrpYWpkNTjg4xHgp2QJv5OE6eULX5jd y3uWr/PIfij8W56oloJYZmz+Y+4IO7JndNfkcg1Isnu+z2hrF82Z6oy+kbyO7SAB+egj 5UrSuIAkCeHel6QYF8mDnCi2ZAL8FFwRE4l+Ez5KJ/nXIFFx0cUH8CM3UidwiTc/SrqT QD4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kn0EDPLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h19si470126ejj.80.2020.06.29.14.33.53; Mon, 29 Jun 2020 14:34:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kn0EDPLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730841AbgF2Vc7 (ORCPT + 99 others); Mon, 29 Jun 2020 17:32:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:60654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728655AbgF2SlD (ORCPT ); Mon, 29 Jun 2020 14:41:03 -0400 Received: from kernel.org (unknown [87.71.40.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3FEEC2311E; Mon, 29 Jun 2020 05:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593407337; bh=LBfhDIhyAbegWKiFoWANZi3Pap2eilYpWYyw9E97Frw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Kn0EDPLt/kFtL3TZwbVsUV6b9Vc5HPIVlyu8B/7Z9XfljZNUO7/rCJq63g5bf9pSJ OuJViNwGVJTHvPk1NoY7dWJEDKZDnrb/oqmreD43xNTbok6DB/kaiaAxuKlUdglMKc LIKCiivFZH7gq+RcuYB4BDBIb7L2Rr8ceeaQPnaU= Date: Mon, 29 Jun 2020 08:08:51 +0300 From: Mike Rapoport To: "Matthew Wilcox (Oracle)" Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, dm-devel@redhat.com, Mikulas Patocka , Jens Axboe , NeilBrown Subject: Re: [PATCH 6/6] mm: Add memalloc_nowait Message-ID: <20200629050851.GC1492837@kernel.org> References: <20200625113122.7540-1-willy@infradead.org> <20200625113122.7540-7-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200625113122.7540-7-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 25, 2020 at 12:31:22PM +0100, Matthew Wilcox (Oracle) wrote: > Similar to memalloc_noio() and memalloc_nofs(), memalloc_nowait() > guarantees we will not sleep to reclaim memory. Use it to simplify > dm-bufio's allocations. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > drivers/md/dm-bufio.c | 30 ++++++++---------------------- > include/linux/sched.h | 1 + > include/linux/sched/mm.h | 12 ++++++++---- > 3 files changed, 17 insertions(+), 26 deletions(-) > > diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c > index 6d1565021d74..140ada9a2c8f 100644 > --- a/drivers/md/dm-bufio.c > +++ b/drivers/md/dm-bufio.c > @@ -412,23 +412,6 @@ static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask, > > *data_mode = DATA_MODE_VMALLOC; > > - /* > - * __vmalloc allocates the data pages and auxiliary structures with > - * gfp_flags that were specified, but pagetables are always allocated > - * with GFP_KERNEL, no matter what was specified as gfp_mask. > - * > - * Consequently, we must set per-process flag PF_MEMALLOC_NOIO so that > - * all allocations done by this process (including pagetables) are done > - * as if GFP_NOIO was specified. > - */ > - if (gfp_mask & __GFP_NORETRY) { > - unsigned noio_flag = memalloc_noio_save(); > - void *ptr = __vmalloc(c->block_size, gfp_mask); > - > - memalloc_noio_restore(noio_flag); > - return ptr; > - } > - > return __vmalloc(c->block_size, gfp_mask); > } > > @@ -866,9 +849,6 @@ static struct dm_buffer *__alloc_buffer_wait_no_callback(struct dm_bufio_client > * dm-bufio is resistant to allocation failures (it just keeps > * one buffer reserved in cases all the allocations fail). > * So set flags to not try too hard: > - * GFP_NOWAIT: don't wait; if we need to sleep we'll release our > - * mutex and wait ourselves. > - * __GFP_NORETRY: don't retry and rather return failure > * __GFP_NOMEMALLOC: don't use emergency reserves > * __GFP_NOWARN: don't print a warning in case of failure > * > @@ -877,7 +857,9 @@ static struct dm_buffer *__alloc_buffer_wait_no_callback(struct dm_bufio_client > */ > while (1) { > if (dm_bufio_cache_size_latch != 1) { > - b = alloc_buffer(c, GFP_NOWAIT | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN); > + unsigned nowait_flag = memalloc_nowait_save(); > + b = alloc_buffer(c, GFP_KERNEL | __GFP_NOMEMALLOC | __GFP_NOWARN); > + memalloc_nowait_restore(nowait_flag); > if (b) > return b; > } > @@ -886,8 +868,12 @@ static struct dm_buffer *__alloc_buffer_wait_no_callback(struct dm_bufio_client > return NULL; > > if (dm_bufio_cache_size_latch != 1 && !tried_noio_alloc) { > + unsigned noio_flag; > + > dm_bufio_unlock(c); > - b = alloc_buffer(c, GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN); > + noio_flag = memalloc_noio_save(); I've read the series twice and I'm still missing the definition of memalloc_noio_save(). And also it would be nice to have a paragraph about it in Documentation/core-api/memory-allocation.rst > + b = alloc_buffer(c, GFP_KERNEL | > __GFP_NOMEMALLOC | __GFP_NOWARN); + > memalloc_noio_restore(noio_flag); dm_bufio_lock(c); if (b) > return b; > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 90336850e940..b1c2cddd366c 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -803,6 +803,7 @@ struct task_struct { > #endif > unsigned memalloc_noio:1; > unsigned memalloc_nofs:1; > + unsigned memalloc_nowait:1; > unsigned memalloc_nocma:1; > > unsigned long atomic_flags; /* Flags requiring atomic access. */ > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > index 6f7b59a848a6..6484569f50df 100644 > --- a/include/linux/sched/mm.h > +++ b/include/linux/sched/mm.h > @@ -179,12 +179,16 @@ static inline bool in_vfork(struct task_struct *tsk) > static inline gfp_t current_gfp_context(gfp_t flags) > { > if (unlikely(current->memalloc_noio || current->memalloc_nofs || > - current->memalloc_nocma)) { > + current->memalloc_nocma) || current->memalloc_nowait) { > /* > - * NOIO implies both NOIO and NOFS and it is a weaker context > - * so always make sure it makes precedence > + * Clearing DIRECT_RECLAIM means we won't get to the point > + * of testing IO or FS, so we don't need to bother clearing > + * them. noio implies neither IO nor FS and it is a weaker > + * context so always make sure it takes precedence. > */ > - if (current->memalloc_noio) > + if (current->memalloc_nowait) > + flags &= ~__GFP_DIRECT_RECLAIM; > + else if (current->memalloc_noio) > flags &= ~(__GFP_IO | __GFP_FS); > else if (current->memalloc_nofs) > flags &= ~__GFP_FS; > -- > 2.27.0 > > -- Sincerely yours, Mike.