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 <rongqianfeng@vivo.corp-partner.google.com>
[cmllamas: switch can_swap to swappiness]
Signed-off-by: Carlos Llamas <cmllamas@google.com>
This commit is contained in:
Qianfeng Rong
2025-03-12 17:13:55 +08:00
committed by Carlos Llamas
parent a68f9ac139
commit 3b8d7fd2b0
4 changed files with 15 additions and 0 deletions
+1
View File
@@ -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);
+2
View File
@@ -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 {
+5
View File
@@ -10,6 +10,7 @@
#include <trace/hooks/vendor_hooks.h>
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,
+7
View File
@@ -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;
}