Commit 14797e23 authored by KOSAKI Motohiro's avatar KOSAKI Motohiro Committed by Linus Torvalds

memcg: add inactive_anon_is_low()

The inactive_anon_is_low() is key component of active/inactive anon
balancing on reclaim.  However current inactive_anon_is_low() function
only consider global reclaim.

Therefore, we need following ugly scan_global_lru() condition.

	if (lru == LRU_ACTIVE_ANON &&
	    (!scan_global_lru(sc) || inactive_anon_is_low(zone))) {
		shrink_active_list(nr_to_scan, zone, sc, priority, file);
		return 0;

it cause that memcg reclaim always deactivate pages when shrink_list() is
called.  To make mem_cgroup_inactive_anon_is_low() improve active/inactive
anon balancing of memcgroup.
Acked-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: default avatarRik van Riel <riel@redhat.com>
Signed-off-by: default avatarKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: "Pekka Enberg" <penberg@cs.helsinki.fi>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 54992762
...@@ -100,6 +100,8 @@ extern void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem, ...@@ -100,6 +100,8 @@ extern void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
extern long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone, extern long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone,
int priority, enum lru_list lru); int priority, enum lru_list lru);
int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg,
struct zone *zone);
#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
extern int do_swap_account; extern int do_swap_account;
...@@ -251,6 +253,13 @@ static inline bool mem_cgroup_oom_called(struct task_struct *task) ...@@ -251,6 +253,13 @@ static inline bool mem_cgroup_oom_called(struct task_struct *task)
{ {
return false; return false;
} }
static inline int
mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg, struct zone *zone)
{
return 1;
}
#endif /* CONFIG_CGROUP_MEM_CONT */ #endif /* CONFIG_CGROUP_MEM_CONT */
#endif /* _LINUX_MEMCONTROL_H */ #endif /* _LINUX_MEMCONTROL_H */
......
...@@ -156,6 +156,9 @@ struct mem_cgroup { ...@@ -156,6 +156,9 @@ struct mem_cgroup {
unsigned long last_oom_jiffies; unsigned long last_oom_jiffies;
int obsolete; int obsolete;
atomic_t refcnt; atomic_t refcnt;
unsigned int inactive_ratio;
/* /*
* statistics. This must be placed at the end of memcg. * statistics. This must be placed at the end of memcg.
*/ */
...@@ -431,6 +434,20 @@ long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone, ...@@ -431,6 +434,20 @@ long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone,
return (nr_pages >> priority); return (nr_pages >> priority);
} }
int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg, struct zone *zone)
{
unsigned long active;
unsigned long inactive;
inactive = mem_cgroup_get_all_zonestat(memcg, LRU_INACTIVE_ANON);
active = mem_cgroup_get_all_zonestat(memcg, LRU_ACTIVE_ANON);
if (inactive * memcg->inactive_ratio < active)
return 1;
return 0;
}
unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan, unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
struct list_head *dst, struct list_head *dst,
unsigned long *scanned, int order, unsigned long *scanned, int order,
...@@ -1360,6 +1377,29 @@ int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask) ...@@ -1360,6 +1377,29 @@ int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask)
return 0; return 0;
} }
/*
* The inactive anon list should be small enough that the VM never has to
* do too much work, but large enough that each inactive page has a chance
* to be referenced again before it is swapped out.
*
* this calculation is straightforward porting from
* page_alloc.c::setup_per_zone_inactive_ratio().
* it describe more detail.
*/
static void mem_cgroup_set_inactive_ratio(struct mem_cgroup *memcg)
{
unsigned int gb, ratio;
gb = res_counter_read_u64(&memcg->res, RES_LIMIT) >> 30;
if (gb)
ratio = int_sqrt(10 * gb);
else
ratio = 1;
memcg->inactive_ratio = ratio;
}
static DEFINE_MUTEX(set_limit_mutex); static DEFINE_MUTEX(set_limit_mutex);
static int mem_cgroup_resize_limit(struct mem_cgroup *memcg, static int mem_cgroup_resize_limit(struct mem_cgroup *memcg,
...@@ -1398,6 +1438,10 @@ static int mem_cgroup_resize_limit(struct mem_cgroup *memcg, ...@@ -1398,6 +1438,10 @@ static int mem_cgroup_resize_limit(struct mem_cgroup *memcg,
GFP_KERNEL, false); GFP_KERNEL, false);
if (!progress) retry_count--; if (!progress) retry_count--;
} }
if (!ret)
mem_cgroup_set_inactive_ratio(memcg);
return ret; return ret;
} }
...@@ -1982,7 +2026,7 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) ...@@ -1982,7 +2026,7 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
res_counter_init(&mem->res, NULL); res_counter_init(&mem->res, NULL);
res_counter_init(&mem->memsw, NULL); res_counter_init(&mem->memsw, NULL);
} }
mem_cgroup_set_inactive_ratio(mem);
mem->last_scanned_child = NULL; mem->last_scanned_child = NULL;
return &mem->css; return &mem->css;
......
...@@ -1310,14 +1310,7 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone, ...@@ -1310,14 +1310,7 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone,
pagevec_release(&pvec); pagevec_release(&pvec);
} }
/** static int inactive_anon_is_low_global(struct zone *zone)
* inactive_anon_is_low - check if anonymous pages need to be deactivated
* @zone: zone to check
*
* Returns true if the zone does not have enough inactive anon pages,
* meaning some active anon pages need to be deactivated.
*/
static int inactive_anon_is_low(struct zone *zone)
{ {
unsigned long active, inactive; unsigned long active, inactive;
...@@ -1330,6 +1323,25 @@ static int inactive_anon_is_low(struct zone *zone) ...@@ -1330,6 +1323,25 @@ static int inactive_anon_is_low(struct zone *zone)
return 0; return 0;
} }
/**
* inactive_anon_is_low - check if anonymous pages need to be deactivated
* @zone: zone to check
* @sc: scan control of this context
*
* Returns true if the zone does not have enough inactive anon pages,
* meaning some active anon pages need to be deactivated.
*/
static int inactive_anon_is_low(struct zone *zone, struct scan_control *sc)
{
int low;
if (scan_global_lru(sc))
low = inactive_anon_is_low_global(zone);
else
low = mem_cgroup_inactive_anon_is_low(sc->mem_cgroup, zone);
return low;
}
static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
struct zone *zone, struct scan_control *sc, int priority) struct zone *zone, struct scan_control *sc, int priority)
{ {
...@@ -1340,8 +1352,7 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, ...@@ -1340,8 +1352,7 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
return 0; return 0;
} }
if (lru == LRU_ACTIVE_ANON && if (lru == LRU_ACTIVE_ANON && inactive_anon_is_low(zone, sc)) {
(!scan_global_lru(sc) || inactive_anon_is_low(zone))) {
shrink_active_list(nr_to_scan, zone, sc, priority, file); shrink_active_list(nr_to_scan, zone, sc, priority, file);
return 0; return 0;
} }
...@@ -1509,9 +1520,7 @@ static void shrink_zone(int priority, struct zone *zone, ...@@ -1509,9 +1520,7 @@ static void shrink_zone(int priority, struct zone *zone,
* Even if we did not try to evict anon pages at all, we want to * Even if we did not try to evict anon pages at all, we want to
* rebalance the anon lru active/inactive ratio. * rebalance the anon lru active/inactive ratio.
*/ */
if (!scan_global_lru(sc) || inactive_anon_is_low(zone)) if (inactive_anon_is_low(zone, sc))
shrink_active_list(SWAP_CLUSTER_MAX, zone, sc, priority, 0);
else if (!scan_global_lru(sc))
shrink_active_list(SWAP_CLUSTER_MAX, zone, sc, priority, 0); shrink_active_list(SWAP_CLUSTER_MAX, zone, sc, priority, 0);
throttle_vm_writeout(sc->gfp_mask); throttle_vm_writeout(sc->gfp_mask);
...@@ -1807,7 +1816,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order) ...@@ -1807,7 +1816,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order)
* Do some background aging of the anon list, to give * Do some background aging of the anon list, to give
* pages a chance to be referenced before reclaiming. * pages a chance to be referenced before reclaiming.
*/ */
if (inactive_anon_is_low(zone)) if (inactive_anon_is_low(zone, &sc))
shrink_active_list(SWAP_CLUSTER_MAX, zone, shrink_active_list(SWAP_CLUSTER_MAX, zone,
&sc, priority, 0); &sc, priority, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment