From 71984f52233c2b3c62956a9012ded4d9535845ac Mon Sep 17 00:00:00 2001 From: Sooyong Suk Date: Thu, 11 Jul 2024 16:20:52 +0900 Subject: [PATCH] ANDROID: memcg: add vendor hook to use vm_swappiness Add vendor hook to use system-wide vm_swappiness. Refered to https://android-review.googlesource.com/c/kernel/common/+/2694466 to avoid build error issue with including include/trace/hooks/vmscan.h. Bug: 351175506 Change-Id: Iba3b71ade27c7d23787d26b3753e49a21358f0e8 Signed-off-by: Sooyong Suk --- drivers/android/vendor_hooks.c | 1 + include/linux/swap.h | 8 ++++++++ include/trace/hooks/vmscan.h | 3 +++ mm/memcontrol.c | 11 +++++++++++ 4 files changed, 23 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 67558027af6e..9bae0bfdcfc1 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -310,3 +310,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_pages_slowpath_end); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_contig_range_not_isolated); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_warn_alloc_tune_ratelimit); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_warn_alloc_show_mem_bypass); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_use_vm_swappiness); diff --git a/include/linux/swap.h b/include/linux/swap.h index d692fa6aab6f..c64ffb27f760 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -619,8 +619,16 @@ static inline void swap_free(swp_entry_t entry) } #ifdef CONFIG_MEMCG +extern void _trace_android_vh_use_vm_swappiness(bool *use_vm_swappiness); + static inline int mem_cgroup_swappiness(struct mem_cgroup *memcg) { + bool use_vm_swappiness = false; + + _trace_android_vh_use_vm_swappiness(&use_vm_swappiness); + if (use_vm_swappiness) + return READ_ONCE(vm_swappiness); + /* Cgroup2 doesn't have per-cgroup swappiness */ if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) return READ_ONCE(vm_swappiness); diff --git a/include/trace/hooks/vmscan.h b/include/trace/hooks/vmscan.h index 357d1bb1aacb..0b232178f6a5 100644 --- a/include/trace/hooks/vmscan.h +++ b/include/trace/hooks/vmscan.h @@ -43,6 +43,9 @@ DECLARE_HOOK(android_vh_do_shrink_slab, DECLARE_HOOK(android_vh_rebalance_anon_lru_bypass, TP_PROTO(bool *bypass), TP_ARGS(bypass)); +DECLARE_HOOK(android_vh_use_vm_swappiness, + TP_PROTO(bool *use_vm_swappiness), + TP_ARGS(use_vm_swappiness)); #endif /* _TRACE_HOOK_VMSCAN_H */ /* This part must be outside protection */ #include diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a40836c3212e..5ec7eaf42db4 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -73,6 +73,7 @@ #include #include +#include struct cgroup_subsys memory_cgrp_subsys __read_mostly; EXPORT_SYMBOL(memory_cgrp_subsys); @@ -116,6 +117,16 @@ struct mem_cgroup *vmpressure_to_memcg(struct vmpressure *vmpr) return container_of(vmpr, struct mem_cgroup, vmpressure); } +/* + * trace_android_vh_use_vm_swappiness is called in include/linux/swap.h by + * including include/trace/hooks/vmscan.h, which will result to build-err. + * So we create func: _trace_android_vh_use_vm_swappiness. + */ +void _trace_android_vh_use_vm_swappiness(bool *use_vm_swappiness) +{ + trace_android_vh_use_vm_swappiness(use_vm_swappiness); +} + #define CURRENT_OBJCG_UPDATE_BIT 0 #define CURRENT_OBJCG_UPDATE_FLAG (1UL << CURRENT_OBJCG_UPDATE_BIT)