From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Matthew Wilcox <willy@infradead.org>,
Salvatore Dipietro <dipiets@amazon.it>
Cc: linux-mm@kvack.org, hch@infradead.org, ritesh.list@gmail.com,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org,
dgc@kernel.org, djwong@kernel.org, brauner@kernel.org,
alisaidi@amazon.com, blakgeof@amazon.com, abuehaze@amazon.com,
dipietro.salvatore@gmail.com, stable@vger.kernel.org,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <jackmanb@google.com>,
Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>
Subject: Re: [PATCH v3] mm/page_alloc: avoid direct compaction for costly __GFP_NORETRY allocations
Date: Wed, 22 Jul 2026 14:17:54 +0200 [thread overview]
Message-ID: <15c65a4b-aa53-4218-baa4-7dbab3b9dbab@kernel.org> (raw)
In-Reply-To: <alEz4Chf7Ibyg-ZG@casper.infradead.org>
On 7/10/26 20:03, Matthew Wilcox wrote:
> On Fri, Jul 10, 2026 at 02:34:37PM +0000, Salvatore Dipietro wrote:
>> Commit 5d8edfb900d5 ("iomap: Copy larger chunks from userspace")
>> introduced high-order folio allocations in the iomap buffered write
>> path.
>
> https://lore.kernel.org/linux-mm/aeZzP6iQel-tkZOu@casper.infradead.org/
>
> I just had a go at implementing what I thought might be the right design
> (having a folio_alloc_orders(min, max, gfp)), but that's not really what
> __filemap_get_folio_mpol() wants because it needs to integrate the actual
> adding of folios to the page cache into the retry loop.
>
> So instead, let's try this. The idea is that we want to try direct reclaim
> _twice_. Once gently (ie with NORETRY specified) when we're trying to
> allocate the maximum order folio. But now that we've tried that once,
> there's no point trying direct reclaim for other sizes, we just want to
> ask the page allocator if it can give us memory of any subsequent size.
>
> Until we come to the minimum order. Then we want to try exactly as hard
> as we were originally asked to try. So revert to the original gfp flags
> and don't set the NOWARN or NORETRY flags.
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 58eb9d240643..23eecaf9b328 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1983,6 +1983,7 @@ struct folio *__filemap_get_folio_mpol(struct address_space *mapping,
> if (!folio && (fgp_flags & FGP_CREAT)) {
> unsigned int min_order = mapping_min_folio_order(mapping);
> unsigned int order = max(min_order, FGF_GET_ORDER(fgp_flags));
> + gfp_t alloc_gfp = gfp | __GFP_NORETRY | __GFP_NOWARN;
> int err;
> index = mapping_align_index(mapping, index);
Note here fgp_flags are checked and may alter gfp towards NOFS or NOWAIT or
add __GFP_WRITE. But alloc_gfp set above will ignore all that for >min_order
attempts, which isn't right. Probably doesn't affect Salvatore's evaluation
though.
> @@ -2004,12 +2005,11 @@ struct folio *__filemap_get_folio_mpol(struct address_space *mapping,
> order = __ffs(index);
>
> do {
> - gfp_t alloc_gfp = gfp;
> -
> err = -ENOMEM;
> - if (order > min_order)
> - alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN;
> + if (order == min_order)
> + alloc_gfp = gfp;
> folio = filemap_alloc_folio(alloc_gfp, order, policy);
> + alloc_gfp &= ~__GFP_DIRECT_RECLAIM;
> if (!folio)
> continue;
>
prev parent reply other threads:[~2026-07-22 12:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 14:34 Salvatore Dipietro
2026-07-10 15:22 ` Johannes Weiner
2026-07-10 18:03 ` Matthew Wilcox
2026-07-14 12:02 ` Salvatore Dipietro
2026-07-22 12:35 ` Vlastimil Babka (SUSE)
2026-07-22 12:17 ` Vlastimil Babka (SUSE) [this message]
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=15c65a4b-aa53-4218-baa4-7dbab3b9dbab@kernel.org \
--to=vbabka@kernel.org \
--cc=abuehaze@amazon.com \
--cc=akpm@linux-foundation.org \
--cc=alisaidi@amazon.com \
--cc=blakgeof@amazon.com \
--cc=brauner@kernel.org \
--cc=dgc@kernel.org \
--cc=dipietro.salvatore@gmail.com \
--cc=dipiets@amazon.it \
--cc=djwong@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hch@infradead.org \
--cc=jackmanb@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=ritesh.list@gmail.com \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®