From 4e714e1a8a260665bd6690693e5416d22f927538 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Sat, 6 Apr 2024 01:05:28 +0000 Subject: [PATCH] ANDROID: add reclaim tune parameter functions This patch adds two exported functions to set/get reclaim parameters. Bug: 323406883 Change-Id: I8c29073dba3e77cb5db7f45b640518deae04b8a9 Signed-off-by: Minchan Kim Signed-off-by: Richard Chang (cherry picked from commit dde2272b2705b283ae3b251823ba8df69c782006) Signed-off-by: Dmitry Skiba --- include/linux/gfp.h | 3 +++ mm/page_alloc.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 090df56a808e..c3a4945287ea 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -431,6 +431,9 @@ static inline bool gfp_compaction_allowed(gfp_t gfp_mask) extern gfp_t vma_thp_gfp_mask(struct vm_area_struct *vma); +int set_reclaim_params(int wmark_scale_factor, int swappiness); +void get_reclaim_params(int *wmark_scale_factor, int *swappiness); + #ifdef CONFIG_CONTIG_ALLOC /* The below functions must be run on a range from a single zone. */ extern int alloc_contig_range_noprof(unsigned long start, unsigned long end, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index dc5ebae985b6..cdf7acc48ea9 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -399,6 +399,30 @@ static inline int pfn_to_bitidx(const struct page *page, unsigned long pfn) return (pfn >> pageblock_order) * NR_PAGEBLOCK_BITS; } +int set_reclaim_params(int wmark_scale_factor, int swappiness) +{ + if (wmark_scale_factor > 3000 || wmark_scale_factor < 1) + return -EINVAL; + + if (swappiness > 200 || swappiness < 0) + return -EINVAL; + + WRITE_ONCE(vm_swappiness, swappiness); + WRITE_ONCE(watermark_scale_factor, wmark_scale_factor); + + setup_per_zone_wmarks(); + + return 0; +} +EXPORT_SYMBOL_GPL(set_reclaim_params); + +void get_reclaim_params(int *wmark_scale_factor, int *swappiness) +{ + *wmark_scale_factor = watermark_scale_factor; + *swappiness = vm_swappiness; +} +EXPORT_SYMBOL_GPL(get_reclaim_params); + /** * get_pfnblock_flags_mask - Return the requested group of flags for the pageblock_nr_pages block of pages * @page: The page within the block of interest