Skip to content

Commit 77008e1

Browse files
x-y-zakpm00
authored andcommitted
mm/huge_memory: do not change split_huge_page*() target order silently
Page cache folios from a file system that support large block size (LBS) can have minimal folio order greater than 0, thus a high order folio might not be able to be split down to order-0. Commit e220917 ("mm: split a folio in minimum folio order chunks") bumps the target order of split_huge_page*() to the minimum allowed order when splitting a LBS folio. This causes confusion for some split_huge_page*() callers like memory failure handling code, since they expect after-split folios all have order-0 when split succeeds but in reality get min_order_for_split() order folios and give warnings. Fix it by failing a split if the folio cannot be split to the target order. Rename try_folio_split() to try_folio_split_to_order() to reflect the added new_order parameter. Remove its unused list parameter. [The test poisons LBS folios, which cannot be split to order-0 folios, and also tries to poison all memory. The non split LBS folios take more memory than the test anticipated, leading to OOM. The patch fixed the kernel warning and the test needs some change to avoid OOM.] Link: https://lkml.kernel.org/r/20251017013630.139907-1-ziy@nvidia.com Fixes: e220917 ("mm: split a folio in minimum folio order chunks") Signed-off-by: Zi Yan <ziy@nvidia.com> Reported-by: syzbot+e6367ea2fdab6ed46056@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/68d2c943.a70a0220.1b52b.02b3.GAE@google.com/ Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Pankaj Raghav <p.raghav@samsung.com> Reviewed-by: Wei Yang <richard.weiyang@gmail.com> Acked-by: David Hildenbrand <david@redhat.com> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Reviewed-by: Miaohe Lin <linmiaohe@huawei.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Barry Song <baohua@kernel.org> Cc: David Hildenbrand <david@redhat.com> Cc: Dev Jain <dev.jain@arm.com> Cc: Jane Chu <jane.chu@oracle.com> Cc: Lance Yang <lance.yang@linux.dev> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Mariano Pache <npache@redhat.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Naoya Horiguchi <nao.horiguchi@gmail.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Christian Brauner <brauner@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent e9a6fb0 commit 77008e1

3 files changed

Lines changed: 28 additions & 42 deletions

File tree

include/linux/huge_mm.h

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -376,45 +376,30 @@ bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
376376
int folio_split(struct folio *folio, unsigned int new_order, struct page *page,
377377
struct list_head *list);
378378
/*
379-
* try_folio_split - try to split a @folio at @page using non uniform split.
379+
* try_folio_split_to_order - try to split a @folio at @page to @new_order using
380+
* non uniform split.
380381
* @folio: folio to be split
381-
* @page: split to order-0 at the given page
382-
* @list: store the after-split folios
382+
* @page: split to @new_order at the given page
383+
* @new_order: the target split order
383384
*
384-
* Try to split a @folio at @page using non uniform split to order-0, if
385-
* non uniform split is not supported, fall back to uniform split.
385+
* Try to split a @folio at @page using non uniform split to @new_order, if
386+
* non uniform split is not supported, fall back to uniform split. After-split
387+
* folios are put back to LRU list. Use min_order_for_split() to get the lower
388+
* bound of @new_order.
386389
*
387390
* Return: 0: split is successful, otherwise split failed.
388391
*/
389-
static inline int try_folio_split(struct folio *folio, struct page *page,
390-
struct list_head *list)
392+
static inline int try_folio_split_to_order(struct folio *folio,
393+
struct page *page, unsigned int new_order)
391394
{
392-
int ret = min_order_for_split(folio);
393-
394-
if (ret < 0)
395-
return ret;
396-
397-
if (!non_uniform_split_supported(folio, 0, false))
398-
return split_huge_page_to_list_to_order(&folio->page, list,
399-
ret);
400-
return folio_split(folio, ret, page, list);
395+
if (!non_uniform_split_supported(folio, new_order, /* warns= */ false))
396+
return split_huge_page_to_list_to_order(&folio->page, NULL,
397+
new_order);
398+
return folio_split(folio, new_order, page, NULL);
401399
}
402400
static inline int split_huge_page(struct page *page)
403401
{
404-
struct folio *folio = page_folio(page);
405-
int ret = min_order_for_split(folio);
406-
407-
if (ret < 0)
408-
return ret;
409-
410-
/*
411-
* split_huge_page() locks the page before splitting and
412-
* expects the same page that has been split to be locked when
413-
* returned. split_folio(page_folio(page)) cannot be used here
414-
* because it converts the page to folio and passes the head
415-
* page to be split.
416-
*/
417-
return split_huge_page_to_list_to_order(page, NULL, ret);
402+
return split_huge_page_to_list_to_order(page, NULL, 0);
418403
}
419404
void deferred_split_folio(struct folio *folio, bool partially_mapped);
420405

@@ -597,14 +582,20 @@ static inline int split_huge_page(struct page *page)
597582
return -EINVAL;
598583
}
599584

585+
static inline int min_order_for_split(struct folio *folio)
586+
{
587+
VM_WARN_ON_ONCE_FOLIO(1, folio);
588+
return -EINVAL;
589+
}
590+
600591
static inline int split_folio_to_list(struct folio *folio, struct list_head *list)
601592
{
602593
VM_WARN_ON_ONCE_FOLIO(1, folio);
603594
return -EINVAL;
604595
}
605596

606-
static inline int try_folio_split(struct folio *folio, struct page *page,
607-
struct list_head *list)
597+
static inline int try_folio_split_to_order(struct folio *folio,
598+
struct page *page, unsigned int new_order)
608599
{
609600
VM_WARN_ON_ONCE_FOLIO(1, folio);
610601
return -EINVAL;

mm/huge_memory.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,8 +3653,6 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
36533653

36543654
min_order = mapping_min_folio_order(folio->mapping);
36553655
if (new_order < min_order) {
3656-
VM_WARN_ONCE(1, "Cannot split mapped folio below min-order: %u",
3657-
min_order);
36583656
ret = -EINVAL;
36593657
goto out;
36603658
}
@@ -3986,12 +3984,7 @@ int min_order_for_split(struct folio *folio)
39863984

39873985
int split_folio_to_list(struct folio *folio, struct list_head *list)
39883986
{
3989-
int ret = min_order_for_split(folio);
3990-
3991-
if (ret < 0)
3992-
return ret;
3993-
3994-
return split_huge_page_to_list_to_order(&folio->page, list, ret);
3987+
return split_huge_page_to_list_to_order(&folio->page, list, 0);
39953988
}
39963989

39973990
/*

mm/truncate.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end)
194194
size_t size = folio_size(folio);
195195
unsigned int offset, length;
196196
struct page *split_at, *split_at2;
197+
unsigned int min_order;
197198

198199
if (pos < start)
199200
offset = start - pos;
@@ -223,8 +224,9 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end)
223224
if (!folio_test_large(folio))
224225
return true;
225226

227+
min_order = mapping_min_folio_order(folio->mapping);
226228
split_at = folio_page(folio, PAGE_ALIGN_DOWN(offset) / PAGE_SIZE);
227-
if (!try_folio_split(folio, split_at, NULL)) {
229+
if (!try_folio_split_to_order(folio, split_at, min_order)) {
228230
/*
229231
* try to split at offset + length to make sure folios within
230232
* the range can be dropped, especially to avoid memory waste
@@ -254,7 +256,7 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end)
254256
*/
255257
if (folio_test_large(folio2) &&
256258
folio2->mapping == folio->mapping)
257-
try_folio_split(folio2, split_at2, NULL);
259+
try_folio_split_to_order(folio2, split_at2, min_order);
258260

259261
folio_unlock(folio2);
260262
out:

0 commit comments

Comments
 (0)