generic/255: read(2) returning ENOMEM on 64k file systems
Subsystems (4)
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].
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
mm/filemap.c +25 -2
@@ -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);
mm/vmscan.c +1 -0
@@ -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 ;