From: "Theodore Ts'o" <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>,
linux-mm@kvack.org, Matthew Wilcox <willy@infradead.org>
Subject: generic/255: read(2) returning ENOMEM on 64k file systems
Date: Sat, 28 Nov 2026 19:24:06 -0500 [thread overview]
Message-ID: <awsvBJeU3SGSdklm@mit.edu> (raw)
[-- Attachment #1: Type: text/plain, Size: 2008 bytes --]
On systems with a 4k page size, when reading from a file system that
has a 64k block size, every page cache folio has an order of at least
4, which is above PAGE_ALLOC_COSTLY_ORDER (== 3). As a result, any
memory allocation without __GFP_RETRY_MAYFAIL or __GFP_NOFAIL can be
very prone to failure, even when there is gigabytes of memory
available.
This is causing the xfstests test generic/251 to fail 50-60% of the
time on my test appliance when running the ext4/64k configuration.
It's not clear what the best solution might be. Please note that this
is not ext4 specific. Any file system attempting to use a 64k block
size on a system with 4k blocks could run into this issue.
The simplest fix which the LLM came up with is the first attached
patch; it causes mm/filemap.c to use __GFP_RETRY_MAYFAIL when needed.
This is not a complete fix, however. The LLM came up with a more
reliable reproducer which fails nearly 100% of the time (25/26 runs),
using __GFP_RETRY_MAYFAIL beings it down to 4% of the time (1/23
runs)[1].
[1] https://github.com/tytso/ext4-artifacts/blob/main/2026-11-xfstests-test-fixes/evidence/mm251/findings.md#42-test-results
Using __GFP_NOFAIL makes it completely reliable (of course), as does
an additional patch which changes direct relcaim to be more aggressive
if __GFP_RETRY_MAYFAIL is passed (the second attached patch,
direct-reclaim.patch).
I believe the first patch shouldn't be _too_ controversial; but it's
not a complete solution. Is the second patch is the right way to go,
or would some other approach would be better?
Thanks in advance for suggestions and comments!
- Ted
P.S. For more details, you can read (in very exhausting detail) the
report from the LLM[2]. Other xfstests failures that I'm working
through can be found here[3].
[2] https://github.com/tytso/ext4-artifacts/blob/main/2026-11-xfstests-test-fixes/evidence/mm251/findings.md
[3] https://github.com/tytso/ext4-artifacts/blob/main/2026-11-xfstests-test-fixes/xfstests-fixes.md
[-- Attachment #2: fix.patch --]
[-- Type: text/x-diff, Size: 2430 bytes --]
diff --git a/mm/filemap.c b/mm/filemap.c
index a1b2ca5b933c..053aa6a5e580 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1956,6 +1956,21 @@ void *filemap_get_entry(struct address_space *mapping, pgoff_t index)
return folio;
}
+/*
+ * A folio of the mapping's minimum order is the smallest unit the page cache
+ * can use for this mapping, so there is no smaller order to fall back to and
+ * a failed allocation is reported to userspace as -ENOMEM. The page allocator
+ * gives up on orders above PAGE_ALLOC_COSTLY_ORDER after a single round of
+ * reclaim and compaction, which happens easily on a fragmented system that
+ * has plenty of reclaimable memory. Ask it to try harder in that case.
+ */
+static gfp_t filemap_min_order_gfp(gfp_t gfp, unsigned int min_order)
+{
+ if (min_order > PAGE_ALLOC_COSTLY_ORDER && !(gfp & __GFP_NORETRY))
+ gfp |= __GFP_RETRY_MAYFAIL;
+ return gfp;
+}
+
/**
* __filemap_get_folio_mpol - Find and get a reference to a folio.
* @mapping: The address_space to search.
@@ -2044,6 +2059,9 @@ struct folio *__filemap_get_folio_mpol(struct address_space *mapping,
err = -ENOMEM;
if (order > min_order)
alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN;
+ else
+ alloc_gfp = filemap_min_order_gfp(alloc_gfp,
+ min_order);
folio = filemap_alloc_folio(alloc_gfp, order, policy);
if (!folio)
continue;
@@ -2652,11 +2670,13 @@ static int filemap_create_folio(struct kiocb *iocb, struct folio_batch *fbatch)
int error;
unsigned int min_order = mapping_min_folio_order(mapping);
pgoff_t index;
+ gfp_t gfp;
if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
return -EAGAIN;
- folio = filemap_alloc_folio(mapping_gfp_mask(mapping), min_order, NULL);
+ gfp = filemap_min_order_gfp(mapping_gfp_mask(mapping), min_order);
+ folio = filemap_alloc_folio(gfp, min_order, NULL);
if (!folio)
return -ENOMEM;
if (iocb->ki_flags & IOCB_DONTCACHE)
@@ -4149,7 +4169,10 @@ static struct folio *do_read_cache_folio(struct address_space *mapping,
repeat:
folio = filemap_get_folio(mapping, index);
if (IS_ERR(folio)) {
- folio = filemap_alloc_folio(gfp, mapping_min_folio_order(mapping), NULL);
+ unsigned int min_order = mapping_min_folio_order(mapping);
+
+ folio = filemap_alloc_folio(filemap_min_order_gfp(gfp, min_order),
+ min_order, NULL);
if (!folio)
return ERR_PTR(-ENOMEM);
index = mapping_align_index(mapping, index);
[-- Attachment #3: direct-reclaim.patch --]
[-- Type: text/x-diff, Size: 446 bytes --]
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 6a1af9b92349..66b8d1bcc0fd 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -6680,6 +6680,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
*/
if (IS_ENABLED(CONFIG_COMPACTION) &&
sc->order > PAGE_ALLOC_COSTLY_ORDER &&
+ !(sc->gfp_mask & __GFP_RETRY_MAYFAIL) &&
compaction_ready(zone, sc)) {
sc->compaction_ready = true;
continue;
next reply other threads:[~2026-11-29 0:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 0:24 Theodore Ts'o [this message]
2026-11-30 0:24 ` generic/255: read(2) returning ENOMEM on 64k file systems sashiko-bot
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=awsvBJeU3SGSdklm@mit.edu \
--to=tytso@mit.edu \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.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.