Commit 1f4c025b authored by KAMEZAWA Hiroyuki's avatar KAMEZAWA Hiroyuki Committed by Linus Torvalds

memcg: export memory cgroup's swappiness with mem_cgroup_swappiness()

Each memory cgroup has a 'swappiness' value which can be accessed by
get_swappiness(memcg).  The major user is try_to_free_mem_cgroup_pages()
and swappiness is passed by argument.  It's propagated by scan_control.

get_swappiness() is a static function but some planned updates will need
to get swappiness from files other than memcontrol.c This patch exports
get_swappiness() as mem_cgroup_swappiness().  With this, we can remove the
argument of swapiness from try_to_free...  and drop swappiness from
scan_control.  only memcg uses it.
Signed-off-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Ying Han <yinghan@google.com>
Cc: Shaohua Li <shaohua.li@intel.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 b830ac1d
...@@ -252,11 +252,9 @@ static inline void lru_cache_add_file(struct page *page) ...@@ -252,11 +252,9 @@ static inline void lru_cache_add_file(struct page *page)
extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order, extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
gfp_t gfp_mask, nodemask_t *mask); gfp_t gfp_mask, nodemask_t *mask);
extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem, extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem,
gfp_t gfp_mask, bool noswap, gfp_t gfp_mask, bool noswap);
unsigned int swappiness);
extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
gfp_t gfp_mask, bool noswap, gfp_t gfp_mask, bool noswap,
unsigned int swappiness,
struct zone *zone, struct zone *zone,
unsigned long *nr_scanned); unsigned long *nr_scanned);
extern int __isolate_lru_page(struct page *page, int mode, int file); extern int __isolate_lru_page(struct page *page, int mode, int file);
...@@ -299,7 +297,14 @@ static inline void scan_unevictable_unregister_node(struct node *node) ...@@ -299,7 +297,14 @@ static inline void scan_unevictable_unregister_node(struct node *node)
extern int kswapd_run(int nid); extern int kswapd_run(int nid);
extern void kswapd_stop(int nid); extern void kswapd_stop(int nid);
#ifdef CONFIG_CGROUP_MEM_RES_CTLR
extern int mem_cgroup_swappiness(struct mem_cgroup *mem);
#else
static inline int mem_cgroup_swappiness(struct mem_cgroup *mem)
{
return vm_swappiness;
}
#endif
#ifdef CONFIG_SWAP #ifdef CONFIG_SWAP
/* linux/mm/page_io.c */ /* linux/mm/page_io.c */
extern int swap_readpage(struct page *); extern int swap_readpage(struct page *);
......
...@@ -249,7 +249,7 @@ struct mem_cgroup { ...@@ -249,7 +249,7 @@ struct mem_cgroup {
atomic_t oom_lock; atomic_t oom_lock;
atomic_t refcnt; atomic_t refcnt;
unsigned int swappiness; int swappiness;
/* OOM-Killer disable */ /* OOM-Killer disable */
int oom_kill_disable; int oom_kill_disable;
...@@ -1329,7 +1329,7 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *mem) ...@@ -1329,7 +1329,7 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *mem)
return margin >> PAGE_SHIFT; return margin >> PAGE_SHIFT;
} }
static unsigned int get_swappiness(struct mem_cgroup *memcg) int mem_cgroup_swappiness(struct mem_cgroup *memcg)
{ {
struct cgroup *cgrp = memcg->css.cgroup; struct cgroup *cgrp = memcg->css.cgroup;
...@@ -1776,12 +1776,11 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem, ...@@ -1776,12 +1776,11 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem,
/* we use swappiness of local cgroup */ /* we use swappiness of local cgroup */
if (check_soft) { if (check_soft) {
ret = mem_cgroup_shrink_node_zone(victim, gfp_mask, ret = mem_cgroup_shrink_node_zone(victim, gfp_mask,
noswap, get_swappiness(victim), zone, noswap, zone, &nr_scanned);
&nr_scanned);
*total_scanned += nr_scanned; *total_scanned += nr_scanned;
} else } else
ret = try_to_free_mem_cgroup_pages(victim, gfp_mask, ret = try_to_free_mem_cgroup_pages(victim, gfp_mask,
noswap, get_swappiness(victim)); noswap);
css_put(&victim->css); css_put(&victim->css);
/* /*
* At shrinking usage, we can't check we should stop here or * At shrinking usage, we can't check we should stop here or
...@@ -3826,7 +3825,7 @@ static int mem_cgroup_force_empty(struct mem_cgroup *mem, bool free_all) ...@@ -3826,7 +3825,7 @@ static int mem_cgroup_force_empty(struct mem_cgroup *mem, bool free_all)
goto out; goto out;
} }
progress = try_to_free_mem_cgroup_pages(mem, GFP_KERNEL, progress = try_to_free_mem_cgroup_pages(mem, GFP_KERNEL,
false, get_swappiness(mem)); false);
if (!progress) { if (!progress) {
nr_retries--; nr_retries--;
/* maybe some writeback is necessary */ /* maybe some writeback is necessary */
...@@ -4288,7 +4287,7 @@ static u64 mem_cgroup_swappiness_read(struct cgroup *cgrp, struct cftype *cft) ...@@ -4288,7 +4287,7 @@ static u64 mem_cgroup_swappiness_read(struct cgroup *cgrp, struct cftype *cft)
{ {
struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
return get_swappiness(memcg); return mem_cgroup_swappiness(memcg);
} }
static int mem_cgroup_swappiness_write(struct cgroup *cgrp, struct cftype *cft, static int mem_cgroup_swappiness_write(struct cgroup *cgrp, struct cftype *cft,
...@@ -4997,7 +4996,7 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) ...@@ -4997,7 +4996,7 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
INIT_LIST_HEAD(&mem->oom_notify); INIT_LIST_HEAD(&mem->oom_notify);
if (parent) if (parent)
mem->swappiness = get_swappiness(parent); mem->swappiness = mem_cgroup_swappiness(parent);
atomic_set(&mem->refcnt, 1); atomic_set(&mem->refcnt, 1);
mem->move_charge_at_immigrate = 0; mem->move_charge_at_immigrate = 0;
mutex_init(&mem->thresholds_lock); mutex_init(&mem->thresholds_lock);
......
...@@ -95,8 +95,6 @@ struct scan_control { ...@@ -95,8 +95,6 @@ struct scan_control {
/* Can pages be swapped as part of reclaim? */ /* Can pages be swapped as part of reclaim? */
int may_swap; int may_swap;
int swappiness;
int order; int order;
/* /*
...@@ -1770,6 +1768,13 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, ...@@ -1770,6 +1768,13 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
return shrink_inactive_list(nr_to_scan, zone, sc, priority, file); return shrink_inactive_list(nr_to_scan, zone, sc, priority, file);
} }
static int vmscan_swappiness(struct scan_control *sc)
{
if (scanning_global_lru(sc))
return vm_swappiness;
return mem_cgroup_swappiness(sc->mem_cgroup);
}
/* /*
* Determine how aggressively the anon and file LRU lists should be * Determine how aggressively the anon and file LRU lists should be
* scanned. The relative value of each set of LRU lists is determined * scanned. The relative value of each set of LRU lists is determined
...@@ -1830,8 +1835,8 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc, ...@@ -1830,8 +1835,8 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
* With swappiness at 100, anonymous and file have the same priority. * With swappiness at 100, anonymous and file have the same priority.
* This scanning priority is essentially the inverse of IO cost. * This scanning priority is essentially the inverse of IO cost.
*/ */
anon_prio = sc->swappiness; anon_prio = vmscan_swappiness(sc);
file_prio = 200 - sc->swappiness; file_prio = 200 - vmscan_swappiness(sc);
/* /*
* OK, so we have swap space and a fair amount of page cache * OK, so we have swap space and a fair amount of page cache
...@@ -2220,7 +2225,6 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order, ...@@ -2220,7 +2225,6 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
.nr_to_reclaim = SWAP_CLUSTER_MAX, .nr_to_reclaim = SWAP_CLUSTER_MAX,
.may_unmap = 1, .may_unmap = 1,
.may_swap = 1, .may_swap = 1,
.swappiness = vm_swappiness,
.order = order, .order = order,
.mem_cgroup = NULL, .mem_cgroup = NULL,
.nodemask = nodemask, .nodemask = nodemask,
...@@ -2244,7 +2248,6 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order, ...@@ -2244,7 +2248,6 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
gfp_t gfp_mask, bool noswap, gfp_t gfp_mask, bool noswap,
unsigned int swappiness,
struct zone *zone, struct zone *zone,
unsigned long *nr_scanned) unsigned long *nr_scanned)
{ {
...@@ -2254,7 +2257,6 @@ unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, ...@@ -2254,7 +2257,6 @@ unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
.may_writepage = !laptop_mode, .may_writepage = !laptop_mode,
.may_unmap = 1, .may_unmap = 1,
.may_swap = !noswap, .may_swap = !noswap,
.swappiness = swappiness,
.order = 0, .order = 0,
.mem_cgroup = mem, .mem_cgroup = mem,
}; };
...@@ -2283,8 +2285,7 @@ unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, ...@@ -2283,8 +2285,7 @@ unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont, unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,
gfp_t gfp_mask, gfp_t gfp_mask,
bool noswap, bool noswap)
unsigned int swappiness)
{ {
struct zonelist *zonelist; struct zonelist *zonelist;
unsigned long nr_reclaimed; unsigned long nr_reclaimed;
...@@ -2294,7 +2295,6 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont, ...@@ -2294,7 +2295,6 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,
.may_unmap = 1, .may_unmap = 1,
.may_swap = !noswap, .may_swap = !noswap,
.nr_to_reclaim = SWAP_CLUSTER_MAX, .nr_to_reclaim = SWAP_CLUSTER_MAX,
.swappiness = swappiness,
.order = 0, .order = 0,
.mem_cgroup = mem_cont, .mem_cgroup = mem_cont,
.nodemask = NULL, /* we don't care the placement */ .nodemask = NULL, /* we don't care the placement */
...@@ -2445,7 +2445,6 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order, ...@@ -2445,7 +2445,6 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
* we want to put equal scanning pressure on each zone. * we want to put equal scanning pressure on each zone.
*/ */
.nr_to_reclaim = ULONG_MAX, .nr_to_reclaim = ULONG_MAX,
.swappiness = vm_swappiness,
.order = order, .order = order,
.mem_cgroup = NULL, .mem_cgroup = NULL,
}; };
...@@ -2915,7 +2914,6 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim) ...@@ -2915,7 +2914,6 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
.may_writepage = 1, .may_writepage = 1,
.nr_to_reclaim = nr_to_reclaim, .nr_to_reclaim = nr_to_reclaim,
.hibernation_mode = 1, .hibernation_mode = 1,
.swappiness = vm_swappiness,
.order = 0, .order = 0,
}; };
struct shrink_control shrink = { struct shrink_control shrink = {
...@@ -3102,7 +3100,6 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order) ...@@ -3102,7 +3100,6 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
.nr_to_reclaim = max_t(unsigned long, nr_pages, .nr_to_reclaim = max_t(unsigned long, nr_pages,
SWAP_CLUSTER_MAX), SWAP_CLUSTER_MAX),
.gfp_mask = gfp_mask, .gfp_mask = gfp_mask,
.swappiness = vm_swappiness,
.order = order, .order = order,
}; };
struct shrink_control shrink = { struct shrink_control shrink = {
......
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