From: Lance Yang <ioworker0@gmail.com>
To: david@redhat.com, ziy@nvidia.com
Cc: ioworker0@gmail.com, 21cnbao@gmail.com,
akpm@linux-foundation.org, fengwei.yin@intel.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
maskray@google.com, mhocko@suse.com, minchan@kernel.org,
peterx@redhat.com, ryan.roberts@arm.com, shy828301@gmail.com,
songmuchun@bytedance.com, wangkefeng.wang@huawei.com,
willy@infradead.org, xiehuan09@gmail.com, zokeefe@google.com
Subject: Re: [PATCH v2 1/1] mm/vmscan: avoid split PMD-mapped THP during shrink_folio_list()
Date: Thu, 25 Apr 2024 16:50:51 +0800 [thread overview]
Message-ID: <20240425085051.74889-1-ioworker0@gmail.com> (raw)
In-Reply-To: <CAK1f24nb6FkipH3OZa0uwbBWkefS3f2BrJ_GTxkS2j6+6bgODQ@mail.gmail.com>
Hey Zi, David,
How about this change(diff against mm-unstable) as follows?
I'd like to add __try_to_unmap_huge_pmd() as a new internal function
specifically for unmapping PMD-mapped folios. If, for any reason, we cannot
unmap the folio, then we'll still split it as previously done.
Currently, __try_to_unmap_huge_pmd() only handles lazyfree THPs, but it
can be extended to support other large folios that are PMD-mapped in the
future if needed.
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 670218f762c8..0f906dc6d280 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -100,8 +100,6 @@ enum ttu_flags {
* do a final flush if necessary */
TTU_RMAP_LOCKED = 0x80, /* do not grab rmap lock:
* caller holds it */
- TTU_LAZYFREE_THP = 0x100, /* avoid splitting PMD-mapped THPs
- * that are marked as lazyfree. */
};
#ifdef CONFIG_MMU
diff --git a/mm/rmap.c b/mm/rmap.c
index a7913a454028..879c8923abfc 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1606,6 +1606,19 @@ void folio_remove_rmap_pmd(struct folio *folio, struct page *page,
#endif
}
+static bool __try_to_unmap_huge_pmd(struct vm_area_struct *vma,
+ unsigned long addr, struct folio *folio)
+{
+ VM_WARN_ON_FOLIO(!folio_test_pmd_mappable(folio), folio);
+
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+ if (folio_test_anon(folio) && !folio_test_swapbacked(folio))
+ return discard_trans_pmd(vma, addr, folio);
+#endif
+
+ return false;
+}
+
/*
* @arg: enum ttu_flags will be passed to this argument
*/
@@ -1631,14 +1644,11 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
if (flags & TTU_SYNC)
pvmw.flags = PVMW_SYNC;
-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
- if (flags & TTU_LAZYFREE_THP)
- if (discard_trans_pmd(vma, address, folio))
+ if (flags & TTU_SPLIT_HUGE_PMD) {
+ if (__try_to_unmap_huge_pmd(vma, address, folio))
return true;
-#endif
-
- if (flags & TTU_SPLIT_HUGE_PMD)
split_huge_pmd_address(vma, address, false, folio);
+ }
/*
* For THP, we have to assume the worse case ie pmd for invalidation.
diff --git a/mm/vmscan.c b/mm/vmscan.c
index e2686cc0c037..49bd94423961 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1277,13 +1277,6 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
if (folio_test_pmd_mappable(folio))
flags |= TTU_SPLIT_HUGE_PMD;
-
-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
- if (folio_test_anon(folio) && !was_swapbacked &&
- (flags & TTU_SPLIT_HUGE_PMD))
- flags |= TTU_LAZYFREE_THP;
-#endif
-
/*
* Without TTU_SYNC, try_to_unmap will only begin to
* hold PTL from the first present PTE within a large
--
Thanks,
Lance
next prev parent reply other threads:[~2024-04-25 8:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-22 5:52 Lance Yang
2024-04-24 4:15 ` Matthew Wilcox
2024-04-24 7:17 ` David Hildenbrand
2024-04-24 15:57 ` Zi Yan
2024-04-24 15:58 ` David Hildenbrand
2024-04-25 4:17 ` Lance Yang
2024-04-25 8:50 ` Lance Yang [this message]
2024-04-25 9:01 ` David Hildenbrand
2024-04-25 9:21 ` Lance Yang
2024-04-25 9:25 ` David Hildenbrand
2024-04-25 12:00 ` Lance Yang
2024-04-24 15:46 ` Lance Yang
2024-04-24 21:20 ` Andrew Morton
2024-04-25 4:19 ` Lance 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=20240425085051.74889-1-ioworker0@gmail.com \
--to=ioworker0@gmail.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=fengwei.yin@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maskray@google.com \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=peterx@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--cc=songmuchun@bytedance.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
--cc=xiehuan09@gmail.com \
--cc=ziy@nvidia.com \
--cc=zokeefe@google.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