From: Ryan Roberts <ryan.roberts@arm.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Ard Biesheuvel <ardb@kernel.org>,
Marc Zyngier <maz@kernel.org>,
Oliver Upton <oliver.upton@linux.dev>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Matthew Wilcox <willy@infradead.org>, Yu Zhao <yuzhao@google.com>,
Mark Rutland <mark.rutland@arm.com>,
David Hildenbrand <david@redhat.com>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
John Hubbard <jhubbard@nvidia.com>, Zi Yan <ziy@nvidia.com>,
Barry Song <21cnbao@gmail.com>,
Alistair Popple <apopple@nvidia.com>,
Yang Shi <shy828301@gmail.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>,
linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 01/16] mm: thp: Batch-collapse PMD with set_ptes()
Date: Mon, 18 Dec 2023 10:50:45 +0000 [thread overview]
Message-ID: <20231218105100.172635-2-ryan.roberts@arm.com> (raw)
In-Reply-To: <20231218105100.172635-1-ryan.roberts@arm.com>
Refactor __split_huge_pmd_locked() so that a present PMD can be
collapsed to PTEs in a single batch using set_ptes(). It also provides a
future opportunity to batch-add the folio to the rmap using David's new
batched rmap APIs.
This should improve performance a little bit, but the real motivation is
to remove the need for the arm64 backend to have to fold the contpte
entries. Instead, since the ptes are set as a batch, the contpte blocks
can be initially set up pre-folded (once the arm64 contpte support is
added in the next few patches). This leads to noticeable performance
improvement during split.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
mm/huge_memory.c | 59 ++++++++++++++++++++++++++++--------------------
1 file changed, 34 insertions(+), 25 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 6be1a380a298..fbf7e95ea983 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2535,15 +2535,16 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
pte = pte_offset_map(&_pmd, haddr);
VM_BUG_ON(!pte);
- for (i = 0, addr = haddr; i < HPAGE_PMD_NR; i++, addr += PAGE_SIZE) {
- pte_t entry;
- /*
- * Note that NUMA hinting access restrictions are not
- * transferred to avoid any possibility of altering
- * permissions across VMAs.
- */
- if (freeze || pmd_migration) {
+
+ /*
+ * Note that NUMA hinting access restrictions are not transferred to
+ * avoid any possibility of altering permissions across VMAs.
+ */
+ if (freeze || pmd_migration) {
+ for (i = 0, addr = haddr; i < HPAGE_PMD_NR; i++, addr += PAGE_SIZE) {
+ pte_t entry;
swp_entry_t swp_entry;
+
if (write)
swp_entry = make_writable_migration_entry(
page_to_pfn(page + i));
@@ -2562,28 +2563,36 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
entry = pte_swp_mksoft_dirty(entry);
if (uffd_wp)
entry = pte_swp_mkuffd_wp(entry);
- } else {
- entry = mk_pte(page + i, READ_ONCE(vma->vm_page_prot));
- if (write)
- entry = pte_mkwrite(entry, vma);
+
+ VM_WARN_ON(!pte_none(ptep_get(pte + i)));
+ set_pte_at(mm, addr, pte + i, entry);
+ }
+ } else {
+ pte_t entry;
+
+ entry = mk_pte(page, READ_ONCE(vma->vm_page_prot));
+ if (write)
+ entry = pte_mkwrite(entry, vma);
+ if (!young)
+ entry = pte_mkold(entry);
+ /* NOTE: this may set soft-dirty too on some archs */
+ if (dirty)
+ entry = pte_mkdirty(entry);
+ if (soft_dirty)
+ entry = pte_mksoft_dirty(entry);
+ if (uffd_wp)
+ entry = pte_mkuffd_wp(entry);
+
+ for (i = 0, addr = haddr; i < HPAGE_PMD_NR; i++, addr += PAGE_SIZE) {
if (anon_exclusive)
SetPageAnonExclusive(page + i);
- if (!young)
- entry = pte_mkold(entry);
- /* NOTE: this may set soft-dirty too on some archs */
- if (dirty)
- entry = pte_mkdirty(entry);
- if (soft_dirty)
- entry = pte_mksoft_dirty(entry);
- if (uffd_wp)
- entry = pte_mkuffd_wp(entry);
page_add_anon_rmap(page + i, vma, addr, RMAP_NONE);
+ VM_WARN_ON(!pte_none(ptep_get(pte + i)));
}
- VM_BUG_ON(!pte_none(ptep_get(pte)));
- set_pte_at(mm, addr, pte, entry);
- pte++;
+
+ set_ptes(mm, haddr, pte, entry, HPAGE_PMD_NR);
}
- pte_unmap(pte - 1);
+ pte_unmap(pte);
if (!pmd_migration)
page_remove_rmap(page, vma, true);
--
2.25.1
next prev parent reply other threads:[~2023-12-18 10:51 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-18 10:50 [PATCH v4 00/16] Transparent Contiguous PTEs for User Mappings Ryan Roberts
2023-12-18 10:50 ` Ryan Roberts [this message]
2023-12-18 17:40 ` [PATCH v4 01/16] mm: thp: Batch-collapse PMD with set_ptes() David Hildenbrand
2023-12-19 8:18 ` Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 02/16] mm: Batch-copy PTE ranges during fork() Ryan Roberts
2023-12-18 17:47 ` David Hildenbrand
2023-12-19 8:30 ` Ryan Roberts
2023-12-19 11:29 ` David Hildenbrand
2023-12-19 17:22 ` David Hildenbrand
2023-12-19 17:42 ` Ryan Roberts
2023-12-20 9:17 ` David Hildenbrand
2023-12-20 9:51 ` Ryan Roberts
2023-12-20 9:54 ` David Hildenbrand
2023-12-20 10:11 ` Ryan Roberts
2023-12-20 10:16 ` David Hildenbrand
2023-12-20 10:41 ` Ryan Roberts
2023-12-20 10:56 ` David Hildenbrand
2023-12-20 11:28 ` Ryan Roberts
2023-12-20 11:36 ` David Hildenbrand
2023-12-20 11:51 ` Ryan Roberts
2023-12-20 11:58 ` David Hildenbrand
2023-12-20 12:04 ` Ryan Roberts
2023-12-20 12:08 ` David Hildenbrand
2023-12-20 12:54 ` David Hildenbrand
2023-12-20 13:02 ` Ryan Roberts
2023-12-20 13:06 ` David Hildenbrand
2023-12-20 13:10 ` Ryan Roberts
2023-12-20 13:13 ` David Hildenbrand
2023-12-20 13:33 ` Ryan Roberts
2023-12-20 14:00 ` David Hildenbrand
2023-12-20 15:05 ` Ryan Roberts
2023-12-20 15:35 ` David Hildenbrand
2023-12-20 15:59 ` Ryan Roberts
2023-12-20 9:57 ` Ryan Roberts
2023-12-20 10:00 ` David Hildenbrand
2023-12-18 10:50 ` [PATCH v4 03/16] mm: Batch-clear PTE ranges during zap_pte_range() Ryan Roberts
2023-12-20 5:25 ` Alistair Popple
2023-12-18 10:50 ` [PATCH v4 04/16] arm64/mm: set_pte(): New layer to manage contig bit Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 05/16] arm64/mm: set_ptes()/set_pte_at(): " Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 06/16] arm64/mm: pte_clear(): " Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 07/16] arm64/mm: ptep_get_and_clear(): " Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 08/16] arm64/mm: ptep_test_and_clear_young(): " Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 09/16] arm64/mm: ptep_clear_flush_young(): " Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 10/16] arm64/mm: ptep_set_wrprotect(): " Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 11/16] arm64/mm: ptep_set_access_flags(): " Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 12/16] arm64/mm: ptep_get(): " Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 13/16] arm64/mm: Split __flush_tlb_range() to elide trailing DSB Ryan Roberts
2023-12-18 10:50 ` [PATCH v4 14/16] arm64/mm: Wire up PTE_CONT for user mappings Ryan Roberts
2024-01-15 15:14 ` Alexandre Ghiti
2024-01-15 16:27 ` Ryan Roberts
2024-01-15 21:23 ` Alexandre Ghiti
2024-01-16 14:44 ` Ryan Roberts
2024-01-16 20:41 ` Alexandre Ghiti
2023-12-18 10:50 ` [PATCH v4 15/16] arm64/mm: Implement new helpers to optimize fork() Ryan Roberts
2023-12-18 10:51 ` [PATCH v4 16/16] arm64/mm: Implement clear_ptes() to optimize exit, munmap, dontneed Ryan Roberts
2023-12-20 5:28 ` Alistair Popple
2023-12-20 8:42 ` Ryan Roberts
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=20231218105100.172635-2-ryan.roberts@arm.com \
--to=ryan.roberts@arm.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=anshuman.khandual@arm.com \
--cc=apopple@nvidia.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=david@redhat.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=james.morse@arm.com \
--cc=jhubbard@nvidia.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=ryabinin.a.a@gmail.com \
--cc=shy828301@gmail.com \
--cc=suzuki.poulose@arm.com \
--cc=vincenzo.frascino@arm.com \
--cc=wangkefeng.wang@huawei.com \
--cc=will@kernel.org \
--cc=willy@infradead.org \
--cc=yuzenghui@huawei.com \
--cc=yuzhao@google.com \
--cc=ziy@nvidia.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