mm-multi-gen-lru-groundwork.patch removed from -mm tree
The quilt patch titled
Subject: mm: multi-gen LRU: groundwork
has been removed from the -mm tree. Its filename was
mm-multi-gen-lru-groundwork.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: groundwork
Date: Sun, 18 Sep 2022 02:00:02 -0600
Evictable pages are divided into multiple generations for each lruvec. The youngest generation number is stored in lrugen->max_seq for both anon and file types as they are aged on an equal footing. The oldest generation numbers are stored in lrugen->min_seq[] separately for anon and file types as clean file pages can be evicted regardless of swap constraints. These three variables are monotonically increasing.
Generation numbers are truncated into order_base_2(MAX_NR_GENS+1) bits in order to fit into the gen counter in folio->flags. Each truncated generation number is an index to lrugen->lists[]. The sliding window technique is used to track at least MIN_NR_GENS and at most MAX_NR_GENS generations. The gen counter stores a value within [1, MAX_NR_GENS] while a page is on one of lrugen->lists[]. Otherwise it stores 0.
There are two conceptually independent procedures: "the aging", which produces young generations, and "the eviction", which consumes old generations. They form a closed-loop system, i.e., "the page reclaim". Both procedures can be invoked from userspace for the purposes of working set estimation and proactive reclaim. These techniques are commonly used to optimize job scheduling (bin packing) in data centers [1][2].
To avoid confusion, the terms "hot" and "cold" will be applied to the multi-gen LRU, as a new convention; the terms "active" and "inactive" will be applied to the active/inactive LRU, as usual.
The protection of hot pages and the selection of cold pages are based on page access channels and patterns. There are two access channels:
one through page tables and the other through file descriptors. The protection of the former channel is by design stronger because:
1. The uncertainty in determining the access patterns of the former channel is higher due to the approximation of the accessed bit.
2. The cost of evicting the former channel is higher due to the TLB flushes required and the likelihood of encountering the dirty bit.
3. The penalty of underprotecting the former channel is higher because applications usually do not prepare themselves for major page faults like they do for blocked I/O. E.g., GUI applications commonly use dedicated I/O threads to avoid blocking rendering threads.
There are also two access patterns: one with temporal locality and the other without. For the reasons listed above, the former channel is assumed to follow the former pattern unless VM_SEQ_READ or VM_RAND_READ is present; the latter channel is assumed to follow the latter pattern unless outlying refaults have been observed [3][4].
The next patch will address the "outlying refaults". Three macros, i.e., LRU_REFS_WIDTH, LRU_REFS_PGOFF and LRU_REFS_MASK, used later are added in this patch to make the entire patchset less diffy.
A page is added to the youngest generation on faulting. The aging needs to check the accessed bit at least twice before handing this page over to the eviction. The first check takes care of the accessed bit set on the initial fault; the second check makes sure this page has not been used since then. This protocol, AKA second chance, requires a minimum of two generations, hence MIN_NR_GENS.
[1] https://dl.acm.org/doi/10.1145/3297858.3304053
[2] https://dl.acm.org/doi/10.1145/3503222.3507731
[3] https://lwn.net/Articles/495543/
[4] https://lwn.net/Articles/815342/
---
fs/fuse/dev.c | 3 include/linux/mm_inline.h | 175 ++++++++++++++++++++++++++++ include/linux/mmzone.h | 102 ++++++++++++++++ include/linux/page-flags-layout.h | 13 +- include/linux/page-flags.h | 4 include/linux/sched.h | 4 kernel/bounds.c | 5 mm/Kconfig | 8 + mm/huge_memory.c | 3 mm/memcontrol.c | 2 mm/memory.c | 25 ++++ mm/mm_init.c | 6 mm/mmzone.c | 2 mm/swap.c | 11 + mm/vmscan.c | 75 ++++++++++++ 15 files changed, 424 insertions(+), 14 deletions(-)
fs/fuse/dev.c renamed from fs/fuse/dev.c~mm-multi-gen-lru-groundwork +2 -1
@@ -776,7 +776,8 @@ static int fuse_check_page(struct page * 1 << PG_active | 1 << PG_workingset | 1 << PG_reclaim | - 1 << PG_waiters))) { + 1 << PG_waiters | + LRU_GEN_MASK | LRU_REFS_MASK))) {dump_page (page,"fuse: trying to steal weird page" );return 1 ; }
include/linux/mm_inline.h renamed from include/linux/mm_inline.h~mm-multi-gen-lru-groundwork +175 -0
204 lines not on this page · raw message
include/linux/mmzone.h renamed from include/linux/mmzone.h~mm-multi-gen-lru-groundwork +102 -0
120 lines not on this page · raw message
include/linux/page-flags.h renamed from include/linux/page-flags.h~mm-multi-gen-lru-groundwork +2 -2
@@ -1058,7 +1058,7 @@ static __always_inline void __ClearPageA1UL << PG_private |1UL << PG_private_2 | \1UL << PG_writeback |1UL << PG_reserved | \1UL << PG_slab |1UL << PG_active | \ - 1UL << PG_unevictable | __PG_MLOCKED) + 1UL << PG_unevictable | __PG_MLOCKED | LRU_GEN_MASK)/* * Flags checked when a page is prepped for return by the page allocator.
@@ -1069,7 +1069,7 @@ static __always_inline void __ClearPageA* alloc-free cycle to prevent from reusing the page. */ #define PAGE_FLAGS_CHECK_AT_PREP \ - (PAGEFLAGS_MASK & ~__PG_HWPOISON) + ((PAGEFLAGS_MASK & ~__PG_HWPOISON) | LRU_GEN_MASK | LRU_REFS_MASK)#define PAGE_FLAGS_PRIVATE \ (1UL << PG_private | 1UL << PG_private_2)
include/linux/page-flags-layout.h renamed from include/linux/page-flags-layout.h~mm-multi-gen-lru-groundwork +8 -5
@@ -55,7 +55,8 @@#define SECTIONS_WIDTH 0#endif -#if ZONES_WIDTH +SECTIONS_WIDTH +NODES_SHIFT <=BITS_PER_LONG -NR_PAGEFLAGS +#if ZONES_WIDTH +LRU_GEN_WIDTH +SECTIONS_WIDTH +NODES_SHIFT \ + <=BITS_PER_LONG -NR_PAGEFLAGS #define NODES_WIDTH NODES_SHIFT#elif defined(CONFIG_SPARSEMEM_VMEMMAP )#error "Vmemmap: No space for nodes field in page flags"
@@ -89,8 +90,8 @@#define LAST_CPUPID_SHIFT 0#endif -#if ZONES_WIDTH +SECTIONS_WIDTH +NODES_WIDTH +KASAN_TAG_WIDTH +LAST_CPUPID_SHIFT \ - <=BITS_PER_LONG -NR_PAGEFLAGS +#if ZONES_WIDTH +LRU_GEN_WIDTH +SECTIONS_WIDTH +NODES_WIDTH + \ +KASAN_TAG_WIDTH +LAST_CPUPID_SHIFT <=BITS_PER_LONG -NR_PAGEFLAGS #define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT#else #define LAST_CPUPID_WIDTH 0
@@ -100,10 +101,12 @@#define LAST_CPUPID_NOT_IN_PAGE_FLAGS #endif -#if ZONES_WIDTH +SECTIONS_WIDTH +NODES_WIDTH +KASAN_TAG_WIDTH +LAST_CPUPID_WIDTH \ - >BITS_PER_LONG -NR_PAGEFLAGS +#if ZONES_WIDTH +LRU_GEN_WIDTH +SECTIONS_WIDTH +NODES_WIDTH + \ +KASAN_TAG_WIDTH +LAST_CPUPID_WIDTH >BITS_PER_LONG -NR_PAGEFLAGS #error "Not enough bits in page flags"#endif +#define LRU_REFS_WIDTH 0 +#endif #endif /* _LINUX_PAGE_FLAGS_LAYOUT */
include/linux/sched.h renamed from include/linux/sched.h~mm-multi-gen-lru-groundwork +4 -0
@@ -914,6 +914,10 @@ struct task_struct {#ifdef CONFIG_MEMCG unsigned in_user_fault:1;#endif +#ifdef CONFIG_LRU_GEN +/* whether the LRU algorithm may apply to this access */ + unsigned in_lru_fault:1; +#endif #ifdef CONFIG_COMPAT_BRK unsigned brk_randomized:1;#endif
kernel/bounds.c renamed from kernel/bounds.c~mm-multi-gen-lru-groundwork +5 -0
@@ -22,6 +22,11 @@ int main(void)DEFINE (NR_CPUS_BITS ,ilog2 (CONFIG_NR_CPUS ));#endif DEFINE (SPINLOCK_SIZE ,sizeof (spinlock_t)); +#ifdef CONFIG_LRU_GEN +DEFINE (LRU_GEN_WIDTH ,order_base_2 (MAX_NR_GENS +1 )); +#else +DEFINE (LRU_GEN_WIDTH ,0 ); +#endif /* End of constants */ return 0 ;
mm/huge_memory.c renamed from mm/huge_memory.c~mm-multi-gen-lru-groundwork +2 -1
@@ -2444,7 +2444,8 @@ static void __split_huge_page_tail(struc#ifdef CONFIG_64BIT (1L << PG_arch_2) | #endif - (1L << PG_dirty))); + (1L << PG_dirty) | + LRU_GEN_MASK | LRU_REFS_MASK));/* ->mapping in first tail page is compound_mapcount */ VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING,
mm/Kconfig renamed from mm/Kconfig~mm-multi-gen-lru-groundwork +8 -0
@@ -1118,6 +1118,14 @@ config PTE_MARKER_UFFD_WP purposes. It is required to enable userfaultfd write protection on file-backed memory types like shmem and hugetlbfs. +config LRU_GEN + bool "Multi-Gen LRU" + depends on MMU + # make sure folio->flags has enough spare bits + depends on 64BIT || !SPARSEMEM || SPARSEMEM_VMEMMAP + help + A high performance LRU implementation to overcommit memory. + source "mm/damon/Kconfig" endmenu
mm/memcontrol.c renamed from mm/memcontrol.c~mm-multi-gen-lru-groundwork +2 -0
@@ -5175,6 +5175,7 @@ static void __mem_cgroup_free(struct memstatic void mem_cgroup_free (struct mem_cgroup *memcg) { +lru_gen_exit_memcg (memcg);memcg_wb_domain_exit (memcg);__mem_cgroup_free (memcg); }
@@ -5233,6 +5234,7 @@ static struct mem_cgroup *mem_cgroup_all memcg->deferred_split_queue.split_queue_len =0 ;#endif idr_replace (&mem_cgroup_idr, memcg, memcg->id.id); +lru_gen_init_memcg (memcg);return memcg; fail:mem_cgroup_id_remove (memcg);
mm/memory.c renamed from mm/memory.c~mm-multi-gen-lru-groundwork +25 -0
@@ -5117,6 +5117,27 @@ static inline void mm_account_fault(struperf_sw_event (PERF_COUNT_SW_PAGE_FAULTS_MIN ,1 , regs, address); } +#ifdef CONFIG_LRU_GEN +static void lru_gen_enter_fault (struct vm_area_struct *vma) +{ +/* the LRU algorithm doesn't apply to sequential or random reads */ + current->in_lru_fault = !(vma->vm_flags & (VM_SEQ_READ |VM_RAND_READ )); +} + +static void lru_gen_exit_fault (void ) +{ + current->in_lru_fault = false; +} +#else +static void lru_gen_enter_fault (struct vm_area_struct *vma) +{ +} + +static void lru_gen_exit_fault (void ) +{ +} +#endif /* CONFIG_LRU_GEN */ +/* * By the time we get here, we already hold the mm semaphore *
@@ -5148,11 +5169,15 @@ vm_fault_t handle_mm_fault(struct vm_areif (flags &FAULT_FLAG_USER )mem_cgroup_enter_user_fault (); +lru_gen_enter_fault (vma); +if (unlikely (is_vm_hugetlb_page (vma))) ret =hugetlb_fault (vma->vm_mm, vma, address, flags);else ret =__handle_mm_fault (vma, address, flags); +lru_gen_exit_fault (); +if (flags &FAULT_FLAG_USER ) {mem_cgroup_exit_user_fault ();/*
mm/mm_init.c renamed from mm/mm_init.c~mm-multi-gen-lru-groundwork +4 -2
@@ -65,14 +65,16 @@ void __init mminit_verify_pageflags_layo shift =8 *sizeof (unsigned long ); width = shift -SECTIONS_WIDTH -NODES_WIDTH -ZONES_WIDTH - -LAST_CPUPID_SHIFT -KASAN_TAG_WIDTH ; + -LAST_CPUPID_SHIFT -KASAN_TAG_WIDTH -LRU_GEN_WIDTH -LRU_REFS_WIDTH ;mminit_dprintk (MMINIT_TRACE ,"pageflags_layout_widths" , -"Section %d Node %d Zone %d Lastcpupid %d Kasantag %d Flags %d\n" , +"Section %d Node %d Zone %d Lastcpupid %d Kasantag %d Gen %d Tier %d Flags %d\n" ,SECTIONS_WIDTH ,NODES_WIDTH ,ZONES_WIDTH ,LAST_CPUPID_WIDTH ,KASAN_TAG_WIDTH , +LRU_GEN_WIDTH , +LRU_REFS_WIDTH ,NR_PAGEFLAGS ); mminit_dprintk(MMINIT_TRACE, "pageflags_layout_shifts", "Section %d Node %d Zone %d Lastcpupid %d Kasantag %d\n",
mm/mmzone.c renamed from mm/mmzone.c~mm-multi-gen-lru-groundwork +2 -0
@@ -88,6 +88,8 @@ void lruvec_init(struct lruvec *lruvec)* Poison its list head, so that any operations on it would crash. */ list_del (&lruvec->lists[LRU_UNEVICTABLE ]); + +lru_gen_init_lruvec (lruvec); }#if defined(CONFIG_NUMA_BALANCING ) && !defined(LAST_CPUPID_NOT_IN_PAGE_FLAGS )
mm/swap.c renamed from mm/swap.c~mm-multi-gen-lru-groundwork +8 -3
@@ -484,6 +484,11 @@ void folio_add_lru(struct folio *folio) folio_test_unevictable(folio), folio);VM_BUG_ON_FOLIO (folio_test_lru (folio), folio); +/* see the comment in lru_gen_add_folio() */ +if (lru_gen_enabled () && !folio_test_unevictable (folio) && +lru_gen_in_fault () && !(current->flags &PF_MEMALLOC )) +folio_set_active (folio); +folio_get (folio);local_lock (&cpu_fbatches.lock); fbatch =this_cpu_ptr (&cpu_fbatches.lru_add);
@@ -575,7 +580,7 @@ static void lru_deactivate_file_fn(strucstatic void lru_deactivate_fn (struct lruvec *lruvec,struct folio *folio) { -if (folio_test_active (folio) && !folio_test_unevictable (folio)) { +if (!folio_test_unevictable (folio) && (folio_test_active (folio) ||lru_gen_enabled ())) {long nr_pages =folio_nr_pages (folio);lruvec_del_folio (lruvec, folio);
@@ -688,8 +693,8 @@ void deactivate_page(struct page *page) {struct folio *folio =page_folio (page); -if (folio_test_lru (folio) &&folio_test_active (folio) && - !folio_test_unevictable (folio)) { +if (folio_test_lru (folio) && !folio_test_unevictable (folio) && + (folio_test_active (folio) ||lru_gen_enabled ())) {struct folio_batch *fbatch;folio_get (folio);
mm/vmscan.c renamed from mm/vmscan.c~mm-multi-gen-lru-groundwork +75 -0
81 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are