Re: [PATCH] mm/huge_memory.c: introduce folio_split_unmapped

Wei Yang
2025-11-14T03:21:11Z

On Fri, Nov 14, 2025 at 12:22:28PM +1100, Balbir Singh wrote:
[...]
>@@ -4079,6 +4091,36 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
> return ret;
> }
>
>+/*
>+ * This function is a helper for splitting folios that have already been unmapped.
>+ * The use case is that the device or the CPU can refuse to migrate THP pages in
>+ * the middle of migration, due to allocation issues on either side
>+ *
>+ * The high level code is copied from __folio_split, since the pages are anonymous
>+ * and are already isolated from the LRU, the code has been simplified to not
>+ * burden __folio_split with unmapped sprinkled into the code.
>+ *
>+ * None of the split folios are unlocked
>+ */
>+int folio_split_unmapped(struct folio *folio, unsigned int new_order)
>+{
>+ int extra_pins, ret = 0;
>+
>+ VM_WARN_ON_FOLIO(folio_mapped(folio), folio);
>+ VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio);
>+ VM_WARN_ON_ONCE_FOLIO(!folio_test_large(folio), folio);
>+

Compared with original logic, we did check folio_split_supported() and
check whether new_order is supported for the file system.

Currently folio_split_unmapped() only pass 0 as new_order, which looks good.
But for a generic helper, it looks reasonable to do the check, IMHO.

>+ if (!can_split_folio(folio, 1, &extra_pins))
>+ return -EAGAIN;
>+
>+ local_irq_disable();
>+ ret = __folio_freeze_and_split_unmapped(folio, new_order, &folio->page, NULL,
>+ NULL, false, NULL, SPLIT_TYPE_UNIFORM,
>+ 0, extra_pins);
>+ local_irq_enable();
>+ 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

--
Wei Yang
Help you, Help me