From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail172.messagelabs.com (mail172.messagelabs.com [216.82.254.3]) by kanga.kvack.org (Postfix) with ESMTP id 334C36B012B for ; Tue, 21 Jun 2011 02:50:05 -0400 (EDT) Received: from kpbe13.cbf.corp.google.com (kpbe13.cbf.corp.google.com [172.25.105.77]) by smtp-out.google.com with ESMTP id p5L6nvQM012173 for ; Mon, 20 Jun 2011 23:49:57 -0700 Received: from qyk29 (qyk29.prod.google.com [10.241.83.157]) by kpbe13.cbf.corp.google.com with ESMTP id p5L6ntgM001151 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Mon, 20 Jun 2011 23:49:55 -0700 Received: by qyk29 with SMTP id 29so2208115qyk.3 for ; Mon, 20 Jun 2011 23:49:55 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20110616125314.4f78b1e0.kamezawa.hiroyu@jp.fujitsu.com> References: <20110616124730.d6960b8b.kamezawa.hiroyu@jp.fujitsu.com> <20110616125314.4f78b1e0.kamezawa.hiroyu@jp.fujitsu.com> Date: Mon, 20 Jun 2011 23:49:54 -0700 Message-ID: Subject: Re: [PATCH 3/7] memcg: add memory.scan_stat From: Ying Han Content-Type: multipart/alternative; boundary=00163649971d6f1b5504a6334269 Sender: owner-linux-mm@kvack.org List-ID: To: KAMEZAWA Hiroyuki Cc: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "akpm@linux-foundation.org" , "nishimura@mxp.nes.nec.co.jp" , "bsingharora@gmail.com" , Michal Hocko , "hannes@cmpxchg.org" --00163649971d6f1b5504a6334269 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jun 15, 2011 at 8:53 PM, KAMEZAWA Hiroyuki < kamezawa.hiroyu@jp.fujitsu.com> wrote: > From e08990dd9ada13cf236bec1ef44b207436434b8e Mon Sep 17 00:00:00 2001 > From: KAMEZAWA Hiroyuki > Date: Wed, 15 Jun 2011 14:11:01 +0900 > Subject: [PATCH 3/7] memcg: add memory.scan_stat > > commit log of commit 0ae5e89 " memcg: count the soft_limit reclaim in..." > says it adds scanning stats to memory.stat file. But it doesn't because > we considered we needed to make a concensus for such new APIs. > > This patch is a trial to add memory.scan_stat. This shows > - the number of scanned pages > - the number of recleimed pages > - the number of elaplsed time (including sleep/pause time) > for both of direct/soft reclaim and shrinking caused by changing limit > or force_empty. > > The biggest difference with oringinal Ying's one is that this file > can be reset by some write, as > > # echo 0 ...../memory.scan_stat > > [kamezawa@bluextal ~]$ cat /cgroup/memory/A/memory.scan_stat > scanned_pages_by_limit 358470 > freed_pages_by_limit 180795 > elapsed_ns_by_limit 21629927 > scanned_pages_by_system 0 > freed_pages_by_system 0 > elapsed_ns_by_system 0 > scanned_pages_by_shrink 76646 > freed_pages_by_shrink 38355 > elappsed_ns_by_shrink 31990670 > elapsed? > total_scanned_pages_by_limit 358470 > total_freed_pages_by_limit 180795 > total_elapsed_ns_by_hierarchical 216299275 > total_scanned_pages_by_system 0 > total_freed_pages_by_system 0 > total_elapsed_ns_by_system 0 > total_scanned_pages_by_shrink 76646 > total_freed_pages_by_shrink 38355 > total_elapsed_ns_by_shrink 31990670 > > total_xxxx is for hierarchy management. > For some reason, i feel the opposite where the local stat (like "scanned_pages_by_limit") are reclaimed under hierarchical reclaim. The total_xxx stats are only incremented for root_mem which is the cgroup triggers the hierarchical reclaim. So: total_scanned_pages_by_limit: number of pages being scanned while the memcg hits its limit scanned_pages_by_limit: number of pages being scanned while one of the memcg's ancestor hits its limit am i missing something? > > This will be useful for further memcg developments and need to be > developped before we do some complicated rework on LRU/softlimit > management. > > Now, scan/free/elapsed_by_system is incomplete but future works of > Johannes at el. will fill remaining information and then, we can > look into problems of isolation between memcgs. > > Signed-off-by: KAMEZAWA Hiroyuki > --- > Documentation/cgroups/memory.txt | 33 +++++++++ > include/linux/memcontrol.h | 16 ++++ > include/linux/swap.h | 6 - > mm/memcontrol.c | 135 > +++++++++++++++++++++++++++++++++++++-- > mm/vmscan.c | 27 ++++++- > 5 files changed, 199 insertions(+), 18 deletions(-) > > Index: mmotm-0615/Documentation/cgroups/memory.txt > =================================================================== > --- mmotm-0615.orig/Documentation/cgroups/memory.txt > +++ mmotm-0615/Documentation/cgroups/memory.txt > @@ -380,7 +380,7 @@ will be charged as a new owner of it. > > 5.2 stat file > > -memory.stat file includes following statistics > +5.2.1 memory.stat file includes following statistics > > # per-memory cgroup local status > cache - # of bytes of page cache memory. > @@ -438,6 +438,37 @@ Note: > file_mapped is accounted only when the memory cgroup is owner of > page > cache.) > > +5.2.2 memory.scan_stat > + > +memory.scan_stat includes statistics information for memory scanning and > +freeing, reclaiming. The statistics shows memory scanning information > since > +memory cgroup creation and can be reset to 0 by writing 0 as > + > + #echo 0 > ../memory.scan_stat > + > +This file contains following statistics. > + > +scanned_pages_by_limit - # of scanned pages at hitting limit. > +freed_pages_by_limit - # of freed pages at hitting limit. > +elapsed_ns_by_limit - nano sec of elappsed time at LRU scan at > + hitting limit.(this includes sleep > time.) > elapsed? > + > +scanned_pages_by_system - # of scanned pages by the kernel. > + (Now, this value means global memory reclaim > + caused by system memory shortage with a hint > + of softlimit. "No soft limit" case will be > + supported in future.) > +freed_pages_by_system - # of freed pages by the kernel. > +elapsed_ns_by_system - nano sec of elappsed time by kernel. > + > +scanned_pages_by_shrink - # of scanned pages by shrinking. > + (i.e. changes of limit, force_empty, > etc.) > +freed_pages_by_shrink - # of freed pages by shirkining. > +elappsed_ns_by_shrink - nano sec of elappsed time at shrinking. > elapsed? > + > +total_xxx includes the statistics of children scanning caused by the > cgroup. > based on the code inspection, the total_xxx also includes the cgroup's scan stat as well. + > + > 5.3 swappiness > > Similar to /proc/sys/vm/swappiness, but affecting a hierarchy of groups > only. > Index: mmotm-0615/include/linux/memcontrol.h > =================================================================== > --- mmotm-0615.orig/include/linux/memcontrol.h > +++ mmotm-0615/include/linux/memcontrol.h > @@ -120,6 +120,22 @@ struct zone_reclaim_stat* > mem_cgroup_get_reclaim_stat_from_page(struct page *page); > extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, > struct task_struct *p); > +struct memcg_scanrecord { > + struct mem_cgroup *mem; /* scanend memory cgroup */ > + struct mem_cgroup *root; /* scan target hierarchy root */ > + int context; /* scanning context (see memcontrol.c) */ > + unsigned long nr_scanned; /* the number of scanned pages */ > + unsigned long nr_freed; /* the number of freed pages */ > + unsigned long elappsed; /* nsec of time elapsed while scanning */ > elapsed? > +}; > + > +extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem, > + gfp_t gfp_mask, bool > noswap, > + struct memcg_scanrecord > *rec); > +extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, > + gfp_t gfp_mask, bool > noswap, > + struct zone *zone, > + struct memcg_scanrecord > *rec); > > #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP > extern int do_swap_account; > Index: mmotm-0615/include/linux/swap.h > =================================================================== > --- mmotm-0615.orig/include/linux/swap.h > +++ mmotm-0615/include/linux/swap.h > @@ -253,12 +253,6 @@ static inline void lru_cache_add_file(st > /* linux/mm/vmscan.c */ > extern unsigned long try_to_free_pages(struct zonelist *zonelist, int > order, > gfp_t gfp_mask, nodemask_t *mask); > -extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem, > - gfp_t gfp_mask, bool > noswap); > -extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, > - gfp_t gfp_mask, bool > noswap, > - struct zone *zone, > - unsigned long *nr_scanned); > extern int __isolate_lru_page(struct page *page, int mode, int file); > extern unsigned long shrink_all_memory(unsigned long nr_pages); > extern int vm_swappiness; > Index: mmotm-0615/mm/memcontrol.c > =================================================================== > --- mmotm-0615.orig/mm/memcontrol.c > +++ mmotm-0615/mm/memcontrol.c > @@ -203,6 +203,57 @@ struct mem_cgroup_eventfd_list { > static void mem_cgroup_threshold(struct mem_cgroup *mem); > static void mem_cgroup_oom_notify(struct mem_cgroup *mem); > > +enum { > + SCAN_BY_LIMIT, > + FREED_BY_LIMIT, > + ELAPSED_BY_LIMIT, > + > + SCAN_BY_SYSTEM, > + FREED_BY_SYSTEM, > + ELAPSED_BY_SYSTEM, > + > + SCAN_BY_SHRINK, > + FREED_BY_SHRINK, > + ELAPSED_BY_SHRINK, > + NR_SCANSTATS, > +}; > +#define __FREED (1) > +#define __ELAPSED (2) > /tab/space/ > + > +struct scanstat { > + spinlock_t lock; > + unsigned long stats[NR_SCANSTATS]; /* local statistics */ > + unsigned long totalstats[NR_SCANSTATS]; /* hierarchical */ > +}; > + > +const char *scanstat_string[NR_SCANSTATS] = { > + "scanned_pages_by_limit", > + "freed_pages_by_limit", > + "elapsed_ns_by_limit", > + > + "scanned_pages_by_system", > + "freed_pages_by_system", > + "elapsed_ns_by_system", > + > + "scanned_pages_by_shrink", > + "freed_pages_by_shrink", > + "elappsed_ns_by_shrink", > elapsed? > +}; > + > +const char *total_scanstat_string[NR_SCANSTATS] = { > + "total_scanned_pages_by_limit", > + "total_freed_pages_by_limit", > + "total_elapsed_ns_by_hierarchical", > typo? > + > + "total_scanned_pages_by_system", > + "total_freed_pages_by_system", > + "total_elapsed_ns_by_system", > + > + "total_scanned_pages_by_shrink", > + "total_freed_pages_by_shrink", > + "total_elapsed_ns_by_shrink", > +}; > + > /* > * The memory controller data structure. The memory controller controls > both > * page cache and RSS per cgroup. We would eventually like to provide > @@ -264,7 +315,8 @@ struct mem_cgroup { > > /* For oom notifier event fd */ > struct list_head oom_notify; > - > + /* For recording LRU-scan statistics */ > + struct scanstat scanstat; > /* > * Should we move charges of a task when a task is moved into this > * mem_cgroup ? And what type of charges should we move ? > @@ -1634,6 +1686,28 @@ int mem_cgroup_select_victim_node(struct > } > #endif > > + > + > +static void mem_cgroup_record_scanstat(struct memcg_scanrecord *rec) > +{ > + struct mem_cgroup *mem; > + int context = rec->context; > + > + mem = rec->mem; > + spin_lock(&mem->scanstat.lock); > + mem->scanstat.stats[context] += rec->nr_scanned; > + mem->scanstat.stats[context + __FREED] += rec->nr_freed; > + mem->scanstat.stats[context + __ELAPSED] += rec->elappsed; > elapsed? + spin_unlock(&mem->scanstat.lock); > + > + mem = rec->root; > + spin_lock(&mem->scanstat.lock); > + mem->scanstat.totalstats[context] += rec->nr_scanned; > + mem->scanstat.totalstats[context + __FREED] += rec->nr_freed; > + mem->scanstat.totalstats[context + __ELAPSED] += rec->elappsed; > elapsed? > + spin_unlock(&mem->scanstat.lock); > +} > + > /* > * Scan the hierarchy if needed to reclaim memory. We remember the last > child > * we reclaimed from, so that we don't end up penalizing one child > extensively > @@ -1659,8 +1733,8 @@ static int mem_cgroup_hierarchical_recla > bool shrink = reclaim_options & MEM_CGROUP_RECLAIM_SHRINK; > bool check_soft = reclaim_options & MEM_CGROUP_RECLAIM_SOFT; > unsigned long excess; > - unsigned long nr_scanned; > int visit; > + struct memcg_scanrecord rec; > > excess = res_counter_soft_limit_excess(&root_mem->res) >> > PAGE_SHIFT; > > @@ -1668,6 +1742,15 @@ static int mem_cgroup_hierarchical_recla > if (!check_soft && root_mem->memsw_is_minimum) > noswap = true; > > + if (shrink) > + rec.context = SCAN_BY_SHRINK; > + else if (check_soft) > + rec.context = SCAN_BY_SYSTEM; > + else > + rec.context = SCAN_BY_LIMIT; > + > + rec.root = root_mem; > > + > again: > if (!shrink) { > visit = 0; > @@ -1695,14 +1778,19 @@ again: > css_put(&victim->css); > continue; > } > + rec.mem = victim; > + rec.nr_scanned = 0; > + rec.nr_freed = 0; > + rec.elappsed = 0; > elapsed? > /* we use swappiness of local cgroup */ > if (check_soft) { > ret = mem_cgroup_shrink_node_zone(victim, gfp_mask, > - noswap, zone, &nr_scanned); > - *total_scanned += nr_scanned; > + noswap, zone, &rec); > + *total_scanned += rec.nr_scanned; > } else > ret = try_to_free_mem_cgroup_pages(victim, gfp_mask, > - noswap); > + noswap, &rec); > + mem_cgroup_record_scanstat(&rec); > css_put(&victim->css); > > total += ret; > @@ -3757,7 +3845,8 @@ try_to_free: > ret = -EINTR; > goto out; > } > - progress = try_to_free_mem_cgroup_pages(mem, GFP_KERNEL, > false); > + progress = try_to_free_mem_cgroup_pages(mem, > + GFP_KERNEL, false, NULL); > So we don't record the stat for force_empty case? > if (!progress) { > nr_retries--; > /* maybe some writeback is necessary */ > @@ -4599,6 +4688,34 @@ static int mem_control_numa_stat_open(st > } > #endif /* CONFIG_NUMA */ > > +static int mem_cgroup_scan_stat_read(struct cgroup *cgrp, > + struct cftype *cft, > + struct cgroup_map_cb *cb) > +{ > + struct mem_cgroup *mem = mem_cgroup_from_cont(cgrp); > + int i; > + > + for (i = 0; i < NR_SCANSTATS; i++) > + cb->fill(cb, scanstat_string[i], mem->scanstat.stats[i]); > + for (i = 0; i < NR_SCANSTATS; i++) > + cb->fill(cb, total_scanstat_string[i], > + mem->scanstat.totalstats[i]); > + return 0; > +} > + > +static int mem_cgroup_reset_scan_stat(struct cgroup *cgrp, > + unsigned int event) > +{ > + struct mem_cgroup *mem = mem_cgroup_from_cont(cgrp); > + > + spin_lock(&mem->scanstat.lock); > + memset(&mem->scanstat.stats, 0, sizeof(mem->scanstat.stats)); > + memset(&mem->scanstat.totalstats, 0, > sizeof(mem->scanstat.totalstats)); > + spin_unlock(&mem->scanstat.lock); > + return 0; > +} > + > + > static struct cftype mem_cgroup_files[] = { > { > .name = "usage_in_bytes", > @@ -4669,6 +4786,11 @@ static struct cftype mem_cgroup_files[] > .mode = S_IRUGO, > }, > #endif > + { > + .name = "scan_stat", > + .read_map = mem_cgroup_scan_stat_read, > + .trigger = mem_cgroup_reset_scan_stat, > + }, > }; > > #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP > @@ -4932,6 +5054,7 @@ mem_cgroup_create(struct cgroup_subsys * > atomic_set(&mem->refcnt, 1); > mem->move_charge_at_immigrate = 0; > mutex_init(&mem->thresholds_lock); > + spin_lock_init(&mem->scanstat.lock); > return &mem->css; > free_out: > __mem_cgroup_free(mem); > Index: mmotm-0615/mm/vmscan.c > =================================================================== > --- mmotm-0615.orig/mm/vmscan.c > +++ mmotm-0615/mm/vmscan.c > @@ -2199,9 +2199,9 @@ unsigned long try_to_free_pages(struct z > #ifdef CONFIG_CGROUP_MEM_RES_CTLR > > unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, > - gfp_t gfp_mask, bool > noswap, > - struct zone *zone, > - unsigned long *nr_scanned) > + gfp_t gfp_mask, bool noswap, > + struct zone *zone, > + struct memcg_scanrecord *rec) > { > struct scan_control sc = { > .nr_scanned = 0, > @@ -2213,6 +2213,7 @@ unsigned long mem_cgroup_shrink_node_zon > .order = 0, > .mem_cgroup = mem, > }; > + unsigned long start, end; > > sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) | > (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK); > @@ -2221,6 +2222,7 @@ unsigned long mem_cgroup_shrink_node_zon > sc.may_writepage, > sc.gfp_mask); > > + start = sched_clock(); > /* > * NOTE: Although we can get the priority field, using it > * here is not a good idea, since it limits the pages we can scan. > @@ -2229,19 +2231,27 @@ unsigned long mem_cgroup_shrink_node_zon > * the priority and make it zero. > */ > shrink_zone(0, zone, &sc); > + end = sched_clock(); > + > + if (rec) { > + rec->nr_scanned += sc.nr_scanned; > > + rec->nr_freed += sc.nr_reclaimed; > + rec->elappsed += end - start; > elapsed? > + } > > trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed); > > - *nr_scanned = sc.nr_scanned; > return sc.nr_reclaimed; > } > > unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont, > gfp_t gfp_mask, > - bool noswap) > + bool noswap, > + struct memcg_scanrecord *rec) > { > struct zonelist *zonelist; > unsigned long nr_reclaimed; > + unsigned long start, end; > int nid; > struct scan_control sc = { > .may_writepage = !laptop_mode, > @@ -2259,6 +2269,7 @@ unsigned long try_to_free_mem_cgroup_pag > .gfp_mask = sc.gfp_mask, > }; > > + start = sched_clock(); > /* > * Unlike direct reclaim via alloc_pages(), memcg's reclaim doesn't > * take care of from where we get pages. So the node where we start > the > @@ -2273,6 +2284,12 @@ unsigned long try_to_free_mem_cgroup_pag > sc.gfp_mask); > > nr_reclaimed = do_try_to_free_pages(zonelist, &sc, &shrink); > + end = sched_clock(); > + if (rec) { > + rec->nr_scanned += sc.nr_scanned; > sc.nr_scanned only contains the nr_scanned of last priority do_try_to_free_pages(). we need to reset it to total_scanned before return. I am looking at v3.0-rc3 . > + rec->nr_freed += sc.nr_reclaimed; > + rec->elappsed += end - start; > elapsed? > + } > > trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed); > > > --Ying --00163649971d6f1b5504a6334269 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Wed, Jun 15, 2011 at 8:53 PM, KAMEZAW= A Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:
>>From e08990dd9ada13cf236bec1ef44b207436434b8e Mon Sep 17 00:00:00 2001
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Date: Wed, 15 Jun 2011 14:11:01 +0900
Subject: [PATCH 3/7] memcg: add memory.scan_stat

commit log of commit 0ae5e89 " memcg: count the soft_limit reclaim in.= .."
says it adds scanning stats to memory.stat file. But it doesn't because=
we considered we needed to make a concensus for such new APIs.

This patch is a trial to add memory.scan_stat. This shows
=A0- the number of scanned pages
=A0- the number of recleimed pages
=A0- the number of elaplsed time (including sleep/pause time)
=A0for both of direct/soft reclaim and shrinking caused by changing limit<= br> =A0or force_empty.

The biggest difference with oringinal Ying's one is that this file
can be reset by some write, as

=A0# echo 0 ...../memory.scan_stat

[kamezawa@bluextal ~]$ cat /cgroup/memory/A/memory.scan_stat
scanned_pages_by_limit 358470
freed_pages_by_limit 180795
elapsed_ns_by_limit 21629927
scanned_pages_by_system 0
freed_pages_by_system 0
elapsed_ns_by_system 0
scanned_pages_by_shrink 76646
freed_pages_by_shrink 38355
elappsed_ns_by_shrink 31990670

elapsed?=
=A0
total_scanned_pages_by_limit 358470
total_freed_pages_by_limit 180795
total_elapsed_ns_by_hierarchical 216299275
total_scanned_pages_by_system 0
total_freed_pages_by_system 0
total_elapsed_ns_by_system 0
total_scanned_pages_by_shrink 76646
total_freed_pages_by_shrink 38355
total_elapsed_ns_by_shrink 31990670

total_xxxx is for hierarchy management.

For some reason, i feel the=A0opposite where the local stat (like "sc= anned_pages_by_limit") are reclaimed under hierarchical reclaim. The t= otal_xxx stats are only incremented for root_mem which is the cgroup trigge= rs the hierarchical reclaim. So:

total_scanned_pages_by_limit: number of pages being sca= nned while the memcg hits its limit
scann= ed_pages_by_limit: number of pages being scanned while one of the memcg'= ;s=A0ancestor hits its limit

am i missing something?=A0
=A0=A0=A0

This will be useful for further memcg developments and need to be
developped before we do some complicated rework on LRU/softlimit
management.

Now, scan/free/elapsed_by_system is incomplete but future works of
Johannes at el. will fill remaining information and then, we can
look into problems of isolation between memcgs.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
=A0Documentation/cgroups/memory.txt | =A0 33 +++++++++
=A0include/linux/memcontrol.h =A0 =A0 =A0 | =A0 16 ++++
=A0include/linux/swap.h =A0 =A0 =A0 =A0 =A0 =A0 | =A0 =A06 -
=A0mm/memcontrol.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0135 ++++++++++++= +++++++++++++++++++++++++--
=A0mm/vmscan.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 27 ++++++-<= br> =A05 files changed, 199 insertions(+), 18 deletions(-)

Index: mmotm-0615/Documentation/cgroups/memory.txt
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- mmotm-0615.orig/Documentation/cgroups/memory.txt
+++ mmotm-0615/Documentation/cgroups/memory.txt
@@ -380,7 +380,7 @@ will be charged as a new owner of it.

=A05.2 stat file

-memory.stat file includes following statistics
+5.2.1 memory.stat file includes following statistics

=A0# per-memory cgroup local status
=A0cache =A0 =A0 =A0 =A0 =A0- # of bytes of page cache memory.
@@ -438,6 +438,37 @@ Note:
=A0 =A0 =A0 =A0 file_mapped is accounted only when the memory cgroup is ow= ner of page
=A0 =A0 =A0 =A0 cache.)

+5.2.2 memory.scan_stat
+
+memory.scan_stat includes statistics information for memory scanning and +freeing, reclaiming. The statistics shows memory scanning information sinc= e
+memory cgroup creation and can be reset to 0 by writing 0 as
+
+ #echo 0 > ../memory.scan_stat
+
+This file contains following statistics.
+
+scanned_pages_by_limit - # of scanned pages at hitting limit.
+freed_pages_by_limit =A0 - # of freed pages at hitting limit.
+elapsed_ns_by_limit =A0 =A0- nano sec of elappsed time at LRU scan at
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hittin= g limit.(this includes sleep time.)
elapsed?=A0
+
+scanned_pages_by_system =A0 =A0 =A0 =A0- # of scanned pages by the kernel.=
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (Now, this value means gl= obal memory reclaim
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 caused by system memo= ry shortage with a hint
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0of softlimit. "No= soft limit" case will be
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0supported in future.)<= br> +freed_pages_by_system =A0- # of freed pages by the kernel.
+elapsed_ns_by_system =A0 - nano sec of elappsed time by kernel.
+
+scanned_pages_by_shrink =A0 =A0 =A0 =A0- # of scanned pages by shrinking.<= br> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (i.e. cha= nges of limit, force_empty, etc.)
+freed_pages_by_shrink =A0- # of freed pages by shirkining.
+elappsed_ns_by_shrink =A0- nano sec of elappsed time at shrinking.
elapsed?=A0
+
+total_xxx includes the statistics of children scanning caused by the cgrou= p.

based on the code inspection, the to= tal_xxx also includes the cgroup's scan stat as well.

+
+
=A05.3 swappiness

=A0Similar to /proc/sys/vm/swappiness, but affecting a hierarchy of groups = only.
Index: mmotm-0615/include/linux/memcontrol.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- mmotm-0615.orig/include/linux/memcontrol.h
+++ mmotm-0615/include/linux/memcontrol.h
@@ -120,6 +120,22 @@ struct zone_reclaim_stat*
=A0mem_cgroup_get_reclaim_stat_from_page(struct page *page);
=A0extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0struct task_struct *p);
+struct memcg_scanrecord {
+ =A0 =A0 =A0 struct mem_cgroup *mem; /* scanend memory cgroup */
+ =A0 =A0 =A0 struct mem_cgroup *root; /* scan target hierarchy root */
+ =A0 =A0 =A0 int context; =A0 =A0 =A0 =A0 =A0 =A0/* scanning context (see = memcontrol.c) */
+ =A0 =A0 =A0 unsigned long nr_scanned; /* the number of scanned pages */ + =A0 =A0 =A0 unsigned long nr_freed; /* the number of freed pages */
+ =A0 =A0 =A0 unsigned long elappsed; /* nsec of time elapsed while scannin= g */
elapsed?=A0
+};
+
+extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem,<= br> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 gfp_t gfp_mask, bool noswap,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 struct memcg_scanrecord *rec);
+extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 gfp_t gfp_mask, bool noswap,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 struct zone *zone,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 struct memcg_scanrecord *rec);

=A0#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
=A0extern int do_swap_account;
Index: mmotm-0615/include/linux/swap.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- mmotm-0615.orig/include/linux/swap.h
+++ mmotm-0615/include/linux/swap.h
@@ -253,12 +253,6 @@ static inline void lru_cache_add_file(st
=A0/* linux/mm/vmscan.c */
=A0extern unsigned long try_to_free_pages(struct zonelist *zonelist, int or= der,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0gfp_t gfp_mask, nodemask_t *mask);
-extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem,<= br> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 gfp_t gfp_mask, bool noswap);
-extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 gfp_t gfp_mask, bool noswap,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 struct zone *zone,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 unsigned long *nr_scanned);
=A0extern int __isolate_lru_page(struct page *page, int mode, int file); =A0extern unsigned long shrink_all_memory(unsigned long nr_pages);
=A0extern int vm_swappiness;
Index: mmotm-0615/mm/memcontrol.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- mmotm-0615.orig/mm/memcontrol.c
+++ mmotm-0615/mm/memcontrol.c
@@ -203,6 +203,57 @@ struct mem_cgroup_eventfd_list {
=A0static void mem_cgroup_threshold(struct mem_cgroup *mem);
=A0static void mem_cgroup_oom_notify(struct mem_cgroup *mem);

+enum {
+ =A0 =A0 =A0 SCAN_BY_LIMIT,
+ =A0 =A0 =A0 FREED_BY_LIMIT,
+ =A0 =A0 =A0 ELAPSED_BY_LIMIT,
+
+ =A0 =A0 =A0 SCAN_BY_SYSTEM,
+ =A0 =A0 =A0 FREED_BY_SYSTEM,
+ =A0 =A0 =A0 ELAPSED_BY_SYSTEM,
+
+ =A0 =A0 =A0 SCAN_BY_SHRINK,
+ =A0 =A0 =A0 FREED_BY_SHRINK,
+ =A0 =A0 =A0 ELAPSED_BY_SHRINK,
+ =A0 =A0 =A0 NR_SCANSTATS,
+};
+#define __FREED =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(1)
+#define =A0 =A0 =A0 =A0__ELAPSED =A0 =A0 =A0 (2)

=
/tab/space/
=A0
+
+struct scanstat {
+ =A0 =A0 =A0 spinlock_t =A0 =A0 =A0lock;
+ =A0 =A0 =A0 unsigned long =A0 stats[NR_SCANSTATS]; =A0 =A0/* local statis= tics */
+ =A0 =A0 =A0 unsigned long =A0 totalstats[NR_SCANSTATS]; =A0 /* hierarchic= al */
+};
+
+const char *scanstat_string[NR_SCANSTATS] =3D {
+ =A0 =A0 =A0 "scanned_pages_by_limit",
+ =A0 =A0 =A0 "freed_pages_by_limit",
+ =A0 =A0 =A0 "elapsed_ns_by_limit",
+
+ =A0 =A0 =A0 "scanned_pages_by_system",
+ =A0 =A0 =A0 "freed_pages_by_system",
+ =A0 =A0 =A0 "elapsed_ns_by_system",
+
+ =A0 =A0 =A0 "scanned_pages_by_shrink",
+ =A0 =A0 =A0 "freed_pages_by_shrink",
+ =A0 =A0 =A0 "elappsed_ns_by_shrink",
elapsed?=A0
+};
+
+const char *total_scanstat_string[NR_SCANSTATS] =3D {
+ =A0 =A0 =A0 "total_scanned_pages_by_limit",
+ =A0 =A0 =A0 "total_freed_pages_by_limit",
+ =A0 =A0 =A0 "total_elapsed_ns_by_hierarchical",

typo?
=A0
+
+ =A0 =A0 =A0 "total_scanned_pages_by_system",
+ =A0 =A0 =A0 "total_freed_pages_by_system",
+ =A0 =A0 =A0 "total_elapsed_ns_by_system",
+
+ =A0 =A0 =A0 "total_scanned_pages_by_shrink",
+ =A0 =A0 =A0 "total_freed_pages_by_shrink",
+ =A0 =A0 =A0 "total_elapsed_ns_by_shrink",
+};
+
=A0/*
=A0* The memory controller data structure. The memory controller controls = both
=A0* page cache and RSS per cgroup. We would eventually like to provide @@ -264,7 +315,8 @@ struct mem_cgroup {

=A0 =A0 =A0 =A0/* For oom notifier event fd */
=A0 =A0 =A0 =A0struct list_head oom_notify;
-
+ =A0 =A0 =A0 /* For recording LRU-scan statistics */
+ =A0 =A0 =A0 struct scanstat scanstat;
=A0 =A0 =A0 =A0/*
=A0 =A0 =A0 =A0 * Should we move charges of a task when a task is moved in= to this
=A0 =A0 =A0 =A0 * mem_cgroup ? And what type of charges should we move ? @@ -1634,6 +1686,28 @@ int mem_cgroup_select_victim_node(struct
=A0}
=A0#endif

+
+
+static void mem_cgroup_record_scanstat(struct memcg_scanrecord *rec)
+{
+ =A0 =A0 =A0 struct mem_cgroup *mem;
+ =A0 =A0 =A0 int context =3D rec->context;
+
+ =A0 =A0 =A0 mem =3D rec->mem;
+ =A0 =A0 =A0 spin_lock(&mem->scanstat.lock);
+ =A0 =A0 =A0 mem->scanstat.stats[context] +=3D rec->nr_scanned;
+ =A0 =A0 =A0 mem->scanstat.stats[context + __FREED] +=3D rec->nr_fre= ed;
+ =A0 =A0 =A0 mem->scanstat.stats[context + __ELAPSED] +=3D rec->elap= psed;
elapsed?=A0

+ =A0 =A0 =A0 spin_unlock(&mem->scanstat.lock);
+
+ =A0 =A0 =A0 mem =3D rec->root;
+ =A0 =A0 =A0 spin_lock(&mem->scanstat.lock);
+ =A0 =A0 =A0 mem->scanstat.totalstats[context] +=3D rec->nr_scanned;=
+ =A0 =A0 =A0 mem->scanstat.totalstats[context + __FREED] +=3D rec->n= r_freed;
+ =A0 =A0 =A0 mem->scanstat.totalstats[context + __ELAPSED] +=3D rec->= ;elappsed;

elap= sed?=A0
+ =A0 =A0 =A0 spin_unlock(&mem->scanstat.lock);
+}
+
=A0/*
=A0* Scan the hierarchy if needed to reclaim memory. We remember the last = child
=A0* we reclaimed from, so that we don't end up penalizing one child e= xtensively
@@ -1659,8 +1733,8 @@ static int mem_cgroup_hierarchical_recla
=A0 =A0 =A0 =A0bool shrink =3D reclaim_options & MEM_CGROUP_RECLAIM_SH= RINK;
=A0 =A0 =A0 =A0bool check_soft =3D reclaim_options & MEM_CGROUP_RECLAI= M_SOFT;
=A0 =A0 =A0 =A0unsigned long excess;
- =A0 =A0 =A0 unsigned long nr_scanned;
=A0 =A0 =A0 =A0int visit;
+ =A0 =A0 =A0 struct memcg_scanrecord rec;

=A0 =A0 =A0 =A0excess =3D res_counter_soft_limit_excess(&root_mem->= res) >> PAGE_SHIFT;

@@ -1668,6 +1742,15 @@ static int mem_cgroup_hierarchical_recla
=A0 =A0 =A0 =A0if (!check_soft && root_mem->memsw_is_minimum) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0noswap =3D true;

+ =A0 =A0 =A0 if (shrink)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec.context =3D SCAN_BY_SHRINK;
+ =A0 =A0 =A0 else if (check_soft)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec.context =3D SCAN_BY_SYSTEM;
+ =A0 =A0 =A0 else
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec.context =3D SCAN_BY_LIMIT;
+
+ =A0 =A0 =A0 rec.root =3D root_mem;
=A0
=A0=
+
=A0again:
=A0 =A0 =A0 =A0if (!shrink) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0visit =3D 0;
@@ -1695,14 +1778,19 @@ again:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0css_put(&victim->css= );
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec.mem =3D victim;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec.nr_scanned =3D 0;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec.nr_freed =3D 0;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec.elappsed =3D 0;
elapsed?=A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* we use swappiness of local cgroup */
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (check_soft) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D mem_cgroup_shrink_n= ode_zone(victim, gfp_mask,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 noswap, zone,= &nr_scanned);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *total_scanned +=3D nr_scanne= d;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 noswap, zone,= &rec);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *total_scanned +=3D rec.nr_sc= anned;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} else
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D try_to_free_mem_cgr= oup_pages(victim, gfp_mask,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 noswap);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 noswap, &rec);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem_cgroup_record_scanstat(&rec);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0css_put(&victim->css);

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0total +=3D ret;
@@ -3757,7 +3845,8 @@ try_to_free:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D -EINTR;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 progress =3D try_to_free_mem_cgroup_pages(mem= , GFP_KERNEL, false);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 progress =3D try_to_free_mem_cgroup_pages(mem= ,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 GFP_KERNEL, f= alse, NULL);

So we don't record the= stat for force_empty case?
=A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (!progress) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0nr_retries--;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* maybe some writeback is = necessary */
@@ -4599,6 +4688,34 @@ static int mem_control_numa_stat_open(st
=A0}
=A0#endif /* CONFIG_NUMA */

+static int mem_cgroup_scan_stat_read(struct cgroup *cgrp,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct cftype= *cft,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct cgroup= _map_cb *cb)
+{
+ =A0 =A0 =A0 struct mem_cgroup *mem =3D mem_cgroup_from_cont(cgrp);
+ =A0 =A0 =A0 int i;
+
+ =A0 =A0 =A0 for (i =3D 0; i < NR_SCANSTATS; i++)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 cb->fill(cb, scanstat_string[i], mem->s= canstat.stats[i]);
+ =A0 =A0 =A0 for (i =3D 0; i < NR_SCANSTATS; i++)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 cb->fill(cb, total_scanstat_string[i],
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem->scanstat.totalstats[i= ]);
+ =A0 =A0 =A0 return 0;
+}
+
+static int mem_cgroup_reset_scan_stat(struct cgroup *cgrp,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int = event)
+{
+ =A0 =A0 =A0 struct mem_cgroup *mem =3D mem_cgroup_from_cont(cgrp);
+
+ =A0 =A0 =A0 spin_lock(&mem->scanstat.lock);
+ =A0 =A0 =A0 memset(&mem->scanstat.stats, 0, sizeof(mem->scansta= t.stats));
+ =A0 =A0 =A0 memset(&mem->scanstat.totalstats, 0, sizeof(mem->sc= anstat.totalstats));
+ =A0 =A0 =A0 spin_unlock(&mem->scanstat.lock);
+ =A0 =A0 =A0 return 0;
+}
+
+
=A0static struct cftype mem_cgroup_files[] =3D {
=A0 =A0 =A0 =A0{
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.name =3D "usage_in_bytes",
@@ -4669,6 +4786,11 @@ static struct cftype mem_cgroup_files[]
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.mode =3D S_IRUGO,
=A0 =A0 =A0 =A0},
=A0#endif
+ =A0 =A0 =A0 {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .name =3D "scan_stat",
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .read_map =3D mem_cgroup_scan_stat_read,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .trigger =3D mem_cgroup_reset_scan_stat,
+ =A0 =A0 =A0 },
=A0};

=A0#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
@@ -4932,6 +5054,7 @@ mem_cgroup_create(struct cgroup_subsys *
=A0 =A0 =A0 =A0atomic_set(&mem->refcnt, 1);
=A0 =A0 =A0 =A0mem->move_charge_at_immigrate =3D 0;
=A0 =A0 =A0 =A0mutex_init(&mem->thresholds_lock);
+ =A0 =A0 =A0 spin_lock_init(&mem->scanstat.lock);
=A0 =A0 =A0 =A0return &mem->css;
=A0free_out:
=A0 =A0 =A0 =A0__mem_cgroup_free(mem);
Index: mmotm-0615/mm/vmscan.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- mmotm-0615.orig/mm/vmscan.c
+++ mmotm-0615/mm/vmscan.c
@@ -2199,9 +2199,9 @@ unsigned long try_to_free_pages(struct z
=A0#ifdef CONFIG_CGROUP_MEM_RES_CTLR

=A0unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 gfp_t gfp_mask, bool noswap,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 struct zone *zone,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 unsigned long *nr_scanned)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 gfp_t gfp_mask, bool noswap,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 struct zone *zone,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 struct memcg_scanrecord *rec)
=A0{
=A0 =A0 =A0 =A0struct scan_control sc =3D {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.nr_scanned =3D 0,
@@ -2213,6 +2213,7 @@ unsigned long mem_cgroup_shrink_node_zon
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.order =3D 0,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.mem_cgroup =3D mem,
=A0 =A0 =A0 =A0};
+ =A0 =A0 =A0 unsigned long start, end;

=A0 =A0 =A0 =A0sc.gfp_mask =3D (gfp_mask & GFP_RECLAIM_MASK) |
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(GFP_HIGHUSER_MOVABLE &= ~GFP_RECLAIM_MASK);
@@ -2221,6 +2222,7 @@ unsigned long mem_cgroup_shrink_node_zon
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0sc.may_writepage,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0sc.gfp_mask);

+ =A0 =A0 =A0 start =3D sched_clock();
=A0 =A0 =A0 =A0/*
=A0 =A0 =A0 =A0 * NOTE: Although we can get the priority field, using it =A0 =A0 =A0 =A0 * here is not a good idea, since it limits the pages we ca= n scan.
@@ -2229,19 +2231,27 @@ unsigned long mem_cgroup_shrink_node_zon
=A0 =A0 =A0 =A0 * the priority and make it zero.
=A0 =A0 =A0 =A0 */
=A0 =A0 =A0 =A0shrink_zone(0, zone, &sc);
+ =A0 =A0 =A0 end =3D sched_clock();
+
+ =A0 =A0 =A0 if (rec) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec->nr_scanned +=3D sc.nr_scanned;

=A0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec->nr_freed +=3D sc.nr_reclaimed;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec->elappsed +=3D end - start;
elapsed?=A0
+ =A0 =A0 =A0 }

=A0 =A0 =A0 =A0trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed= );

- =A0 =A0 =A0 *nr_scanned =3D sc.nr_scanned;
=A0 =A0 =A0 =A0return sc.nr_reclaimed;
=A0}

=A0unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,<= br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 gfp_t gfp_mask,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0bool noswap)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0bool noswap,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0struct memcg_scanrecord *rec)
=A0{
=A0 =A0 =A0 =A0struct zonelist *zonelist;
=A0 =A0 =A0 =A0unsigned long nr_reclaimed;
+ =A0 =A0 =A0 unsigned long start, end;
=A0 =A0 =A0 =A0int nid;
=A0 =A0 =A0 =A0struct scan_control sc =3D {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.may_writepage =3D !laptop_mode,
@@ -2259,6 +2269,7 @@ unsigned long try_to_free_mem_cgroup_pag
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.gfp_mask =3D sc.gfp_mask,
=A0 =A0 =A0 =A0};

+ =A0 =A0 =A0 start =3D sched_clock();
=A0 =A0 =A0 =A0/*
=A0 =A0 =A0 =A0 * Unlike direct reclaim via alloc_pages(), memcg's rec= laim doesn't
=A0 =A0 =A0 =A0 * take care of from where we get pages. So the node where = we start the
@@ -2273,6 +2284,12 @@ unsigned long try_to_free_mem_cgroup_pag
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0sc.gfp_mask);

=A0 =A0 =A0 =A0nr_reclaimed =3D do_try_to_free_pages(zonelist, &sc, &a= mp;shrink);
+ =A0 =A0 =A0 end =3D sched_clock();
+ =A0 =A0 =A0 if (rec) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec->nr_scanned +=3D sc.nr_scanned;

sc.nr_scanned only= contains the nr_scanned of last priority=A0do_try_to_free_pages(). we need= to reset it to total_scanned before return. I am looking at=A0v3.0-rc3 .
=A0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0= rec->nr_freed +=3D sc.nr_reclaimed;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rec->elappsed +=3D end - start;
elapsed?=A0
+ =A0 =A0 =A0 }

=A0 =A0 =A0 =A0trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed);


--Ying=A0

--00163649971d6f1b5504a6334269-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: email@kvack.org