Skip to contentSkip to conversation

mm/huge_memory: improve split_huge_page_to_list_to_order() return value documentation

PATCH Applied David Hildenbrand 2 participants 2 messages Apr 22, 2024 – Apr 23, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm/huge_memory: improve split_huge_page_to_list_to_order() return value documentation

The documentation is wrong and relying on it almost resulted in BUGs in new callers: ever since fd4a7ac32918 ("mm: migrate: try again if THP split is failed due to page refcnt") we return -EAGAIN on unexpected folio references, not -EBUSY.

Let's fix that and also document which other return values we can currently see and why they could happen.

---

v1 -> v2:
* Also document concurrent removal from the page cache (likely we should return -EBUSY -- but likely it doesn't really matter).
* Reference fd4a7ac32918 in patch description

---
 mm/huge_memory.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
mm/huge_memory.c +11 -3
index ee12726291f1b..a7406267323ed 100644
@@ -2956,7 +2956,7 @@ bool can_split_folio(struct folio *folio, int *pextra_pins)
  *
  * 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.
+ *    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
@@ -2975,8 +2975,16 @@ bool can_split_folio(struct folio *folio, int *pextra_pins)
  *
  * Returns 0 if the huge page was split successfully.
  *
- * Returns -EBUSY if @page's folio is pinned, or if the anon_vma disappeared
- * from under us.
+ * 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).
+ *
+ * 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)
Signature · 1 line
2.44.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 48 lines · David Hildenbrand

The documentation is wrong and relying on it almost resulted in BUGs in new callers: ever since fd4a7ac32918 ("mm: migrate: try again if THP split is failed due to page refcnt") we return -EAGAIN on unexpected folio references, not -EBUSY.

Let's fix that and also document which other return values we can currently see and why they could happen.

---

v1 -> v2:
* Also document concurrent removal from the page cache (likely we should return -EBUSY -- but likely it doesn't really matter).
* Reference fd4a7ac32918 in patch description

---
  mm/huge_memory.c | 14 +++++++++++---
  1 file changed, 11 insertions(+), 3 deletions(-)
mm/huge_memory.c +4 -3
index ee12726291f1b..a7406267323ed 100644
@@ -2956,7 +2956,7 @@ bool can_split_folio(struct folio *folio, int *pextra_pins)
   *
   * 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.
+ *    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
@@ -2975,8 +2975,16 @@ bool can_split_folio(struct folio *folio, int *pextra_pins)
   *
   * Returns 0 if the huge page was split successfully.
   *
- * Returns -EBUSY if @page's folio is pinned, or if the anon_vma disappeared
- * from under us.
+ * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if
+ * the folio was concurrently removed from the page cache.
+ *

mm/huge_memory.c bool can_split_folio(struct folio *folio, int *pextra_pins) · line 2990

Quoted 10 lines
mm/huge_memory.c +7 -0
+ * 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).
+ *
+ * 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)

LGTM. Thanks for fixing the document that I missed:)