[PATCH v3 1/5] x86/mm: avoid redundant checking if pgprot has no change

From: Bin Yang
Date: Mon Aug 20 2018 - 21:16:40 EST


In try_preserve_large_page(), the check for
pgprot_val(new_prot) == pgprot_val(old_port) can definitely
be done at first to avoid redundant checking.

The approach and some of the comments came from Thomas Gleixner's
email example for how to do this

Suggested-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Signed-off-by: Bin Yang <bin.yang@xxxxxxxxx>
---
arch/x86/mm/pageattr.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 8d6c34f..68613fd 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -629,6 +629,22 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,
new_prot = static_protections(req_prot, address, pfn);

/*
+ * The static_protections() is used to check specific protection flags
+ * for certain areas of memory. The old pgprot should be checked already
+ * when it was applied before. If it's not, then this is a bug in some
+ * other code and needs to be fixed there.
+ *
+ * If new pgprot is same as old pgprot, return directly without any
+ * additional checking. The following static_protections() checking is
+ * pointless if pgprot has no change. It can avoid the redundant
+ * checking and optimize the performance of large page split checking.
+ */
+ if (pgprot_val(new_prot) == pgprot_val(old_prot)) {
+ do_split = 0;
+ goto out_unlock;
+ }
+
+ /*
* We need to check the full range, whether
* static_protection() requires a different pgprot for one of
* the pages in the range we try to preserve:
@@ -642,14 +658,6 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,
goto out_unlock;
}

- /*
- * If there are no changes, return. maxpages has been updated
- * above:
- */
- if (pgprot_val(new_prot) == pgprot_val(old_prot)) {
- do_split = 0;
- goto out_unlock;
- }

/*
* We need to change the attributes. Check, whether we can
--
2.7.4