Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* generic/255: read(2) returning ENOMEM on 64k file systems
@ 2026-11-29  0:24 Theodore Ts'o
  2026-11-30  0:24 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Theodore Ts'o @ 2026-11-29  0:24 UTC (permalink / raw)
  To: Ext4 Developers List, linux-mm, Matthew Wilcox

[-- 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;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: generic/255: read(2) returning ENOMEM on 64k file systems
  2026-11-29  0:24 generic/255: read(2) returning ENOMEM on 64k file systems Theodore Ts'o
@ 2026-11-30  0:24 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30  0:24 UTC (permalink / raw)
  To: Theodore Ts'o, Ext4 Developers List, linux-mm, Matthew Wilcox

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mm: missing Signed-off-by trailer and informal RFC email commit
  message
- [High] mm: vmscan: bypassing compaction_ready() breaks costly
  __GFP_RETRY_MAYFAIL
- [Low] mm/filemap: missing Fixes trailer for minimum-order folio
  allocations
--

commit 6134b8058c4679c6f6ebfa5d61c0da90b8cc6fdd
Author: Theodore Ts'o <tytso@mit.edu>

> generic/255: read(2) returning ENOMEM on 64k file systems
>
> 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

[Severity: High]
This commit is missing a Signed-off-by: trailer.  In addition, the commit
message is written as an informal RFC mailing-list note discussing two
separate attached patches rather than a self-contained kernel changelog, and
the subject line lacks an mm: prefix while citing generic/255 instead of
generic/251.

[Severity: Low]
For the minimum folio order allocation failure in mm/filemap.c, should this
include a Fixes: tag for the commit that started allocating
mapping_min_folio_order() folios?

  Fixes: ab95d23bab22 ("filemap: allocate mapping_min_order folios in the page cache")

> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 6a1af9b92349f..66b8d1bcc0fd5 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;

[Severity: High]
Does bypassing compaction_ready() for all costly __GFP_RETRY_MAYFAIL
allocations force unconditional node reclaim and prevent compaction from
escalating to COMPACT_PRIO_SYNC_FULL when a zone already has plenty of free
base pages?

In __alloc_pages_slowpath(), the initial compact_first pass only runs
COMPACT_PRIO_ASYNC compaction before entering __alloc_pages_direct_reclaim().
compaction_ready() checks both whether the high-order watermark is already
met and whether free base pages satisfy compaction_suitable() above the high
watermark:

mm/vmscan.c:compaction_ready() {
	if (!gfp_compaction_allowed(sc->gfp_mask))
		return false;

	/* Allocation can already succeed, nothing to do */
	if (zone_watermark_ok(zone, sc->order, min_wmark_pages(zone),
			      sc->reclaim_idx, 0))
		return true;
    ...
	watermark = high_wmark_pages(zone);
	if (compaction_suitable(zone, sc->order, watermark, sc->reclaim_idx))
		return true;

	return false;
}

With compaction_ready() skipped, shrink_zones() unconditionally calls
shrink_node() on every node in the zonelist even when gigabytes of free
order-0..3 pages are already available for synchronous compaction.  Under
MGLRU, shrink_node() does not call should_continue_reclaim() and keeps
reclaiming until sc->nr_reclaimed reaches max(sc->nr_to_reclaim,
compact_gap(sc->order)).

Worse, if a zone has abundant free base pages for compaction but no
unprotected reclaimable LRU pages (for example, memory is already free in
lower orders or protected by memory.low), sc->compaction_ready remains false
and do_try_to_free_pages() cannot return 1 via its sc->compaction_ready
check.  Instead, direct reclaim scans all priorities down to 0, throttles in
VMSCAN_THROTTLE_NOPROGRESS, triggers the force_deactivate and
memcg_low_reclaim retry passes (breaching cgroup memory.low protection), and
returns 0.  A zero return from __perform_reclaim() causes
__alloc_pages_direct_reclaim() to skip drain_all_pages() and causes
__alloc_pages_slowpath() to skip should_compact_retry(), so compaction
never escalates to COMPACT_PRIO_SYNC_FULL.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/awsvBJeU3SGSdklm@mit.edu?part=1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30  0:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  0:24 generic/255: read(2) returning ENOMEM on 64k file systems Theodore Ts'o
2026-11-30  0:24 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox