From 3b8d7fd2b0fa2300e032d23acec37d4c4e7407ad Mon Sep 17 00:00:00 2001 From: Qianfeng Rong Date: Wed, 12 Mar 2025 17:13:55 +0800 Subject: [PATCH] ANDROID: vendor hooks: Add hooks to skip mglru aging For direct memory reclaim, aging can be skipped, and threads such as kswapd can be allowed to execute, reducing the time spent on direct memory reclaim. Why do we need to reseve 6 u64s OEM data? The two u64s parameters are used to tell kswapd how to age this lrugen. The other four u64s are used for two list heads to store some special pages. The size of 'struct lru_gen_folio' only affects the size of 'struct lruvec', the size of 'struct mem_cgroup_per_node' and the size of 'struct pglist_data'. The influence of OEM data: sizeof(struct lru_gen_folio) is changed from 960 to 1008. sizeof(struct lruvec) is changed from 1176 to 1224. sizeof(struct mem_cgroup_per_node) is changed from 1472 to 1536. sizeof(struct pglist_data) is changed from 7424 to 7488. The 'struct mem_cgroup_per_node' is alloc for in alloc_mem_cgroup_per_node_info() using kzalloc_node(). while the size of 'struct mem_cgroup_per_node' is 1472Byte. Due to alignment reasons, the memory size allocate is 2KB. Adding 6 u64s will not increase the alloc size. Bug: 402316914 Change-Id: Ib9667e83a8227a36e3adc63e84d73a6b529000a8 Signed-off-by: Qianfeng Rong [cmllamas: switch can_swap to swappiness] Signed-off-by: Carlos Llamas --- drivers/android/vendor_hooks.c | 1 + include/linux/mmzone.h | 2 ++ include/trace/hooks/vmscan.h | 5 +++++ mm/vmscan.c | 7 +++++++ 4 files changed, 15 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index ef8da5cc4c7c..09987377ca68 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -238,6 +238,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_oom_check_panic); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rmqueue_smallest_bypass); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_free_one_page_bypass); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_migration_target_bypass); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mglru_aging_bypass); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_shrink_node_memcgs_bypass); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_adjust_alloc_flags); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_tune_scan_type); diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index cbfd1d151c56..540432972d5a 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -480,6 +480,8 @@ struct lru_gen_folio { u8 seg; /* per-node lru_gen_folio list for global reclaim */ struct hlist_nulls_node list; + + ANDROID_OEM_DATA_ARRAY(1, 6); }; enum { diff --git a/include/trace/hooks/vmscan.h b/include/trace/hooks/vmscan.h index 97329e5f81cb..d6b1206c1852 100644 --- a/include/trace/hooks/vmscan.h +++ b/include/trace/hooks/vmscan.h @@ -10,6 +10,7 @@ #include struct mem_cgroup_reclaim_cookie; +struct lruvec; DECLARE_RESTRICTED_HOOK(android_rvh_set_balance_anon_file_reclaim, TP_PROTO(bool *balance_anon_file_reclaim), @@ -36,6 +37,10 @@ DECLARE_HOOK(android_vh_mglru_should_abort_scan, TP_PROTO(unsigned long nr_reclaimed, unsigned long nr_to_reclaim, unsigned int order, bool *bypass), TP_ARGS(nr_to_reclaim, nr_reclaimed, order, bypass)); +DECLARE_HOOK(android_vh_mglru_aging_bypass, + TP_PROTO(struct lruvec *lruvec, unsigned long max_seq, + int swappiness, bool *bypass, bool *young), + TP_ARGS(lruvec, max_seq, swappiness, bypass, young)); DECLARE_HOOK(android_vh_shrink_node_memcgs_bypass, TP_PROTO(u64 *ext, struct mem_cgroup_reclaim_cookie *partial, unsigned long nr_to_reclaim, unsigned long nr_reclaimed, diff --git a/mm/vmscan.c b/mm/vmscan.c index e0a9f699853d..af9a66cf99c3 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4816,6 +4816,8 @@ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc, int s unsigned long nr_to_scan; struct mem_cgroup *memcg = lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); + bool bypass = false; + bool young = false; if (mem_cgroup_below_min(sc->target_mem_cgroup, memcg)) return -1; @@ -4830,6 +4832,11 @@ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc, int s if (!success || sc->priority == DEF_PRIORITY) return nr_to_scan >> sc->priority; + trace_android_vh_mglru_aging_bypass(lruvec, max_seq, + swappiness, &bypass, &young); + if (bypass) + return young ? -1 : 0; + /* stop scanning this lruvec as it's low on cold folios */ return try_to_inc_max_seq(lruvec, max_seq, swappiness, false) ? -1 : 0; }