From: Wei Yang <richard.weiyang@gmail.com>
To: akpm@linux-foundation.org, david@kernel.org,
lorenzo.stoakes@oracle.com, ziy@nvidia.com,
baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com,
npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com,
baohua@kernel.org, lance.yang@linux.dev, linmiaohe@huawei.com,
nao.horiguchi@gmail.com
Cc: linux-mm@kvack.org, Wei Yang <richard.weiyang@gmail.com>
Subject: [RFC Patch 01/11] mm/huge_memory: relocate fundamental folio split comment to __folio_split()
Date: Mon, 8 Dec 2025 14:36:06 +0000 [thread overview]
Message-ID: <20251208143616.20797-2-richard.weiyang@gmail.com> (raw)
In-Reply-To: <20251208143616.20797-1-richard.weiyang@gmail.com>
The core function responsible for folio splitting has shifted over time.
Historically, the mechanism was documented primarily within
__split_huge_page_to_list_to_order().
However, the current central function for folio splitting is now
__folio_split().
To ensure documentation matches the current code structure, this commit
moves the fundamental mechanism comment to __folio_split().
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>
---
mm/huge_memory.c | 96 +++++++++++++++++++++++-------------------------
1 file changed, 46 insertions(+), 50 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 8db0d81fca40..37a73bfb96ff 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3911,15 +3911,61 @@ static int __folio_freeze_and_split_unmapped(struct folio *folio, unsigned int n
* @list: after-split folios will be put on it if non NULL
* @split_type: perform uniform split or not (non-uniform split)
*
+ * This function splits a large folio into smaller folios of order @new_order.
+ * @page can point to any page of the large folio to split. The split operation
+ * does not change the position of @page.
+ *
+ * Prerequisites:
+ *
+ * 1) The caller must hold a reference on the @page's owning folio, also known
+ * as the large folio.
+ *
+ * 2) The large folio must be locked.
+ *
+ * 3) The folio must not be pinned. Any unexpected folio references, including
+ * GUP pins, will result in the folio not getting split; instead, the caller
+ * will receive an -EAGAIN.
+ *
+ * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not
+ * supported for non-file-backed folios, because folio->_deferred_list, which
+ * is used by partially mapped folios, is stored in subpage 2, but an order-1
+ * folio only has subpages 0 and 1. File-backed order-1 folios are supported,
+ * since they do not use _deferred_list.
+ *
* It calls __split_unmapped_folio() to perform uniform and non-uniform split.
* It is in charge of checking whether the split is supported or not and
* preparing @folio for __split_unmapped_folio().
*
+ * After splitting, the caller's folio reference will be transferred to @page,
+ * resulting in a raised refcount of @page after this call. The other pages may
+ * be freed if they are not mapped.
+ *
* After splitting, the after-split folio containing @lock_at remains locked
* and others are unlocked:
* 1. for uniform split, @lock_at points to one of @folio's subpages;
* 2. for buddy allocator like (non-uniform) split, @lock_at points to @folio.
*
+ * If @list is null, tail pages will be added to LRU list, otherwise, to @list.
+ *
+ * Pages in @new_order will inherit the mapping, flags, and so on from the
+ * huge page.
+ *
+ * Returns 0 if the huge page was split successfully.
+ *
+ * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if
+ * the folio was concurrently removed from the page cache.
+ *
+ * Returns -EBUSY when trying to split the huge zeropage, if the folio is
+ * under writeback, if fs-specific folio metadata cannot currently be
+ * released, or if some unexpected race happened (e.g., anon VMA disappeared,
+ * truncation).
+ *
+ * Callers should ensure that the order respects the address space mapping
+ * min-order if one is set for non-anonymous folios.
+ *
+ * Returns -EINVAL when trying to split to an order that is incompatible
+ * with the folio. Splitting to order 0 is compatible with all folios.
+ *
* Return: 0 - successful, <0 - failed (if -ENOMEM is returned, @folio might be
* split but not to @new_order, the caller needs to check)
*/
@@ -4136,53 +4182,6 @@ int folio_split_unmapped(struct folio *folio, unsigned int new_order)
return ret;
}
-/*
- * This function splits a large folio into smaller folios of order @new_order.
- * @page can point to any page of the large folio to split. The split operation
- * does not change the position of @page.
- *
- * Prerequisites:
- *
- * 1) The caller must hold a reference on the @page's owning folio, also known
- * as the large folio.
- *
- * 2) The large folio must be locked.
- *
- * 3) The folio must not be pinned. Any unexpected folio references, including
- * GUP pins, will result in the folio not getting split; instead, the caller
- * will receive an -EAGAIN.
- *
- * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not
- * supported for non-file-backed folios, because folio->_deferred_list, which
- * is used by partially mapped folios, is stored in subpage 2, but an order-1
- * folio only has subpages 0 and 1. File-backed order-1 folios are supported,
- * since they do not use _deferred_list.
- *
- * After splitting, the caller's folio reference will be transferred to @page,
- * resulting in a raised refcount of @page after this call. The other pages may
- * be freed if they are not mapped.
- *
- * If @list is null, tail pages will be added to LRU list, otherwise, to @list.
- *
- * Pages in @new_order will inherit the mapping, flags, and so on from the
- * huge page.
- *
- * Returns 0 if the huge page was split successfully.
- *
- * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if
- * the folio was concurrently removed from the page cache.
- *
- * Returns -EBUSY when trying to split the huge zeropage, if the folio is
- * under writeback, if fs-specific folio metadata cannot currently be
- * released, or if some unexpected race happened (e.g., anon VMA disappeared,
- * truncation).
- *
- * Callers should ensure that the order respects the address space mapping
- * min-order if one is set for non-anonymous folios.
- *
- * Returns -EINVAL when trying to split to an order that is incompatible
- * with the folio. Splitting to order 0 is compatible with all folios.
- */
int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
unsigned int new_order)
{
@@ -4200,9 +4199,6 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list
* @list: after-split folios are added to @list if not null, otherwise to LRU
* list
*
- * It has the same prerequisites and returns as
- * split_huge_page_to_list_to_order().
- *
* Split a folio at @split_at to a new_order folio, leave the
* remaining subpages of the original folio as large as possible. For example,
* in the case of splitting an order-9 folio at its third order-3 subpages to
--
2.34.1
next prev parent reply other threads:[~2025-12-08 14:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 14:36 [RFC Patch 00/11] Convert huge page split API to folio-style Wei Yang
2025-12-08 14:36 ` Wei Yang [this message]
2025-12-08 14:36 ` [RFC Patch 02/11] mm/huge_memory: remove split_folio_to_list_to_order() helper Wei Yang
2025-12-08 14:36 ` [RFC Patch 03/11] mm/huge_memory: convert try_folio_split_to_order() to use split_folio_to_order() Wei Yang
2025-12-08 14:36 ` [RFC Patch 04/11] mm/memory-failure: convert try_to_split_thp_page() " Wei Yang
2025-12-08 14:36 ` [RFC Patch 05/11] mm/huge_memory: remove unused function split_huge_page_to_order() Wei Yang
2025-12-08 14:36 ` [RFC Patch 06/11] mm/huge_memory: introduce __split_folio_and_update_stats() to consolidate split task Wei Yang
2025-12-08 14:36 ` [RFC Patch 07/11] mm/huge_memory: separate uniform/non uniform split logic in __split_unmapped_folio() Wei Yang
2025-12-08 14:36 ` [RFC Patch 08/11] mm/huge_memory: restrict @split_at check to non-uniform splits Wei Yang
2025-12-08 14:36 ` [RFC Patch 09/11] mm/huge_memory: introduce folio_split_uniform() helper for uniform splitting Wei Yang
2025-12-08 14:36 ` [RFC Patch 10/11] mm/huge_memory: convert folio split helpers to use folio_split_uniform() Wei Yang
2025-12-08 14:36 ` [RFC Patch 11/11] mm/huge_memory: simplify split_huge_page() by calling __folio_split() directly Wei Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251208143616.20797-2-richard.weiyang@gmail.com \
--to=richard.weiyang@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=linmiaohe@huawei.com \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=nao.horiguchi@gmail.com \
--cc=npache@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox