Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

memcg: fix direct softlimit reclaim to be called in limit path

Commit d149e3b25d7c ("memcg: add the soft_limit reclaim in global direct
reclaim") adds a softlimit hook to shrink_zones(). By this, soft limit
is called as

try_to_free_pages()
do_try_to_free_pages()
shrink_zones()
mem_cgroup_soft_limit_reclaim()

Then, direct reclaim is memcg softlimit hint aware, now.

But, the memory cgroup's "limit" path can call softlimit shrinker.

try_to_free_mem_cgroup_pages()
do_try_to_free_pages()
shrink_zones()
mem_cgroup_soft_limit_reclaim()

This will cause a global reclaim when a memcg hits limit.

This is bug. soft_limit_reclaim() should be called when
scanning_global_lru(sc) == true.

And the commit adds a variable "total_scanned" for counting softlimit
scanned pages....it's not "total". This patch removes the variable and
update sc->nr_scanned instead of it. This will affect shrink_slab()'s
scan condition but, global LRU is scanned by softlimit and I think this
change makes sense.

TODO: avoid too much scanning of a zone when softlimit did enough work.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Ying Han <yinghan@google.com>
Cc: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

KAMEZAWA Hiroyuki and committed by
Linus Torvalds
ac34a1a3 26c4caea

+15 -12
+15 -12
mm/vmscan.c
··· 1995 1995 * If a zone is deemed to be full of pinned pages then just give it a light 1996 1996 * scan then give up on it. 1997 1997 */ 1998 - static unsigned long shrink_zones(int priority, struct zonelist *zonelist, 1998 + static void shrink_zones(int priority, struct zonelist *zonelist, 1999 1999 struct scan_control *sc) 2000 2000 { 2001 2001 struct zoneref *z; 2002 2002 struct zone *zone; 2003 2003 unsigned long nr_soft_reclaimed; 2004 2004 unsigned long nr_soft_scanned; 2005 - unsigned long total_scanned = 0; 2006 2005 2007 2006 for_each_zone_zonelist_nodemask(zone, z, zonelist, 2008 2007 gfp_zone(sc->gfp_mask), sc->nodemask) { ··· 2016 2017 continue; 2017 2018 if (zone->all_unreclaimable && priority != DEF_PRIORITY) 2018 2019 continue; /* Let kswapd poll it */ 2020 + /* 2021 + * This steals pages from memory cgroups over softlimit 2022 + * and returns the number of reclaimed pages and 2023 + * scanned pages. This works for global memory pressure 2024 + * and balancing, not for a memcg's limit. 2025 + */ 2026 + nr_soft_scanned = 0; 2027 + nr_soft_reclaimed = mem_cgroup_soft_limit_reclaim(zone, 2028 + sc->order, sc->gfp_mask, 2029 + &nr_soft_scanned); 2030 + sc->nr_reclaimed += nr_soft_reclaimed; 2031 + sc->nr_scanned += nr_soft_scanned; 2032 + /* need some check for avoid more shrink_zone() */ 2019 2033 } 2020 - 2021 - nr_soft_scanned = 0; 2022 - nr_soft_reclaimed = mem_cgroup_soft_limit_reclaim(zone, 2023 - sc->order, sc->gfp_mask, 2024 - &nr_soft_scanned); 2025 - sc->nr_reclaimed += nr_soft_reclaimed; 2026 - total_scanned += nr_soft_scanned; 2027 2034 2028 2035 shrink_zone(priority, zone, sc); 2029 2036 } 2030 - 2031 - return total_scanned; 2032 2037 } 2033 2038 2034 2039 static bool zone_reclaimable(struct zone *zone) ··· 2097 2094 sc->nr_scanned = 0; 2098 2095 if (!priority) 2099 2096 disable_swap_token(sc->mem_cgroup); 2100 - total_scanned += shrink_zones(priority, zonelist, sc); 2097 + shrink_zones(priority, zonelist, sc); 2101 2098 /* 2102 2099 * Don't shrink slabs when reclaiming memory from 2103 2100 * over limit cgroups