mm: make faultaround produce old ptes
Subsystems (5)
PATCH v2 1/1 mm: make faultaround produce old ptes
Based on Kirill's patch [1].
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[2], as it makes vmscan think that these pages are hot and not push them out on first round.
During sparse file access faultaround gets more pages mapped and all of them are young. Under memory pressure, this makes vmscan swap out anon pages instead, or to drop other page cache pages which otherwise stay resident.
Modify faultaround to produce old ptes if sysctl 'want_old_faultaround_pte' is set, so they can easily be reclaimed under memory pressure.
This can to some extend defeat the purpose of faultaround on machines without hardware accessed bit as it will not help us with reducing the number of minor page faults.
Making the faultaround ptes old results in a unixbench regression for some architectures [3][4]. But on some architectures like arm64 it is not found to cause any regression.
unixbench shell8 scores on arm64 v8.2 hardware with CONFIG_ARM64_HW_AFDBM enabled (5 runs min, max, avg):
Base: (741,748,744)
With this patch: (739,748,743)
So by default produce young ptes and provide a sysctl option to make the ptes old.
[1] http://lkml.kernel.org/r/1463488366-47723-1-git-send-email-kirill.shutemov@linux.intel.com
[2] https://lkml.kernel.org/r/[email protected]
[3] https://marc.info/?l=linux-kernel&m=146582237922378&w=2
[4] https://marc.info/?l=linux-mm&m=146589376909424&w=2
---
V2:
1. Removed the arch hook and want_old_faultaround_pte is made a sysctl
2. Renamed FAULT_FLAG_MKOLD to FAULT_FLAG_PREFAULT_OLD (suggested by Jan Kara)
3. Removed the saved fault address from vmf (suggested by Jan Kara)
Documentation/sysctl/vm.txt | 22 ++++++++++++++++++++++ include/linux/mm.h | 3 +++ kernel/sysctl.c | 9 +++++++++ mm/filemap.c | 10 ++++++++++ mm/memory.c | 4 ++++ 5 files changed, 48 insertions(+)
Documentation/sysctl/vm.txt +22 -0
@@ -63,6 +63,7 @@ Currently, these files are in /proc/sys/vm: - vfs_cache_pressure - watermark_scale_factor - zone_reclaim_mode +- want_old_faultaround_pte ==============================================================
@@ -887,4 +888,25 @@ Allowing regular swap effectively restricts allocations to the local node unless explicitly overridden by memory policies or cpuset configurations. +============================================================= + +want_old_faultaround_pte: + +By default faultaround code produces young pte. When want_old_faultaround_pte is +set to 1, faultaround produces old ptes. + +During sparse file access faultaround gets more pages mapped and when all of +them are young (default), under memory pressure, this makes vmscan swap out anon +pages instead, or to drop other page cache pages which otherwise stay resident. +Setting want_old_faultaround_pte to 1 avoids this. + +Making the faultaround ptes old can result in performance regression on some +architectures. This is due to cycles spent in micro-fault for TLB lookup of old +entry. One such known test that shows a regression on x86 is unixbench shell8. +Set want_old_faultaround_pte to 1 on architectures which does not show this +regression or if the workload shows overall performance benefit with old +faultaround ptes. + +The default value is 0. + ============ End of Document =================================
include/linux/mm.h +3 -0
@@ -302,6 +302,7 @@ extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *,#define FAULT_FLAG_USER 0x40/* The fault originated in userspace */ #define FAULT_FLAG_REMOTE 0x80/* faulting for non current tsk/mm */ #define FAULT_FLAG_INSTRUCTION 0x100/* The fault was during an instruction fetch */ +#define FAULT_FLAG_PREFAULT_OLD 0x200/* Make faultaround ptes old */ #define FAULT_FLAG_TRACE \ { FAULT_FLAG_WRITE, "WRITE" }, \
@@ -2676,5 +2677,7 @@ static inline bool page_is_guard(struct page *page)static inline void setup_nr_node_ids (void ) {}#endif +extern int want_old_faultaround_pte; +#endif /* __KERNEL__ */ #endif /* _LINUX_MM_H */
kernel/sysctl.c +9 -0
@@ -1343,6 +1343,15 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write, .extra1 = &zero, .extra2 = &one_hundred, }, + { + .procname = "want_old_faultaround_pte", + .data = &want_old_faultaround_pte, + .maxlen = sizeof(want_old_faultaround_pte), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, #ifdef CONFIG_HUGETLB_PAGE { .procname = "nr_hugepages",
mm/filemap.c +10 -0
@@ -48,6 +48,8 @@#include <asm/mman.h> +int want_old_faultaround_pte; +/* * Shared mappings implemented 30.11.1994. It's not fully working yet, * though.
@@ -2677,6 +2679,14 @@ void filemap_map_pages(struct vm_fault *vmf,if (vmf->pte) vmf->pte += iter.index - last_pgoff; last_pgoff = iter.index; + +if (want_old_faultaround_pte) { +if (iter.index == vmf->pgoff) + vmf->flags &= ~FAULT_FLAG_PREFAULT_OLD ; +else + vmf->flags |=FAULT_FLAG_PREFAULT_OLD ; + } +if (alloc_set_pte (vmf,NULL , page)) goto unlock;unlock_page (page);
mm/memory.c +4 -0
@@ -3438,6 +3438,10 @@ int alloc_set_pte(struct vm_fault *vmf, struct mem_cgroup *memcg, entry =mk_pte (page, vma->vm_page_prot);if (write) entry =maybe_mkwrite (pte_mkdirty (entry), vma); + +if (vmf->flags &FAULT_FLAG_PREFAULT_OLD ) + entry =pte_mkold (entry); +/* copy-on-write page */ if (write && !(vma->vm_flags &VM_SHARED )) {inc_mm_counter_fast (vma->vm_mm,MM_ANONPAGES );
Signature · 8 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 71 lines · Vinayak Menon
Based on Kirill's patch [1].
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[2], as it makes vmscan think that these pages are hot and not push them out on first round.
During sparse file access faultaround gets more pages mapped and all of them are young. Under memory pressure, this makes vmscan swap out anon pages instead, or to drop other page cache pages which otherwise stay resident.
Modify faultaround to produce old ptes if sysctl '
want_old_faultaround_pte' is set, so they can easily be reclaimed under memory pressure.This can to some extend defeat the purpose of faultaround on machines without hardware accessed bit as it will not help us with reducing the number of minor page faults.
Making the faultaround ptes old results in a unixbench regression for some architectures [3][4]. But on some architectures like arm64 it is not found to cause any regression.
unixbench shell8 scores on arm64 v8.2 hardware with
CONFIG_ARM64_HW_AFDBMenabled (5 runs min, max, avg):
Base: (741,748,744)
With this patch: (739,748,743)So by default produce young ptes and provide a sysctl option to make the ptes old.
[1] http://lkml.kernel.org/r/1463488366-47723-1-git-send-email-kirill.shutemov@linux.intel.com
[2] https://lkml.kernel.org/r/[email protected]
[3] https://marc.info/?l=linux-kernel&m=146582237922378&w=2
[4] https://marc.info/?l=linux-mm&m=146589376909424&w=2Signed-off-by Vinayak Menon <[email protected]>---
V2:
1. Removed the arch hook andwant_old_faultaround_pteis made a sysctl
2. RenamedFAULT_FLAG_MKOLDtoFAULT_FLAG_PREFAULT_OLD(suggested by Jan Kara)
3. Removed the saved fault address from vmf (suggested by Jan Kara)Documentation/sysctl/vm.txt | 22 ++++++++++++++++++++++ include/linux/mm.h | 3 +++ kernel/sysctl.c | 9 +++++++++ mm/filemap.c | 10 ++++++++++ mm/memory.c | 4 ++++ 5 files changed, 48 insertions(+)Documentation/sysctl/vm.txt +6
-0@@ -63,6 +63,7 @@ Currently, these files are in /proc/sys/vm: - vfs_cache_pressure - watermark_scale_factor - zone_reclaim_mode +- want_old_faultaround_pte ==============================================================@@ -887,4 +888,25 @@ Allowing regular swap effectively restricts allocations to the local node unless explicitly overridden by memory policies or cpuset configurations. +============================================================= + +want_old_faultaround_pte: + +By default faultaround code produces young pte. When want_old_faultaround_pte is
Documentation/sysctl/vm.txt Allowing regular swap effectively restricts allocations to the local · line 905
Quoted 10 lines
Documentation/sysctl/vm.txt +10
-0+set to 1, faultaround produces old ptes. + +During sparse file access faultaround gets more pages mapped and when all of +them are young (default), under memory pressure, this makes vmscan swap out anon +pages instead, or to drop other page cache pages which otherwise stay resident. +Setting want_old_faultaround_pte to 1 avoids this. + +Making the faultaround ptes old can result in performance regression on some +architectures. This is due to cycles spent in micro-fault for TLB lookup of old +entry.
It's not for TLB lookup. Micro-fault would take page walk to set young bit in the pte.
Otherwise patch looks good to me.
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 76 lines · Kirill A. Shutemov
Quoted 75 lines · Vinayak Menon
Based on Kirill's patch [1].
Currently, faultaround code produces young pte. This can screw up vmscan behaviour[2], as it makes vmscan think that these pages are hot and not push them out on first round.
During sparse file access faultaround gets more pages mapped and all of them are young. Under memory pressure, this makes vmscan swap out anon pages instead, or to drop other page cache pages which otherwise stay resident.
Modify faultaround to produce old ptes if sysctl '
want_old_faultaround_pte' is set, so they can easily be reclaimed under memory pressure.This can to some extend defeat the purpose of faultaround on machines without hardware accessed bit as it will not help us with reducing the number of minor page faults.
Making the faultaround ptes old results in a unixbench regression for some architectures [3][4]. But on some architectures like arm64 it is not found to cause any regression.
unixbench shell8 scores on arm64 v8.2 hardware with
CONFIG_ARM64_HW_AFDBMenabled (5 runs min, max, avg):
Base: (741,748,744)
With this patch: (739,748,743)So by default produce young ptes and provide a sysctl option to make the ptes old.
[1] http://lkml.kernel.org/r/1463488366-47723-1-git-send-email-kirill.shutemov@linux.intel.com
[2] https://lkml.kernel.org/r/[email protected]
[3] https://marc.info/?l=linux-kernel&m=146582237922378&w=2
[4] https://marc.info/?l=linux-mm&m=146589376909424&w=2Signed-off-by Vinayak Menon <[email protected]>---
V2:
1. Removed the arch hook andwant_old_faultaround_pteis made a sysctl
2. RenamedFAULT_FLAG_MKOLDtoFAULT_FLAG_PREFAULT_OLD(suggested by Jan Kara)
3. Removed the saved fault address from vmf (suggested by Jan Kara)Documentation/sysctl/vm.txt | 22 ++++++++++++++++++++++ include/linux/mm.h | 3 +++ kernel/sysctl.c | 9 +++++++++ mm/filemap.c | 10 ++++++++++ mm/memory.c | 4 ++++ 5 files changed, 48 insertions(+)Documentation/sysctl/vm.txt +10
-0@@ -63,6 +63,7 @@ Currently, these files are in /proc/sys/vm: - vfs_cache_pressure - watermark_scale_factor - zone_reclaim_mode +- want_old_faultaround_pte ==============================================================@@ -887,4 +888,25 @@ Allowing regular swap effectively restricts allocations to the local node unless explicitly overridden by memory policies or cpuset configurations. +============================================================= + +want_old_faultaround_pte: + +By default faultaround code produces young pte. When want_old_faultaround_pte is +set to 1, faultaround produces old ptes. + +During sparse file access faultaround gets more pages mapped and when all of +them are young (default), under memory pressure, this makes vmscan swap out anon
Quoted 8 lines
Documentation/sysctl/vm.txt Allowing regular swap effectively restricts allocations to the local
Quoted 6 lines
Documentation/sysctl/vm.txt +6
-0+pages instead, or to drop other page cache pages which otherwise stay resident. +Setting want_old_faultaround_pte to 1 avoids this. + +Making the faultaround ptes old can result in performance regression on some +architectures. This is due to cycles spent in micro-fault for TLB lookup of old +entry.It's not for TLB lookup. Micro-fault would take page walk to set young bit in the pte.
Fixed it in v3. Thanks Kirill.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>