mm: multi-gen LRU scanning for page promotion
Subsystems (4)
cover mm: multi-gen LRU scanning for page promotion
This patch series introduces a software-based approach to identify hot pages for promotion in tiered memory systems, particularly those leveraging CXL-attached memory, by utilizing the Multi-Generational LRU (MGLRU) framework. This method is designed to complement hardware-based hotness detection mechanisms like Intel PMU sampling, AMD IBS, or dedicated CXL memory monitoring units, providing a more comprehensive view of page access patterns, similar to kmmscand [1].
We propose to utilize MGLRU's existing infrastructure to provide hot page information. A key benefit here is the reuse of the MGLRU page table walk code, thus avoiding the overhead and duplication of effort involved in implementing a separate page table scanning mechanism. The working set reporting proposal [2] also reuses MGLRU's infrastructure, but focuses on cold page detection. It provides its own aging daemon, which could additionally provide hot page information by integrating this proof-of-concept.
This series relies on kpromoted [3] as the migration engine to implement the promotion policies. This is just an early proof-of-concept RFC posted now in the context of LSFMM.
Kinsey Ho (2):
mm: mglru: generalize page table walk
mm: klruscand: use mglru scanning for page promotion
include/linux/mmzone.h | 5 ++ mm/Kconfig | 8 ++ mm/Makefile | 1 + mm/internal.h | 4 + mm/klruscand.c | 118 +++++++++++++++++++++++++++ mm/vmscan.c | 177 ++++++++++++++++++++++++++++++----------- 6 files changed, 267 insertions(+), 46 deletions(-) create mode 100644 mm/klruscand.c
Signature · 1 line
2.49.0.395.g12beb8f557-goog
RFC PATCH 1/2 mm: mglru: generalize page table walk
Refactor the existing MGLRU page table walking logic to make it resumable.
Additionally, introduce two hooks into the MGLRU page table walk:
accessed callback and flush callback. The accessed callback is called for each accessed page detected via the scanned accessed bit. The flush callback is called when the accessed callback reports an out of space error. This allows for processing pages in batches for efficiency.
With a generalised page table walk, introduce a new scan function which repeatedly scans on the same young generation and does not add a new young generation.
--- include/linux/mmzone.h | 5 ++ mm/internal.h | 4 + mm/vmscan.c | 177 ++++++++++++++++++++++++++++++----------- 3 files changed, 140 insertions(+), 46 deletions(-)
include/linux/mmzone.h +5 -0
@@ -511,6 +511,8 @@ struct lru_gen_mm_walk {unsigned long seq;/* the next address within an mm to scan */ unsigned long next_addr; +/* called for each accessed pte/pmd */ +int (*accessed_cb)(pfn_t pfn);/* to batch promoted pages */ int nr_pages[MAX_NR_GENS ][ANON_AND_FILE ][MAX_NR_ZONES ];/* to batch the mm stats */
@@ -518,6 +520,9 @@ struct lru_gen_mm_walk {/* total batched items */ int batched;int swappiness; +/* for the pmd under scanning */ +int nr_young_pte; +int nr_total_pte;bool force_scan; };
mm/internal.h +4 -0
@@ -476,6 +476,10 @@ extern unsigned long highest_memmap_pfn;bool folio_isolate_lru (struct folio *folio);void folio_putback_lru (struct folio *folio);extern void reclaim_throttle (pg_data_t *pgdat,enum vmscan_throttle_state reason); +void set_task_reclaim_state (struct task_struct *task, +struct reclaim_state *rs); +void lru_gen_scan_lruvec (struct lruvec *lruvec,unsigned long seq, +int (*accessed_cb)(pfn_t ),void (*flush_cb)(void ));/* * in mm/rmap.c:
mm/vmscan.c +131 -46
353 lines not on this page · raw message
Signature · 1 line
2.49.0.395.g12beb8f557-goog
RFC PATCH 2/2 mm: klruscand: use mglru scanning for page promotion
In reply to Kinsey HoIntroduce a new kernel daemon, klruscand, that periodically invokes the MGLRU page table walk. It leverages the new callbacks to gather access information and forwards it to the kpromoted daemon for promotion decisions.
This benefits from reusing the existing MGLRU page table walk infrastructure, which is optimized with features such as hierarchical scanning and bloom filters to reduce CPU overhead.
As an additional optimization to be added in the future, we can tune the scan intervals for each memcg.
--- mm/Kconfig | 8 ++++ mm/Makefile | 1 + mm/klruscand.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 mm/klruscand.c
mm/Kconfig +8 -0
@@ -1366,6 +1366,14 @@ config KPROMOTED Promote hot pages from lower tier to top tier by using the memory access information provided by various sources. +config KLRUSCAND + bool "Kernel lower tier access scan daemon" + default y + depends on KPROMOTED && LRU_GEN_WALKS_MMU + help + Scan for accesses from lower tiers by invoking MGLRU to perform + page table walks. + source "mm/damon/Kconfig" endmenu
mm/Makefile +1 -0
@@ -148,3 +148,4 @@ obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o obj-$(CONFIG_PT_RECLAIM) += pt_reclaim.o obj-$(CONFIG_KPROMOTED) += kpromoted.o +obj-$(CONFIG_KLRUSCAND) += klruscand.o
mm/klruscand.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.49.0.395.g12beb8f557-goog
Quoted 17 lines · Kinsey Ho
This patch series introduces a software-based approach to identify hot pages for promotion in tiered memory systems, particularly those leveraging CXL-attached memory, by utilizing the Multi-Generational LRU (MGLRU) framework. This method is designed to complement hardware-based hotness detection mechanisms like Intel PMU sampling, AMD IBS, or dedicated CXL memory monitoring units, providing a more comprehensive view of page access patterns, similar to kmmscand [1].
We propose to utilize MGLRU's existing infrastructure to provide hot page information. A key benefit here is the reuse of the MGLRU page table walk code, thus avoiding the overhead and duplication of effort involved in implementing a separate page table scanning mechanism. The working set reporting proposal [2] also reuses MGLRU's infrastructure, but focuses on cold page detection. It provides its own aging daemon, which could additionally provide hot page information by integrating this proof-of-concept.
Quoted 3 lines
This series relies on kpromoted [3] as the migration engine to implement the promotion policies. This is just an early proof-of-concept RFC posted now in the context of LSFMM.
Thanks for your patchset. I haven't looked at the patches in detail yet, but gave it a quick try with the micro-benchmark that I have been using.
The below numbers can be compared with the base numbers that I have posted here (https://lore.kernel.org/linux-mm/[email protected]/). Test 2 in the above link is the one I tried with this patchset.
kernel.numa_balancing = 0
demotion=true
cpufreq governor=performance
Benchmark run configuration:
Compute-node = 1 Memory-node = 2 Memory-size = 206158430208 Hot-region-size = 1073741824 Nr-hot-regions = 192 Access pattern = random Access granularity = 4096 Delay b/n accesses = 0 Load/store ratio = 50l50s THP used = no Nr accesses = 25769803776 Nr repetitions = 512
Benchmark completed in 605983205.0 us
numa_hit 63621437numa_miss 2721737numa_foreign 2721737numa_interleave 0numa_local 48243292numa_other 18099882pgpromote_success 0pgpromote_candidate 0pgdemote_kswapd 15409682pgdemote_direct 0pgdemote_khugepaged 0numa_pte_updates 0numa_huge_pte_updates 0numa_hint_faults 0numa_hint_faults_local 0numa_pages_migrated 19596pgmigrate_success 15429278pgmigrate_fail 256
kpromoted_recorded_accesses 27647687kpromoted_recorded_hwhints 0kpromoted_recorded_pgtscans 27647687kpromoted_record_toptier 0kpromoted_record_added 17184209kpromoted_record_exists 10463478kpromoted_mig_right_node 0kpromoted_mig_non_lru 404308kpromoted_mig_cold_old 6417567kpromoted_mig_cold_not_accessed 10342825kpromoted_mig_promoted 19509kpromoted_mig_dropped 17164700
When I try to get the same benchmark numbers for kpromoted driven by kmmscand, kpromoted gets overwhelmed with the amount of data that kmmdscand provides while no such issues with the amount of accesses reported by this patchset.
As I have mentioned earlier, the hot page categorization heuristics is simplistic in kpromoted and may not have been able to promote more pages than what it has for this benchmark.
Regards,
Bharata.
Yuanchu Xie
reviewerQuoted 3 lines · Bharata B Rao
Thanks for your patchset. I haven't looked at the patches in detail yet, but gave it a quick try with the micro-benchmark that I have been using.
Thanks for running the numbers. Unfortunately neither of us can attend LSF/MM in person, but we're excited about this opportunity for collaboration.
Quoted 24 lines
The below numbers can be compared with the base numbers that I have posted here
(https://lore.kernel.org/linux-mm/[email protected]/).
Test 2 in the above link is the one I tried with this patchset.kernel.numa_balancing = 0
demotion=true
cpufreq governor=performanceBenchmark run configuration:
Compute-node = 1 Memory-node = 2 Memory-size = 206158430208 Hot-region-size = 1073741824 Nr-hot-regions = 192 Access pattern = random Access granularity = 4096 Delay b/n accesses = 0 Load/store ratio = 50l50s THP used = no Nr accesses = 25769803776 Nr repetitions = 512
Quoted 1 line
Benchmark completed in 605983205.0 us
The benchmark does seem to complete in less time, but I'm not sure why especially given the small number of pages promoted. I think it would also be useful to see the usage breakdown of DRAM/CXL over time.
Quoted 20 lines
numa_hit63621437numa_miss2721737numa_foreign2721737numa_interleave0numa_local48243292numa_other18099882pgpromote_success0pgpromote_candidate0pgdemote_kswapd15409682pgdemote_direct0pgdemote_khugepaged0numa_pte_updates0numa_huge_pte_updates0numa_hint_faults0numa_hint_faults_local0numa_pages_migrated19596pgmigrate_success15429278pgmigrate_fail256
Quoted 4 lines
kpromoted_recorded_accesses27647687kpromoted_recorded_hwhints0kpromoted_recorded_pgtscans27647687kpromoted_record_toptier0
Makes sense, we skip toptier scanning
Quoted 7 lines
kpromoted_record_added17184209kpromoted_record_exists10463478kpromoted_mig_right_node0kpromoted_mig_non_lru404308kpromoted_mig_cold_old6417567kpromoted_mig_cold_not_accessed10342825kpromoted_mig_promoted19509
Compared to 611077 (IBS number) this is a lot lower.
Quoted 6 lines
kpromoted_mig_dropped17164700When I try to get the same benchmark numbers for kpromoted driven by kmmscand, kpromoted gets overwhelmed with the amount of data that kmmdscand provides while no such issues with the amount of accesses reported by this patchset.
The scan interval in this series is 4 seconds, while the kmmscand's pause between scanning is 16ms. So there're definitely some gaps here. The MGLRU page table walk also has a bunch of optimizations, and some of them are more focused on reclaim, so we might need to tweak some things there too.
Yuanchu