Skip to content

Commit e3f70d6

Browse files
author
Pengfei Li
committed
ANDROID: vendor_hook: Added hook for memory reclaim tuning
The following hooks are added for memory reclaim tuning: android_vh_mm_isolate_priv_lru - This hook is used to properly handle certain folios when they are reclaimed. android_vh_mm_customize_file_is_tiny - For a specific process, we want only anonymous pages to be reclaimed. This hook allows vendors to modify the value of file_is_tiny to affect the reclaim behavior. android_vh_mm_customize_pgdat_balanced - When there are multiple zones, it is not always reasonable to perform indirect reclaim only when all zones do not meet the watermark. This hook allows vendors to customize pgdat_balanced to use their own strategy to determine whether to perform and stop indirect collection. android_vh_mm_customize_reclaim_idx - When there are multiple zones, vendors use this hook to customize which zones can be reclaimed. android_vh_mm_customize_zone_can_compact - When there are multiple zones, vendors use this hook to customize which zones can be compacted. Bug: 431672372 Bug: 435545311 Change-Id: I860c2665088753a5c3b6d6dfeeb25a82aeefc8af Signed-off-by: Pengfei Li <pengfei.kernel@vivo.corp-partner.google.com> (cherry picked from commit 6c25b93a26385e5ab85750db953d2fedf5754e0e)
1 parent ee23c5c commit e3f70d6

File tree

5 files changed

+81
-2
lines changed

5 files changed

+81
-2
lines changed

drivers/android/vendor_hooks.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_customize_suitable_zone);
581581
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_customize_wmark_ok);
582582
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_customize_zone_max_order);
583583
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_customize_zone_pageset);
584+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_isolate_priv_lru);
585+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_customize_file_is_tiny);
586+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_customize_pgdat_balanced);
587+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_customize_reclaim_idx);
588+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_customize_zone_can_compact);

include/trace/hooks/compaction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ enum compact_result;
1919
DECLARE_HOOK(android_vh_compaction_try_to_compact_exit,
2020
TP_PROTO(enum compact_result *compact_result),
2121
TP_ARGS(compact_result));
22+
DECLARE_HOOK(android_vh_mm_customize_zone_can_compact,
23+
TP_PROTO(struct zone *zone, bool *can_compact),
24+
TP_ARGS(zone, can_compact));
2225
#endif /* _TRACE_HOOK_COMPACTION_H */
2326
/* This part must be outside protection */
2427
#include <trace/define_trace.h>

include/trace/hooks/vmscan.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ DECLARE_HOOK(android_vh_shrink_node_memcgs,
111111
DECLARE_HOOK(android_vh_shrink_node,
112112
TP_PROTO(pg_data_t *pgdat, struct mem_cgroup *memcg),
113113
TP_ARGS(pgdat, memcg));
114+
DECLARE_HOOK(android_vh_mm_isolate_priv_lru,
115+
TP_PROTO(unsigned long nr_to_scan, struct lruvec *lruvec, enum lru_list lru,
116+
struct list_head *dst, int reclaim_idx, bool may_unmap,
117+
unsigned long *nr_scanned, unsigned long *nr_taken),
118+
TP_ARGS(nr_to_scan, lruvec, lru, dst, reclaim_idx, may_unmap, nr_scanned, nr_taken));
119+
DECLARE_HOOK(android_vh_mm_customize_file_is_tiny,
120+
TP_PROTO(unsigned int may_swap, int order, int highest_zoneidx, bool *file_is_tiny),
121+
TP_ARGS(may_swap, order, highest_zoneidx, file_is_tiny));
122+
DECLARE_HOOK(android_vh_mm_customize_pgdat_balanced,
123+
TP_PROTO(int order, int highest_zoneidx, bool *balanced, bool *customized),
124+
TP_ARGS(order, highest_zoneidx, balanced, customized));
125+
DECLARE_HOOK(android_vh_mm_customize_reclaim_idx,
126+
TP_PROTO(int order, gfp_t gfp, s8 *reclaim_idx, enum zone_type *highest_zoneidx),
127+
TP_ARGS(order, gfp, reclaim_idx, highest_zoneidx));
114128
#endif /* _TRACE_HOOK_VMSCAN_H */
115129
/* This part must be outside protection */
116130
#include <trace/define_trace.h>

mm/compaction.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,11 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
28542854
for_each_zone_zonelist_nodemask(zone, z, ac->zonelist,
28552855
ac->highest_zoneidx, ac->nodemask) {
28562856
enum compact_result status;
2857+
bool can_compact = true;
2858+
2859+
trace_android_vh_mm_customize_zone_can_compact(zone, &can_compact);
2860+
if (!can_compact)
2861+
continue;
28572862

28582863
if (cpusets_enabled() &&
28592864
(alloc_flags & ALLOC_CPUSET) &&
@@ -2921,10 +2926,16 @@ void compact_node_async(int nid)
29212926
};
29222927

29232928
for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
2929+
bool can_compact = true;
2930+
29242931
zone = &pgdat->node_zones[zoneid];
29252932
if (!populated_zone(zone))
29262933
continue;
29272934

2935+
trace_android_vh_mm_customize_zone_can_compact(zone, &can_compact);
2936+
if (!can_compact)
2937+
continue;
2938+
29282939
if (fatal_signal_pending(current))
29292940
break;
29302941

@@ -2960,10 +2971,16 @@ static int compact_node(pg_data_t *pgdat, bool proactive)
29602971
};
29612972

29622973
for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
2974+
bool can_compact = true;
2975+
29632976
zone = &pgdat->node_zones[zoneid];
29642977
if (!populated_zone(zone))
29652978
continue;
29662979

2980+
trace_android_vh_mm_customize_zone_can_compact(zone, &can_compact);
2981+
if (!can_compact)
2982+
continue;
2983+
29672984
if (fatal_signal_pending(current))
29682985
return -EINTR;
29692986

@@ -3090,11 +3107,16 @@ static bool kcompactd_node_suitable(pg_data_t *pgdat)
30903107
enum compact_result ret;
30913108

30923109
for (zoneid = 0; zoneid <= highest_zoneidx; zoneid++) {
3110+
bool can_compact = true;
30933111
zone = &pgdat->node_zones[zoneid];
30943112

30953113
if (!populated_zone(zone))
30963114
continue;
30973115

3116+
trace_android_vh_mm_customize_zone_can_compact(zone, &can_compact);
3117+
if (!can_compact)
3118+
continue;
3119+
30983120
ret = compaction_suit_allocation_order(zone,
30993121
pgdat->kcompactd_max_order,
31003122
highest_zoneidx, ALLOC_WMARK_MIN);
@@ -3129,11 +3151,16 @@ static void kcompactd_do_work(pg_data_t *pgdat)
31293151

31303152
for (zoneid = 0; zoneid <= cc.highest_zoneidx; zoneid++) {
31313153
int status;
3154+
bool can_compact = true;
31323155

31333156
zone = &pgdat->node_zones[zoneid];
31343157
if (!populated_zone(zone))
31353158
continue;
31363159

3160+
trace_android_vh_mm_customize_zone_can_compact(zone, &can_compact);
3161+
if (!can_compact)
3162+
continue;
3163+
31373164
if (compaction_deferred(zone, cc.order))
31383165
continue;
31393166

mm/vmscan.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,12 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan,
17311731
unsigned long skipped = 0;
17321732
unsigned long scan, total_scan, nr_pages;
17331733
LIST_HEAD(folios_skipped);
1734+
unsigned long nr_scanned_before = *nr_scanned;
1735+
1736+
trace_android_vh_mm_isolate_priv_lru(nr_to_scan, lruvec, lru, dst, sc->reclaim_idx,
1737+
sc->may_unmap, nr_scanned, &nr_taken);
1738+
if (*nr_scanned != nr_scanned_before)
1739+
return nr_taken;
17341740

17351741
total_scan = 0;
17361742
scan = 0;
@@ -1989,7 +1995,7 @@ static unsigned long shrink_inactive_list(unsigned long nr_to_scan,
19891995
enum lru_list lru)
19901996
{
19911997
LIST_HEAD(folio_list);
1992-
unsigned long nr_scanned;
1998+
unsigned long nr_scanned = 0;
19931999
unsigned int nr_reclaimed = 0;
19942000
unsigned long nr_taken;
19952001
struct reclaim_stat stat;
@@ -2110,7 +2116,7 @@ static void shrink_active_list(unsigned long nr_to_scan,
21102116
enum lru_list lru)
21112117
{
21122118
unsigned long nr_taken;
2113-
unsigned long nr_scanned;
2119+
unsigned long nr_scanned = 0;
21142120
unsigned long vm_flags;
21152121
LIST_HEAD(l_hold); /* The folios which were snipped off */
21162122
LIST_HEAD(l_active);
@@ -2345,6 +2351,15 @@ static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru)
23452351
return inactive * inactive_ratio < active;
23462352
}
23472353

2354+
static void customize_sc_file_is_tiny(struct scan_control *sc)
2355+
{
2356+
bool file_is_tiny = sc->file_is_tiny;
2357+
2358+
trace_android_vh_mm_customize_file_is_tiny(sc->may_swap, sc->order,
2359+
sc->reclaim_idx, &file_is_tiny);
2360+
sc->file_is_tiny = file_is_tiny;
2361+
}
2362+
23482363
enum scan_balance {
23492364
SCAN_EQUAL,
23502365
SCAN_FRACT,
@@ -2458,6 +2473,8 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc)
24582473
!(sc->may_deactivate & DEACTIVATE_ANON) &&
24592474
anon >> sc->priority;
24602475
}
2476+
2477+
customize_sc_file_is_tiny(sc);
24612478
}
24622479

24632480
/*
@@ -6302,6 +6319,9 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
63026319
sc->reclaim_idx = gfp_zone(sc->gfp_mask);
63036320
}
63046321

6322+
trace_android_vh_mm_customize_reclaim_idx(sc->order, sc->gfp_mask,
6323+
&sc->reclaim_idx, NULL);
6324+
63056325
for_each_zone_zonelist_nodemask(zone, z, zonelist,
63066326
sc->reclaim_idx, sc->nodemask) {
63076327
/*
@@ -6853,8 +6873,15 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx)
68536873
{
68546874
int i;
68556875
unsigned long mark = -1;
6876+
bool customized = false;
6877+
bool balanced = false;
68566878
struct zone *zone;
68576879

6880+
trace_android_vh_mm_customize_pgdat_balanced(order, highest_zoneidx,
6881+
&balanced, &customized);
6882+
if (customized)
6883+
return balanced;
6884+
68586885
/*
68596886
* Check watermarks bottom-up as lower zones are more likely to
68606887
* meet watermarks.
@@ -7462,6 +7489,9 @@ void wakeup_kswapd(struct zone *zone, gfp_t gfp_flags, int order,
74627489
if (!cpuset_zone_allowed(zone, gfp_flags))
74637490
return;
74647491

7492+
trace_android_vh_mm_customize_reclaim_idx(order, gfp_flags, NULL,
7493+
&highest_zoneidx);
7494+
74657495
pgdat = zone->zone_pgdat;
74667496
curr_idx = READ_ONCE(pgdat->kswapd_highest_zoneidx);
74677497

0 commit comments

Comments
 (0)