Skip to content

Commit 1c4b406

Browse files
committed
x86/mm/cpa: Optimize same protection check
When the existing mapping is correct and the new requested page protections are the same as the existing ones, then further checks can be omitted and the large page can be preserved. The slow path 4k wise check will not come up with a different result. Before: 1G pages checked: 2 1G pages sameprot: 0 1G pages preserved: 0 2M pages checked: 540 2M pages sameprot: 466 2M pages preserved: 47 4K pages checked: 800709 4K pages set-checked: 7668 After: 1G pages checked: 2 1G pages sameprot: 0 1G pages preserved: 0 2M pages checked: 538 2M pages sameprot: 466 2M pages preserved: 47 4K pages checked: 560642 4K pages set-checked: 7668 Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Bin Yang <[email protected]> Cc: Mark Gross <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent f61c5ba commit 1c4b406

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

arch/x86/mm/pageattr.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,20 @@ static int __should_split_large_page(pte_t *kpte, unsigned long address,
839839
return 1;
840840
}
841841

842+
/*
843+
* Optimization: If the requested pgprot is the same as the current
844+
* pgprot, then the large page can be preserved and no updates are
845+
* required independent of alignment and length of the requested
846+
* range. The above already established that the current pgprot is
847+
* correct, which in consequence makes the requested pgprot correct
848+
* as well if it is the same. The static protection scan below will
849+
* not come to a different conclusion.
850+
*/
851+
if (pgprot_val(req_prot) == pgprot_val(old_prot)) {
852+
cpa_inc_lp_sameprot(level);
853+
return 0;
854+
}
855+
842856
/*
843857
* Make sure that the requested pgprot does not violate the static
844858
* protections. Check the full large page whether one of the pages

0 commit comments

Comments
 (0)