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 e220917fa507 ("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.]
Showing the changes to include (1 of 3 files). Show all
Unified · Split
| @@ -376,45 +376,30 @@ bool non_uniform_split_supported(struct folio *folio, unsigned int new_order, · 375 unmodified lines | |||
| 376 | int folio_split(struct folio *folio, unsigned int new_order, struct page *page, | 376 | int folio_split(struct folio *folio, unsigned int new_order, struct page *page, |
| 377 | struct list_head *list); | 377 | struct list_head *list); |
| 378 | /* | 378 | /* |
| 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. | ||
| 380 | * @folio: folio to be split | 381 | * @folio: folio to be split |
| 381 | * @page: split to order-0 at the given page | 382 | * @page: split to @new_order at the given page |
| 382 | * @list: store the after-split folios | 383 | * @new_order: the target split order |
| 383 | * | 384 | * |
| 384 | * Try to split a @folio at @page using non uniform split to order-0, if | 385 | * Try to split a @folio at @page using non uniform split to @new_order, if |
| 385 | * non uniform split is not supported, fall back to uniform split. | 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. | ||
| 386 | * | 389 | * |
| 387 | * Return: 0: split is successful, otherwise split failed. | 390 | * Return: 0: split is successful, otherwise split failed. |
| 388 | */ | 391 | */ |
| 389 | static inline int try_folio_split(struct folio *folio, struct page *page, | 392 | static inline int try_folio_split_to_order(struct folio *folio, |
| 390 | struct list_head *list) | 393 | struct page *page, unsigned int new_order) |
| 391 | { | 394 | { |
| 392 | int ret = min_order_for_split(folio); | 395 | if (!non_uniform_split_supported(folio, new_order, /* warns= */ false)) |
| 393 | 396 | return split_huge_page_to_list_to_order(&folio->page, NULL, | |
| 394 | if (ret < 0) | 397 | new_order); |
| 395 | return ret; | 398 | return folio_split(folio, new_order, page, NULL); |
| 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); | ||
| 401 | } | 399 | } |
| 402 | static inline int split_huge_page(struct page *page) | 400 | static inline int split_huge_page(struct page *page) |
| 403 | { | 401 | { |
| 404 | struct folio *folio = page_folio(page); | 402 | return split_huge_page_to_list_to_order(page, NULL, 0); |
| 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); | ||
| 418 | } | 403 | } |
| 419 | void deferred_split_folio(struct folio *folio, bool partially_mapped); | 404 | void deferred_split_folio(struct folio *folio, bool partially_mapped); |
| 420 | 405 | ||
| @@ -597,14 +582,20 @@ static inline int split_huge_page(struct page *page) · 176 unmodified lines | |||
| 597 | return -EINVAL; | 582 | return -EINVAL; |
| 598 | } | 583 | } |
| 599 | 584 | ||
| 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 | |||
| 600 | static inline int split_folio_to_list(struct folio *folio, struct list_head *list) | 591 | static inline int split_folio_to_list(struct folio *folio, struct list_head *list) |
| 601 | { | 592 | { |
| 602 | VM_WARN_ON_ONCE_FOLIO(1, folio); | 593 | VM_WARN_ON_ONCE_FOLIO(1, folio); |
| 603 | return -EINVAL; | 594 | return -EINVAL; |
| 604 | } | 595 | } |
| 605 | 596 | ||
| 606 | static inline int try_folio_split(struct folio *folio, struct page *page, | 597 | static inline int try_folio_split_to_order(struct folio *folio, |
| 607 | struct list_head *list) | 598 | struct page *page, unsigned int new_order) |
| 608 | { | 599 | { |
| 609 | VM_WARN_ON_ONCE_FOLIO(1, folio); | 600 | VM_WARN_ON_ONCE_FOLIO(1, folio); |
| 610 | return -EINVAL; | 601 | return -EINVAL; |