diff mbox series

huge_memory.c: document huge page splitting rules more thoroughly

Message ID 20240325044452.217463-1-jhubbard@nvidia.com (mailing list archive)
State New
Headers show
Series huge_memory.c: document huge page splitting rules more thoroughly | expand

Commit Message

John Hubbard March 25, 2024, 4:44 a.m. UTC
1. Add information about the behavior of huge page splitting, with
   respect to page/folio refcounts, and gup/pup pins.

2. Update and clarify the existing documentation, to compensate for the
   ravages of time and code change.

Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Zi Yan <ziy@nvidia.com>

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---

Hi David, Matthew, Zi,

This is a follow up from our short email thread of a week ago [1].

Zi, I've inflicted some minor violence upon your original wording, and
moved it into a Prerequisites section (item 4).


[1] https://lore.kernel.org/all/d9c06bec-805f-4d53-9f91-6b8ad29fcb6b@redhat.com/

thanks,
John Hubbard
NVIDIA

 mm/huge_memory.c | 42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)

Comments

Zi Yan March 25, 2024, 1:28 p.m. UTC | #1
On 25 Mar 2024, at 0:44, John Hubbard wrote:

> 1. Add information about the behavior of huge page splitting, with
>    respect to page/folio refcounts, and gup/pup pins.
>
> 2. Update and clarify the existing documentation, to compensate for the
>    ravages of time and code change.
>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: Zi Yan <ziy@nvidia.com>
>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> ---
>
> Hi David, Matthew, Zi,
>
> This is a follow up from our short email thread of a week ago [1].
>
> Zi, I've inflicted some minor violence upon your original wording, and
> moved it into a Prerequisites section (item 4).
>
>
> [1] https://lore.kernel.org/all/d9c06bec-805f-4d53-9f91-6b8ad29fcb6b@redhat.com/
>
> thanks,
> John Hubbard
> NVIDIA
>
>  mm/huge_memory.c | 42 +++++++++++++++++++++++++++---------------
>  1 file changed, 27 insertions(+), 15 deletions(-)
>
LGTM. Thanks. Reviewed-by: Zi Yan <ziy@nvidia.com>

--
Best Regards,
Yan, Zi
David Hildenbrand March 25, 2024, 2:05 p.m. UTC | #2
On 25.03.24 05:44, John Hubbard wrote:
> 1. Add information about the behavior of huge page splitting, with
>     respect to page/folio refcounts, and gup/pup pins.
> 
> 2. Update and clarify the existing documentation, to compensate for the
>     ravages of time and code change.
> 
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: Zi Yan <ziy@nvidia.com>
> 
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> ---

Thanks!

Reviewed-by: David Hildenbrand <david@redhat.com>
diff mbox series

Patch

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 9859aa4f7553..9f2354068359 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3013,28 +3013,40 @@  bool can_split_folio(struct folio *folio, int *pextra_pins)
 }
 
 /*
- * This function splits huge page into pages in @new_order. @page can point to
- * any subpage of huge page to split. Split doesn't change the position of
- * @page.
+ * 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.
  *
- * NOTE: order-1 anonymous folio is not supported because _deferred_list,
- * which is used by partially mapped folios, is stored in subpage 2 and an
- * order-1 folio only has subpage 0 and 1. File-backed order-1 folios are OK,
- * since they do not use _deferred_list.
+ * Prerequisites:
  *
- * Only caller must hold pin on the @page, otherwise split fails with -EBUSY.
- * The huge page must be locked.
+ * 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 -EBUSY.
+ *
+ * 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 mapping, flags, and so on from the hugepage.
+ * Pages in @new_order will inherit the mapping, flags, and so on from the
+ * huge page.
  *
- * GUP pin and PG_locked transferred to @page or the compound page @page belongs
- * to. Rest subpages can be freed if they are not mapped.
+ * Returns 0 if the huge page was split successfully.
  *
- * Returns 0 if the hugepage is split successfully.
- * Returns -EBUSY if the page is pinned or if anon_vma disappeared from under
- * us.
+ * Returns -EBUSY if @page's folio is pinned, or if the anon_vma disappeared
+ * from under us.
  */
 int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
 				     unsigned int new_order)