From 368d710d7f327b6512cbc90846b33cbf9934a579 Mon Sep 17 00:00:00 2001 From: Ma Wupeng Date: Wed, 30 Mar 2022 03:33:04 +0000 Subject: [PATCH] mm: Fallback to non-mirrored region below low watermark hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SK3S CVE: NA -------------------------------- Commit 45bd608ef89e ("mm: Introduce watermark check for memory reliable") introduce watermark to reserve memory in mirrored region for kernel usage. But this value does not interact well with kswapd and this will lead to fallback to non-mirrored region without release pagecache in mirrored region. With this patch, watermark is set to zero to avoid this problem. Memory allocation with ___GFP_RELIABILITY will fallback to non-mirrored region if zone's low watermark is reached and kswapd will be awakened at this time. Signed-off-by: Ma Wupeng Reviewed-by: Kefeng Wang Signed-off-by: Yongqiang Liu --- mm/mem_reliable.c | 2 +- mm/page_alloc.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/mm/mem_reliable.c b/mm/mem_reliable.c index 5505577d3784..6d4ab4bee3d5 100644 --- a/mm/mem_reliable.c +++ b/mm/mem_reliable.c @@ -11,7 +11,7 @@ #include #include -#define MEM_RELIABLE_RESERVE_MIN (256UL << 20) +#define MEM_RELIABLE_RESERVE_MIN 0 enum mem_reliable_types { MEM_RELIABLE_ALL, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index fa1cdeba5293..9d4f75235420 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4271,6 +4271,29 @@ check_retry_cpuset(int cpuset_mems_cookie, struct alloc_context *ac) return false; } +#ifdef CONFIG_MEMORY_RELIABLE +static inline void mem_reliable_fallback_slowpath(gfp_t gfp_mask, + struct alloc_context *ac) +{ + if (!reliable_allow_fb_enabled()) + return; + + if (gfp_mask & __GFP_NOFAIL) + return; + + if ((ac->high_zoneidx == ZONE_NORMAL) && + (gfp_mask & ___GFP_RELIABILITY)) { + ac->high_zoneidx = gfp_zone(gfp_mask & ~___GFP_RELIABILITY); + ac->preferred_zoneref = first_zones_zonelist( + ac->zonelist, ac->high_zoneidx, ac->nodemask); + return; + } +} +#else +static inline void mem_reliable_fallback_slowpath(gfp_t gfp_mask, + struct alloc_context *ac) {} +#endif + static inline struct page * __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, struct alloc_context *ac) @@ -4322,6 +4345,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, if (gfp_mask & __GFP_KSWAPD_RECLAIM) wake_all_kswapds(order, gfp_mask, ac); + mem_reliable_fallback_slowpath(gfp_mask, ac); + /* * The adjusted alloc_flags might result in immediate success, so try * that first -- GitLab