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.

Bug: 158645321
Change-Id: Idfa6b0b06b1b819d706c847e702bc94ddf7aa55a
Signed-off-by: Chris Goldsworthy <cgoldswo@codeaurora.org>
Signed-off-by: Sukadev Bhattiprolu <quic_sukadev@quicinc.com>
This commit is contained in:
Chris Goldsworthy 2020-11-09 22:26:47 -08:00 committed by Carlos Llamas
parent 31f15608bb
commit 342be123fd
8 changed files with 39 additions and 15 deletions

View File

@ -3509,6 +3509,8 @@
__traceiter_android_rvh_select_task_rq_rt
__traceiter_android_rvh_set_balance_anon_file_reclaim
__traceiter_android_rvh_set_cpus_allowed_by_task
__traceiter_android_rvh_set_gfp_zone_flags
__traceiter_android_rvh_set_readahead_gfp_mask
__traceiter_android_rvh_setscheduler
__traceiter_android_rvh_set_task_cpu
__traceiter_android_rvh_set_user_nice
@ -3639,6 +3641,8 @@
__tracepoint_android_rvh_select_task_rq_rt
__tracepoint_android_rvh_set_balance_anon_file_reclaim
__tracepoint_android_rvh_set_cpus_allowed_by_task
__tracepoint_android_rvh_set_gfp_zone_flags
__tracepoint_android_rvh_set_readahead_gfp_mask
__tracepoint_android_rvh_setscheduler
__tracepoint_android_rvh_set_task_cpu
__tracepoint_android_rvh_set_user_nice

View File

@ -187,3 +187,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_store_partner_src_caps);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_get_timer);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_modify_src_caps);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_log);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_gfp_zone_flags);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_readahead_gfp_mask);

View File

@ -123,7 +123,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);
@ -134,6 +134,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

@ -485,11 +485,13 @@ static inline struct page *page_cache_alloc(struct address_space *x)
return __page_cache_alloc(mapping_gfp_mask(x));
}
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

@ -16,19 +16,14 @@ DECLARE_RESTRICTED_HOOK(android_rvh_shmem_get_folio,
TP_PROTO(struct shmem_inode_info *info, struct folio **folio),
TP_ARGS(info, folio), 2);
/*
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_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);
DECLARE_RESTRICTED_HOOK(android_rvh_set_readahead_gfp_mask,
TP_PROTO(unsigned int *flags), /* gfp_t *flags */
TP_ARGS(flags), 1);
*/
#endif /* _TRACE_HOOK_MM_H */
/* This part must be outside protection */

View File

@ -3802,8 +3802,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
if (data_race(si->flags & SWP_SYNCHRONOUS_IO) &&
__swap_count(entry) == 1) {
/* skip swapcache */
folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0,
vma, vmf->address, false);
folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE|__GFP_CMA,
0, vma, vmf->address, false);
page = &folio->page;
if (folio) {
__folio_set_locked(folio);
@ -3829,7 +3829,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
folio->private = NULL;
}
} else {
page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE,
page = swapin_readahead(entry,
GFP_HIGHUSER_MOVABLE|__GFP_CMA,
vmf);
if (page)
folio = page_folio(page);

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)
{
@ -110,3 +111,10 @@ int page_cpupid_xchg_last(struct page *page, 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

@ -129,6 +129,7 @@
#include <linux/blk-cgroup.h>
#include <linux/fadvise.h>
#include <linux/sched/mm.h>
#include <trace/hooks/mm.h>
#include "internal.h"
@ -144,6 +145,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;