mm-multi-gen-lru-support-page-table-walks.patch removed from -mm tree
The quilt patch titled
Subject: mm: multi-gen LRU: support page table walks
has been removed from the -mm tree. Its filename was
mm-multi-gen-lru-support-page-table-walks.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Yu Zhao <[email protected]>
Subject: mm: multi-gen LRU: support page table walks
Date: Sun, 18 Sep 2022 02:00:05 -0600
To further exploit spatial locality, the aging prefers to walk page tables to search for young PTEs and promote hot pages. A kill switch will be added in the next patch to disable this behavior. When disabled, the aging relies on the rmap only.
NB: this behavior has nothing similar with the page table scanning in the 2.4 kernel [1], which searches page tables for old PTEs, adds cold pages to swapcache and unmaps them.
To avoid confusion, the term "iteration" specifically means the traversal of an entire mm_struct list; the term "walk" will be applied to page tables and the rmap, as usual.
An mm_struct list is maintained for each memcg, and an mm_struct follows its owner task to the new memcg when this task is migrated. Given an lruvec, the aging iterates lruvec_memcg()->mm_list and calls walk_page_range() with each mm_struct on this list to promote hot pages before it increments max_seq.
When multiple page table walkers iterate the same list, each of them gets a unique mm_struct; therefore they can run concurrently. Page table walkers ignore any misplaced pages, e.g., if an mm_struct was migrated, pages it left in the previous memcg will not be promoted when its current memcg is under reclaim. Similarly, page table walkers will not promote pages from nodes other than the one under reclaim.
This patch uses the following optimizations when walking page tables:
1. It tracks the usage of mm_struct's between context switches so that page table walkers can skip processes that have been sleeping since the last iteration.
2. It uses generational Bloom filters to record populated branches so that page table walkers can reduce their search space based on the query results, e.g., to skip page tables containing mostly holes or misplaced pages.
3. It takes advantage of the accessed bit in non-leaf PMD entries when CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG=y.
4. It does not zigzag between a PGD table and the same PMD table spanning multiple VMAs. IOW, it finishes all the VMAs within the range of the same PMD table before it returns to a PGD table. This improves the cache performance for workloads that have large numbers of tiny VMAs [2], especially when CONFIG_PGTABLE_LEVELS=5.
Server benchmark results:
Single workload:
fio (buffered I/O): no change
Single workload:
memcached (anon): +[8, 10]%
Ops/sec KB/sec
patch1-7: 1147696.57 44640.29
patch1-8: 1245274.91 48435.66 Configurations:
no change
Client benchmark results:
kswapd profiles:
patch1-7
48.16% lzo1x_1_do_compress (real work)
8.20% page_vma_mapped_walk (overhead)
7.06% _raw_spin_unlock_irq
2.92% ptep_clear_flush
2.53% __zram_bvec_write
2.11% do_raw_spin_lock
2.02% memmove
1.93% lru_gen_look_around
1.56% free_unref_page_list
1.40% memset
patch1-8
49.44% lzo1x_1_do_compress (real work)
6.19% page_vma_mapped_walk (overhead)
5.97% _raw_spin_unlock_irq
3.13% get_pfn_folio
2.85% ptep_clear_flush
2.42% __zram_bvec_write
2.08% do_raw_spin_lock
1.92% memmove
1.44% alloc_zspage
1.36% memset Configurations:
no change
Thanks to the following developers for their efforts [3].
kernel test robot <[email protected]>
[1] https://lwn.net/Articles/23732/
[2] https://llvm.org/docs/ScudoHardenedAllocator.html
[3] https://lore.kernel.org/r/[email protected]/
---
fs/exec.c | 2 include/linux/memcontrol.h | 5 include/linux/mm_types.h | 76 ++ include/linux/mmzone.h | 56 + include/linux/swap.h | 4 kernel/exit.c | 1 kernel/fork.c | 9 kernel/sched/core.c | 1 mm/memcontrol.c | 25 mm/vmscan.c | 1010 ++++++++++++++++++++++++++++++++++- 10 files changed, 1172 insertions(+), 17 deletions(-)
fs/exec.c renamed from fs/exec.c~mm-multi-gen-lru-support-page-table-walks +2 -0
@@ -1014,6 +1014,7 @@ static int exec_mmap(struct mm_struct *m active_mm = tsk->active_mm; tsk->active_mm = mm; tsk->mm = mm; +lru_gen_add_mm (mm);/* * This prevents preemption while active_mm is being loaded and * it and mm are being updated, which could cause problems for
@@ -1029,6 +1030,7 @@ static int exec_mmap(struct mm_struct *m tsk->mm->vmacache_seqnum =0 ;vmacache_flush (tsk);task_unlock (tsk); +lru_gen_use_mm (mm);if (vfork)timens_on_fork (tsk->nsproxy, tsk);
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-multi-gen-lru-support-page-table-walks +5 -0
@@ -350,6 +350,11 @@ struct mem_cgroup {struct deferred_split deferred_split_queue;#endif +#ifdef CONFIG_LRU_GEN +/* per-memcg mm_struct list */ +struct lru_gen_mm_list mm_list; +#endif +struct mem_cgroup_per_node *nodeinfo[]; };
include/linux/mm_types.h renamed from include/linux/mm_types.h~mm-multi-gen-lru-support-page-table-walks +76 -0
88 lines not on this page · raw message
include/linux/mmzone.h renamed from include/linux/mmzone.h~mm-multi-gen-lru-support-page-table-walks +55 -1
80 lines not on this page · raw message
include/linux/swap.h renamed from include/linux/swap.h~mm-multi-gen-lru-support-page-table-walks +4 -0
@@ -162,6 +162,10 @@ union swap_header {*/ struct reclaim_state {unsigned long reclaimed_slab; +#ifdef CONFIG_LRU_GEN +/* per-thread mm walk data */ +struct lru_gen_mm_walk *mm_walk; +#endif };#ifdef __KERNEL__
kernel/exit.c renamed from kernel/exit.c~mm-multi-gen-lru-support-page-table-walks +1 -0
@@ -466,6 +466,7 @@ assign_new_owner: goto retry; }WRITE_ONCE (mm->owner, c); +lru_gen_migrate_mm (mm);task_unlock (c);put_task_struct (c); }
kernel/fork.c renamed from kernel/fork.c~mm-multi-gen-lru-support-page-table-walks +9 -0
@@ -1152,6 +1152,7 @@ static struct mm_struct *mm_init(struct goto fail_nocontext; mm->user_ns =get_user_ns (user_ns); +lru_gen_init_mm (mm);return mm; fail_nocontext:
@@ -1194,6 +1195,7 @@ static inline void __mmput(struct mm_str }if (mm->binfmt)module_put (mm->binfmt->module); +lru_gen_del_mm (mm);mmdrop (mm); }
@@ -2694,6 +2696,13 @@ pid_t kernel_clone(struct kernel_clone_aget_task_struct (p); } +if (IS_ENABLED (CONFIG_LRU_GEN ) && !(clone_flags &CLONE_VM )) { +/* lock the task to synchronize with memcg migration */ +task_lock (p); +lru_gen_add_mm (p->mm); +task_unlock (p); + } +wake_up_new_task (p);/* forking complete and child started to run, tell ptracer */
kernel/sched/core.c renamed from kernel/sched/core.c~mm-multi-gen-lru-support-page-table-walks +1 -0
@@ -5180,6 +5180,7 @@ context_switch(struct rq *rq, struct tas* finish_task_switch()'s mmdrop(). */ switch_mm_irqs_off (prev->active_mm, next->mm, next); +lru_gen_use_mm (next->mm);if (!prev->mm) {// from kernel /* will mmdrop() in finish_task_switch(). */
mm/memcontrol.c renamed from mm/memcontrol.c~mm-multi-gen-lru-support-page-table-walks +25 -0
@@ -6204,6 +6204,30 @@ static void mem_cgroup_move_task(void) }#endif +#ifdef CONFIG_LRU_GEN +static void mem_cgroup_attach (struct cgroup_taskset *tset) +{ +struct task_struct *task; +struct cgroup_subsys_state *css; + +/* find the first leader if there is any */ +cgroup_taskset_for_each_leader (task, css, tset) +break ; + +if (!task) +return ; + +task_lock (task); +if (task->mm &&READ_ONCE (task->mm->owner) == task) +lru_gen_migrate_mm (task->mm); +task_unlock (task); +} +#else +static void mem_cgroup_attach (struct cgroup_taskset *tset) +{ +} +#endif /* CONFIG_LRU_GEN */ +static int seq_puts_memcg_tunable (struct seq_file *m,unsigned long value) {if (value ==PAGE_COUNTER_MAX )
@@ -6609,6 +6633,7 @@ struct cgroup_subsys memory_cgrp_subsys .css_reset = mem_cgroup_css_reset, .css_rstat_flush = mem_cgroup_css_rstat_flush, .can_attach = mem_cgroup_can_attach, + .attach = mem_cgroup_attach, .cancel_attach = mem_cgroup_cancel_attach, .post_attach = mem_cgroup_move_task, .dfl_cftypes = memory_files,
mm/vmscan.c renamed from mm/vmscan.c~mm-multi-gen-lru-support-page-table-walks +994 -16
1,194 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are