Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=18.9.28.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795911864; b=OOyl1J2iE/4jhY/bTviZrqPZoqaHx71NwnzKvMLXEKuv6q47ywXSlInr+nupR1iYWFPI pRxZr8DfxS4Akk/Vd7lTQwubA+y+/mEyhrYFXxp9t6x1k1tcDNFDBPLSE8AZfZY/OHOYR JcwqS3gVhyCWioJb6sHTEP+xhnMppGMj//R0lmn9rzohIyAphBvYdSUuY7YhKFoQfP95k yuvmiLJroDLJNJv5ua/KGLJwlwRAKZk9O/xZ6L1PhCWrZWMLmcS6teDKqFFkPIJ5uywJi plKmPEZiWdhiixiNh0TdwYT24X/gdYUD9CzvLnOKJfDrsDR1jmdet116joQ7sRCmA+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795911864; h=DMARC-Filter:Received:DKIM-Signature:Received:Date:From:To:Subject: Message-ID:MIME-Version:Content-Type:Content-Disposition; bh=1bk7x3a3seKCIB2CFqf1Nt/DQj5jrewLdDauL0m2YWU=; b=M7BzjqoJPj80ku8/dDVw59eXM+8lNHbQ+frSnjo2Jo86ARZBLeCy5yC8otATuDICu73T VLNCdL2NwIWSWNGncXlgwoa5NGM/Sw4xhRHUz1oO4Vr1rS6XdtsygExDeAn9ijOPnRnaz 5oZXDq2fkcJBGjXxuHfxdFEAMm2+VyF6aBmFiZB7zKOzfhsFo9eWITKzVn5GonvL2bacg ufJIPFwwFhuHRmK+DAnPfRCdbiu0kKnu79V5TWI7khf1Zod2YMk9LfWAjlE+Byj2s8NFz nLiYTs4au853HQg0/GLFYC4qijqRCM7aEAQcCNU4rUKbftdWlzR/luwAUn+EMwnFa9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mit.edu; spf=pass smtp.mailfrom=mit.edu; dkim=pass header.d=mit.edu header.i=@mit.edu header.a=rsa-sha256 header.s=outgoing header.b=IJLJVFDZ; arc=none smtp.remote-ip=18.9.28.11 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2094D606A31C for ; Sun, 29 Nov 2026 00:24:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2094D606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mit.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mit.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=mit.edu header.i=@mit.edu header.a=rsa-sha256 header.s=outgoing header.b=IJLJVFDZ Received: from trampoline.thunk.org (pool-173-48-111-191.bstnma.fios.verizon.net [173.48.111.191]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 6AT0O6gP014771 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 28 Nov 2026 19:24:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1795911850; bh=1bk7x3a3seKCIB2CFqf1Nt/DQj5jrewLdDauL0m2YWU=; h=Date:From:Subject:Message-ID:MIME-Version:Content-Type; b=IJLJVFDZsBShq+DWlQqPUUKLAdXn7E+ndpMV7n+xSowlgqT3lYC9MxqjSMzibuvsR 2j0uFTxePuGXio5V9nBYnPY3Bp98PuEpkzHjIKw6LWIWpJcOK1i92jKguj9daoRf0q mv00vuXfKfxd8pkF08q9n5mkl2tQEJJpw25KouNOoEtDYcw0uqKnbUvRqzdPo9MkxA GjgNQZrFyErub7g16POUNjP69W0ISCbjPJmsyU6rPTkULeNmNTaXU3fYqqAmju7tw/ m6w1oJNM53T4bZHC1ZUaoXFUMAqFfNYyC1yWbCxQndfu0iGJ9b4a7ypugEKaEgyxrn Oa8y9ZVBmg4VQ== Received: by trampoline.thunk.org (Postfix, from userid 15806) id 76D692E011A; Sat, 28 Nov 2026 19:24:06 -0500 (EST) Date: Sat, 28 Nov 2026 19:24:06 -0500 From: "Theodore Ts'o" To: Ext4 Developers List , linux-mm@kvack.org, Matthew Wilcox Subject: generic/255: read(2) returning ENOMEM on 64k file systems Message-ID: X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="pkqpdjaqk3uzcnwz" Content-Disposition: inline --pkqpdjaqk3uzcnwz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --pkqpdjaqk3uzcnwz Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="fix.patch" 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); --pkqpdjaqk3uzcnwz Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="direct-reclaim.patch" 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; --pkqpdjaqk3uzcnwz--