ANDROID: mm: Create hooks for ZONE_MOVABLE allocs

Create a vendor hook inside of gfp_zone() to modify which allocations
get to enter ZONE_MOVABLE, by zeroing out __GFP_HIGHMEM inside of the
trace hook based on certain conditions.

Separately, create a trace hook in the readahead path to affect the
behavior of the tracehook in gfp_zone().

In 5.15, we had set_skip_swapcache_flags trace-hook in do_swap_page()
but commit ac26e9c7b809 ("ANDROID: cma: allow to use CMA in swap-in path")
added __GFP_CMA explicitly, so the set_skip_swapcache_flags trace hook
is no longer needed.

Note:	To comply with vendor hook guidlines, avoid including types.h in
	trace/hooks/mm.h and use unsigned int for gfp_t.

The original commit included a change to set __GFP_CMA in mm/memory.c,
but commit 988dc02 ("BACKPORT: mm: support large folios swap-in for sync
io devices") overwrote this, and __GFP_CMA is not currently set in
android16-6.12, so in the current commit, we decided to keep the status
quo, the missing __GFP_CMA flags will be added in a separate patch.

Bug: 330201547
Bug: 417417101
Change-Id: Idfa6b0b06b1b819d706c847e702bc94ddf7aa55a
Signed-off-by: Chris Goldsworthy <cgoldswo@codeaurora.org>
Signed-off-by: Sukadev Bhattiprolu <quic_sukadev@quicinc.com>
(cherry picked from commit 31feff06a014b0241a77c06162831ea027d2946d)
Signed-off-by: ying zuxin <11154159@vivo.com>
This commit is contained in:
Chris Goldsworthy
2024-03-17 23:52:20 -07:00
committed by Treehugger Robot
parent fb5cc85bab
commit 14abb0c187
6 changed files with 27 additions and 9 deletions

View File

@@ -543,3 +543,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_swapmem_gather_add_bypass);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_swapmem_gather_finish);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_oom_swapmem_gather_init);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_oom_swapmem_gather_finish);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_gfp_zone_flags);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_readahead_gfp_mask);

View File

@@ -127,7 +127,7 @@ static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags)
| 1 << (___GFP_MOVABLE | ___GFP_DMA32 | ___GFP_DMA | ___GFP_HIGHMEM) \
)
static inline enum zone_type gfp_zone(gfp_t flags)
static inline enum zone_type __gfp_zone(gfp_t flags)
{
enum zone_type z;
int bit = (__force int) (flags & GFP_ZONEMASK);
@@ -138,6 +138,8 @@ static inline enum zone_type gfp_zone(gfp_t flags)
return z;
}
enum zone_type gfp_zone(gfp_t flags);
/*
* There is only one page-allocator function, and two main namespaces to
* it. The alloc_page*() variants return 'struct page *' and as such

View File

@@ -683,11 +683,13 @@ static inline struct page *__page_cache_alloc(gfp_t gfp)
return &filemap_alloc_folio(gfp, 0)->page;
}
static inline gfp_t readahead_gfp_mask(struct address_space *x)
static inline gfp_t __readahead_gfp_mask(struct address_space *x)
{
return mapping_gfp_mask(x) | __GFP_NORETRY | __GFP_NOWARN;
}
gfp_t readahead_gfp_mask(struct address_space *x);
typedef int filler_t(struct file *, struct folio *);
pgoff_t page_cache_next_miss(struct address_space *mapping,

View File

@@ -52,18 +52,13 @@ DECLARE_RESTRICTED_HOOK(android_rvh_bitmap_find_best_next_area,
DECLARE_HOOK(android_vh_madvise_cold_pageout_skip,
TP_PROTO(struct vm_area_struct *vma, struct folio *folio, bool pageout, bool *need_skip),
TP_ARGS(vma, folio, pageout, need_skip));
/*
DECLARE_RESTRICTED_HOOK(android_rvh_set_skip_swapcache_flags,
TP_PROTO(gfp_t *flags),
TP_ARGS(flags), 1);
DECLARE_RESTRICTED_HOOK(android_rvh_set_gfp_zone_flags,
TP_PROTO(gfp_t *flags),
TP_PROTO(unsigned int *flags), /* gfp_t *flags */
TP_ARGS(flags), 1);
DECLARE_RESTRICTED_HOOK(android_rvh_set_readahead_gfp_mask,
TP_PROTO(gfp_t *flags),
TP_PROTO(unsigned int *flags), /* gfp_t *flags */
TP_ARGS(flags), 1);
*/
struct mem_cgroup;
DECLARE_HOOK(android_vh_mem_cgroup_alloc,
TP_PROTO(struct mem_cgroup *memcg),

View File

@@ -9,6 +9,7 @@
#include <linux/stddef.h>
#include <linux/mm.h>
#include <linux/mmzone.h>
#include <trace/hooks/mm.h>
struct pglist_data *first_online_pgdat(void)
{
@@ -111,3 +112,10 @@ int folio_xchg_last_cpupid(struct folio *folio, int cpupid)
return last_cpupid;
}
#endif
enum zone_type gfp_zone(gfp_t flags)
{
trace_android_rvh_set_gfp_zone_flags(&flags);
return __gfp_zone(flags);
}

View File

@@ -144,6 +144,15 @@ file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping)
}
EXPORT_SYMBOL_GPL(file_ra_state_init);
gfp_t readahead_gfp_mask(struct address_space *x)
{
gfp_t mask = __readahead_gfp_mask(x);
trace_android_rvh_set_readahead_gfp_mask(&mask);
return mask;
}
EXPORT_SYMBOL_GPL(readahead_gfp_mask);
static void read_pages(struct readahead_control *rac)
{
const struct address_space_operations *aops = rac->mapping->a_ops;