Re: [PATCH v4 0/5] mm/rmap: Refactor try_to_unmap_one
From: Andrew Morton
Date: Thu Jul 30 2026 - 15:26:14 EST
On Thu, 30 Jul 2026 09:45:51 +0000 Dev Jain <dev.jain@xxxxxxx> wrote:
> In preparation for batching anonymous large folio unmapping to optimize it,
> refactor try_to_unmap_one. This series refactors hugetlb, anon-lazyfree
> and anon-swapbacked logic into their own functions, significantly
> reducing the length of the huge try_to_unmap_one.
>
Thanks, updated.
>
> v3->v4:
> - Tighten comment around TTU_HWPOISON
> - try_to_unmap_hugetlb_one -> try_to_unmap_poisoned_hugetlb_one
> - VM_WARN_ON -> VM_WARN_ON_ONCE
Here's how v4 altered mm.git:
mm/rmap.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
--- a/mm/rmap.c~b
+++ a/mm/rmap.c
@@ -1978,7 +1978,7 @@ static inline unsigned int folio_unmap_p
FPB_RESPECT_WRITE | FPB_RESPECT_SOFT_DIRTY);
}
-static bool try_to_unmap_hugetlb_one(struct folio *folio,
+static bool try_to_unmap_poisoned_hugetlb_one(struct folio *folio,
struct vm_area_struct *vma, unsigned long address, void *arg)
{
DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0);
@@ -1993,7 +1993,7 @@ static bool try_to_unmap_hugetlb_one(str
* The try_to_unmap() is only passed a hugetlb folio in the case
* where the hugetlb folio is poisoned.
*/
- VM_WARN_ON_FOLIO(!folio_test_hwpoison(folio), folio);
+ VM_WARN_ON_ONCE_FOLIO(!folio_test_hwpoison(folio), folio);
VM_WARN_ON_ONCE(!(flags & TTU_HWPOISON));
range.end = vma_address_end(&pvmw);
@@ -2031,7 +2031,7 @@ static bool try_to_unmap_hugetlb_one(str
if (!folio_test_anon(folio)) {
struct mmu_gather tlb;
- VM_WARN_ON(!(flags & TTU_RMAP_LOCKED));
+ VM_WARN_ON_ONCE(!(flags & TTU_RMAP_LOCKED));
if (!hugetlb_vma_trylock_write(vma)) {
ret = false;
goto walk_done;
@@ -2350,7 +2350,7 @@ static bool try_to_unmap_one(struct foli
/* Update high watermark before we lower rss */
update_hiwater_rss(mm);
- /* With TTU_HWPOISON, we only expect small folios here. */
+ /* unmap_poisoned_folio() only refs order-0 folios */
if (folio_test_hwpoison(folio) && (flags & TTU_HWPOISON)) {
pteval = swp_entry_to_pte(make_hwpoison_entry(page));
dec_mm_counter(mm, mm_counter(folio));
@@ -2440,7 +2440,7 @@ void try_to_unmap(struct folio *folio, e
{
struct rmap_walk_control rwc = {
.rmap_one = folio_test_hugetlb(folio) ?
- try_to_unmap_hugetlb_one : try_to_unmap_one,
+ try_to_unmap_poisoned_hugetlb_one : try_to_unmap_one,
.arg = (void *)flags,
.done = folio_not_mapped,
.anon_lock = folio_lock_anon_vma_read,
_