[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251025032221.2905818-23-libaokun@huaweicloud.com>
Date: Sat, 25 Oct 2025 11:22:18 +0800
From: libaokun@...weicloud.com
To: linux-ext4@...r.kernel.org
Cc: tytso@....edu,
adilger.kernel@...ger.ca,
jack@...e.cz,
linux-kernel@...r.kernel.org,
kernel@...kajraghav.com,
mcgrof@...nel.org,
linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org,
yi.zhang@...wei.com,
yangerkun@...wei.com,
chengzhihao1@...wei.com,
libaokun1@...wei.com,
libaokun@...weicloud.com
Subject: [PATCH 22/25] fs/buffer: prevent WARN_ON in __alloc_pages_slowpath() when BS > PS
From: Baokun Li <libaokun1@...wei.com>
In __alloc_pages_slowpath(), allocating page units greater than order-1
with the __GFP_NOFAIL flag may trigger an unexpected WARN_ON. To avoid
this, handle the case separately in grow_dev_folio(). This ensures that
buffer_head-based filesystems will not encounter the warning when using
__GFP_NOFAIL to read metadata after BS > PS support is enabled.
Signed-off-by: Baokun Li <libaokun1@...wei.com>
Reviewed-by: Zhang Yi <yi.zhang@...wei.com>
---
fs/buffer.c | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index 6a8752f7bbed..2f5a7dd199b2 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1031,6 +1031,35 @@ static sector_t folio_init_buffers(struct folio *folio,
return end_block;
}
+static struct folio *blkdev_get_folio(struct address_space *mapping,
+ pgoff_t index, fgf_t fgp_flags, gfp_t gfp)
+{
+ struct folio *folio;
+ unsigned int min_order = mapping_min_folio_order(mapping);
+
+ /*
+ * Allocating page units greater than order-1 with __GFP_NOFAIL in
+ * __alloc_pages_slowpath() can trigger an unexpected WARN_ON.
+ * Handle this case separately to suppress the warning.
+ */
+ if (min_order <= 1)
+ return __filemap_get_folio(mapping, index, fgp_flags, gfp);
+
+ while (1) {
+ folio = __filemap_get_folio(mapping, index, fgp_flags,
+ gfp & ~__GFP_NOFAIL);
+ if (!IS_ERR(folio) || !(gfp & __GFP_NOFAIL))
+ return folio;
+
+ if (PTR_ERR(folio) != -ENOMEM && PTR_ERR(folio) != -EAGAIN)
+ return folio;
+
+ memalloc_retry_wait(gfp);
+ }
+
+ return folio;
+}
+
/*
* Create the page-cache folio that contains the requested block.
*
@@ -1047,8 +1076,8 @@ static bool grow_dev_folio(struct block_device *bdev, sector_t block,
struct buffer_head *bh;
sector_t end_block = 0;
- folio = __filemap_get_folio(mapping, index,
- FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
+ folio = blkdev_get_folio(mapping, index,
+ FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
if (IS_ERR(folio))
return false;
--
2.46.1
Powered by blists - more mailing lists