From: Xuefeng Wang <wxf.wang@hisilicon.com>
To: <catalin.marinas@arm.com>, <will@kernel.org>,
<mark.rutland@arm.com>, <arnd@arndb.de>,
<akpm@linux-foundation.org>
Cc: <linux-arch@vger.kernel.org>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>, <chenzhou10@huawei.com>,
Xuefeng Wang <wxf.wang@hisilicon.com>
Subject: [PATCH v2 2/2] arm64: mm: rework the pmd protect changing flow
Date: Thu, 23 Jan 2020 15:55:13 +0800 [thread overview]
Message-ID: <20200123075514.15142-3-wxf.wang@hisilicon.com> (raw)
In-Reply-To: <20200123075514.15142-1-wxf.wang@hisilicon.com>
On KunPeng920 board. When changing permission of a large range region,
pmdp_invalidate() takes about 65% in profile (with hugepages) in JIT tool.
Kernel will flush tlb twice: first flush happens in pmdp_invalidate, second
flush happens at the end of change_protect_range(). The first pmdp_invalidate
is not necessary if the hardware support atomic pmdp changing. The atomic
changing pimd to zero can prevent the hardware from update asynchronous.
So reconstruct it and remove the first pmdp_invalidate. And the second tlb
flush can make sure the new tlb entry valid.
Add pmdp_modify_prot_start() in arm64, which uses pmdp_huge_get_and_clear()
to fetch the pmd and zero entry, preventing racing of any hardware updates.
After rework, the mprotect can get 3~13 times performace gain in range
64M to 512M.
4K granule/THP on
memory size(M) 64 128 256 320 448 512
pre-patch 0.77 1.40 2.64 3.23 4.49 5.10
post-patch 0.20 0.23 0.28 0.31 0.37 0.39
Signed-off-by: Xuefeng Wang <wxf.wang@hisilicon.com>
Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
---
arch/arm64/include/asm/pgtable.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index cd5de0e40bfa..bccdaa5bd5f2 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -769,6 +769,20 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
}
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+#define __HAVE_ARCH_PMDP_MODIFY_PROT_TRANSACTION
+static inline pmd_t pmdp_modify_prot_start(struct vm_area_struct *vma,
+ unsigned long addr,
+ pmd_t *pmdp)
+{
+ /*
+ * Atomic change pmd to zero, prevent the hardware from update
+ * aynchronously update it.
+ */
+ return pmdp_huge_get_and_clear(vma->vm_mm, addr, pmdp);
+}
+#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
+
/*
* ptep_set_wrprotect - mark read-only while trasferring potential hardware
* dirty status (PTE_DBM && !PTE_RDONLY) to the software PTE_DIRTY bit.
--
2.17.1
next prev parent reply other threads:[~2020-01-23 7:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-23 7:55 [PATCH 0/2] mm/thp: " Xuefeng Wang
2020-01-23 7:55 ` [PATCH v2 1/2] mm: add helpers pmdp_modify_prot_start/commit Xuefeng Wang
2020-01-23 7:55 ` Xuefeng Wang [this message]
2020-01-23 8:24 ` [PATCH 0/2] mm/thp: rework the pmd protect changing flow Anshuman Khandual
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=20200123075514.15142-3-wxf.wang@hisilicon.com \
--to=wxf.wang@hisilicon.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=catalin.marinas@arm.com \
--cc=chenzhou10@huawei.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mark.rutland@arm.com \
--cc=will@kernel.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