Skip to content

Commit

Permalink
ANDROID: mm: create vendor hooks for memory reclaim
Browse files Browse the repository at this point in the history
we try to adjust page reclaim operations based on the running task
and kernel memory pressure. Thus, we want to create some vendor hooks
into kernel6.1.

Firstly, we add ADNRROID_VENDOR_DATA into the struct scan_control,
special operations would be performed based on this special scan option.
We measure the importance of the current process in the system and
obtain its weight, which is recorded in ANDROID_VENDOR_DATA.

The hook function: trace_android_vh_modify_scan_control is added inside
of the function modify_scan_control() to adjust reclaim operations based
on memory pressure.

The hook function: trace_android_vh_should_continue_reclaim is added inside
of the function shrink_node() to decide if page_reclaim would continue
or not based on memory pressure.

The hook function: trace_android_vh_file_is_tiny_bypass is added into the
function prepare_scan_count() to decide if the file pages should be skipped
in condition to file refualts and memory pressure.

Bug: 279793370
Change-Id: I1efe9d3e866f37b0295c7cd94ec8ca0117a9bd4a
Signed-off-by: Dezhi Huang <[email protected]>
  • Loading branch information
Dezhi Huang authored and surenbaghdasaryan committed Jun 5, 2023
1 parent 8e6a28c commit 3e2dc32
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/android/vendor_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_psci_cpu_suspend);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_psi_event);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_psi_group);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpufreq_acct_update_power);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_modify_scan_control);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_should_continue_reclaim);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_file_is_tiny_bypass);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_mmc_resume);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_mmc_suspend);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_exit_signal);
Expand Down
12 changes: 12 additions & 0 deletions include/trace/hooks/vmscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ DECLARE_HOOK(android_vh_do_shrink_slab,
DECLARE_HOOK(android_vh_shrink_node_memcgs,
TP_PROTO(struct mem_cgroup *memcg, bool *skip),
TP_ARGS(memcg, skip));
DECLARE_HOOK(android_vh_modify_scan_control,
TP_PROTO(u64 *ext, unsigned long *nr_to_reclaim,
struct mem_cgroup *target_mem_cgroup,
bool *file_is_tiny, bool *may_writepage),
TP_ARGS(ext, nr_to_reclaim, target_mem_cgroup, file_is_tiny, may_writepage));
DECLARE_HOOK(android_vh_should_continue_reclaim,
TP_PROTO(u64 *ext, unsigned long *nr_to_reclaim,
unsigned long *nr_reclaimed, bool *continue_reclaim),
TP_ARGS(ext, nr_to_reclaim, nr_reclaimed, continue_reclaim));
DECLARE_HOOK(android_vh_file_is_tiny_bypass,
TP_PROTO(bool file_is_tiny, bool *bypass),
TP_ARGS(file_is_tiny, bypass));
#endif /* _TRACE_HOOK_VMSCAN_H */
/* This part must be outside protection */
#include <trace/define_trace.h>
29 changes: 29 additions & 0 deletions mm/vmscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct scan_control {

/* for recording the reclaimed slab by now */
struct reclaim_state reclaim_state;
ANDROID_VENDOR_DATA(1);
};

#ifdef ARCH_HAS_PREFETCHW
Expand Down Expand Up @@ -2805,6 +2806,7 @@ static void prepare_scan_count(pg_data_t *pgdat, struct scan_control *sc)
{
unsigned long file;
struct lruvec *target_lruvec;
bool bypass = false;

if (lru_gen_enabled())
return;
Expand Down Expand Up @@ -2866,6 +2868,11 @@ static void prepare_scan_count(pg_data_t *pgdat, struct scan_control *sc)
else
sc->cache_trim_mode = 0;


trace_android_vh_file_is_tiny_bypass(sc->file_is_tiny, &bypass);
if (bypass)
return;

/*
* Prevent the reclaimer from falling into the cache trap: as
* cache pages start out inactive, every cache fault will tip
Expand Down Expand Up @@ -6330,6 +6337,7 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat,
unsigned long pages_for_compaction;
unsigned long inactive_lru_pages;
int z;
bool continue_reclaim = true;

/* If not in reclaim/compaction mode, stop */
if (!in_reclaim_compaction(sc))
Expand Down Expand Up @@ -6373,6 +6381,11 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat,
if (can_reclaim_anon_pages(NULL, pgdat->node_id, sc))
inactive_lru_pages += node_page_state(pgdat, NR_INACTIVE_ANON);

trace_android_vh_should_continue_reclaim(&sc->android_vendor_data1,
&sc->nr_to_reclaim, &sc->nr_reclaimed, &continue_reclaim);
if (!continue_reclaim)
return false;

return inactive_lru_pages > pages_for_compaction;
}

Expand Down Expand Up @@ -6727,6 +6740,20 @@ static void snapshot_refaults(struct mem_cgroup *target_memcg, pg_data_t *pgdat)
target_lruvec->refaults[WORKINGSET_FILE] = refaults;
}

static void modify_scan_control(struct scan_control *sc)
{
bool file_is_tiny = false, may_writepage = true;

trace_android_vh_modify_scan_control(&sc->android_vendor_data1,
&sc->nr_to_reclaim, sc->target_mem_cgroup, &file_is_tiny,
&may_writepage);

if (file_is_tiny)
sc->file_is_tiny = true;
if (!may_writepage)
sc->may_writepage = false;
}

/*
* This is the main entry point to direct page reclaim.
*
Expand All @@ -6750,6 +6777,8 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
pg_data_t *last_pgdat;
struct zoneref *z;
struct zone *zone;

modify_scan_control(sc);
retry:
delayacct_freepages_start();

Expand Down

0 comments on commit 3e2dc32

Please sign in to comment.