From: Xu Yu <xuyu@linux.alibaba.com>
To: linux-mm@kvack.org
Cc: david@redhat.com
Subject: [PATCH v2 2/2] mm/khugepaged: add case for mapping anonymous pte-mapped THPs by pmds
Date: Thu, 7 Dec 2023 11:09:46 +0800 [thread overview]
Message-ID: <94575367298bc13d36937f15ac2cd1652684272f.1701917546.git.xuyu@linux.alibaba.com> (raw)
In-Reply-To: <cover.1701917546.git.xuyu@linux.alibaba.com>
This adds another case, as David points out, which is suitable for
mapping anonymous pte-mapped THPs by pmds. When all subpages are
PageAnonExclusive (PTEs may be either R/O or R/W), we can clear
PageAnonExclusive on all tail pages but the first (head) page and
collapse to a R/W PMD with VM_WRITE or a R/O PMD without VM_WRITE.
Signed-off-by: Xu Yu <xuyu@linux.alibaba.com>
---
mm/khugepaged.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 85c7a2ab44ce..5c51b09cb291 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1366,8 +1366,14 @@ static int collapse_pte_mapped_anon_thp(struct mm_struct *mm,
* Case 1:
* No subpages are PageAnonExclusive (PTEs must be R/O), we can
* collapse into a R/O PMD without further action.
+ *
+ * Case 2:
+ * All subpages are PageAnonExclusive (PTEs may be either R/O or R/W),
+ * we clear PageAnonExclusive on all tail pages but the head page and
+ * collapse to a R/W PMD with VM_WRITE or a R/O PMD without VM_WRITE.
*/
- if (!(exclusive == 0 && !writable))
+ if (!((exclusive == 0 && !writable) ||
+ (exclusive == HPAGE_PMD_NR)))
goto drop_hpage;
/* Collapse pmd entry */
@@ -1396,12 +1402,21 @@ static int collapse_pte_mapped_anon_thp(struct mm_struct *mm,
page = vm_normal_page(vma, addr, pteval);
page_remove_rmap(page, vma, false);
+
+ if (exclusive == HPAGE_PMD_NR)
+ ClearPageAnonExclusive(page);
}
pte_unmap_unlock(start_pte, ptl);
/* Install pmd entry */
pgtable = pmd_pgtable(pmdval);
pmdval = mk_huge_pmd(hpage, vma->vm_page_prot);
+
+ if (exclusive == HPAGE_PMD_NR) {
+ SetPageAnonExclusive(hpage);
+ pmdval = maybe_pmd_mkwrite(pmd_mkdirty(pmdval), vma);
+ }
+
spin_lock(pml);
page_add_anon_rmap(hpage, vma, haddr, RMAP_COMPOUND);
pgtable_trans_huge_deposit(mm, pmd, pgtable);
@@ -1596,7 +1611,9 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
out_unmap:
pte_unmap_unlock(pte, ptl);
- if (is_hpage && (exclusive == 0 && !writable)) {
+ if (is_hpage &&
+ ((exclusive == 0 && !writable) ||
+ (exclusive == HPAGE_PMD_NR))) {
int res;
res = collapse_pte_mapped_anon_thp(mm, vma, address,
--
2.37.1
next prev parent reply other threads:[~2023-12-07 3:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-13 9:05 [PATCH 0/1] mm/khugepaged: map " Xu Yu
2023-11-13 9:05 ` [PATCH 1/1] " Xu Yu
2023-11-13 9:26 ` David Hildenbrand
2023-11-13 9:33 ` Xu Yu
2023-11-13 10:10 ` David Hildenbrand
2023-12-07 3:09 ` [PATCH v2 0/2] attempt to " Xu Yu
2023-12-07 3:09 ` [PATCH v2 1/2] mm/khugepaged: " Xu Yu
2023-12-07 7:47 ` Xu Yu
2023-12-07 10:37 ` David Hildenbrand
2023-12-18 2:45 ` Xu Yu
2023-12-07 3:09 ` Xu Yu [this message]
2023-12-18 7:06 ` [PATCH v3 0/2] " Xu Yu
2023-12-18 7:06 ` [PATCH v3 1/2] mm/khugepaged: map RO non-exclusive pte-mapped anon " Xu Yu
2023-12-18 7:06 ` [PATCH v3 2/2] mm/khugepaged: map exclusive anonymous pte-mapped " Xu Yu
2023-12-21 20:40 ` [PATCH v3 0/2] attempt to map " Zach O'Keefe
2023-12-21 20:54 ` David Hildenbrand
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=94575367298bc13d36937f15ac2cd1652684272f.1701917546.git.xuyu@linux.alibaba.com \
--to=xuyu@linux.alibaba.com \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
/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