From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail143.messagelabs.com (mail143.messagelabs.com [216.82.254.35]) by kanga.kvack.org (Postfix) with ESMTP id 7568990023D for ; Fri, 24 Jun 2011 17:40:50 -0400 (EDT) Received: from hpaq2.eem.corp.google.com (hpaq2.eem.corp.google.com [172.25.149.2]) by smtp-out.google.com with ESMTP id p5OLejjq017309 for ; Fri, 24 Jun 2011 14:40:45 -0700 Received: from qwj9 (qwj9.prod.google.com [10.241.195.73]) by hpaq2.eem.corp.google.com with ESMTP id p5OLehLJ013535 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Fri, 24 Jun 2011 14:40:44 -0700 Received: by qwj9 with SMTP id 9so1284416qwj.21 for ; Fri, 24 Jun 2011 14:40:43 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20110622092031.e4be1846.kamezawa.hiroyu@jp.fujitsu.com> References: <20110616124730.d6960b8b.kamezawa.hiroyu@jp.fujitsu.com> <20110616125314.4f78b1e0.kamezawa.hiroyu@jp.fujitsu.com> <20110622092031.e4be1846.kamezawa.hiroyu@jp.fujitsu.com> Date: Fri, 24 Jun 2011 14:40:42 -0700 Message-ID: Subject: Re: [PATCH 3/7] memcg: add memory.scan_stat From: Ying Han Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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" On Tue, Jun 21, 2011 at 5:20 PM, KAMEZAWA Hiroyuki wrote: > On Mon, 20 Jun 2011 23:49:54 -0700 > Ying Han wrote: > >> 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 becaus= e >> > 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 li= mit >> > =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? >> > > you'r right. > >> >> > 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 me= mcg >> 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? >> > > scanned_pages_by_limit: one of ancestors and itself's limit. yes, and that is what I understood. > > > > >> >> > >> > 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 >> > --- >> > =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 +++= +++- >> > =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 i= s owner 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 >> > 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 =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 =A0h= itting limit.(this includes sleep >> > time.) >> > >> elapsed? >> >> > + >> > +scanned_pages_by_system =A0 =A0 =A0 =A0- # of scanned pages by the ke= rnel. >> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (Now, this value mea= ns global memory reclaim >> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 caused by system= memory 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 futu= re.) >> > +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 shrink= ing. >> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (i.e= . changes 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? >> >> > + >> > +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 s= can >> stat as well. >> > > yes. > > >> + >> > + >> > =A05.3 swappiness >> > >> > =A0Similar to /proc/sys/vm/swappiness, but affecting a hierarchy of gr= oups >> > 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 sc= anning */ >> > >> elapsed? >> >> > +}; >> > + >> > +extern unsigned long try_to_free_mem_cgroup_pages(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 =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 *m= em, >> > + =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, i= nt >> > order, >> > =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, >> > - =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 *m= em, >> > - =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/ >> >> >> > + >> > +struct scanstat { >> > + =A0 =A0 =A0 spinlock_t =A0 =A0 =A0lock; >> > + =A0 =A0 =A0 unsigned long =A0 stats[NR_SCANSTATS]; =A0 =A0/* local s= tatistics */ >> > + =A0 =A0 =A0 unsigned long =A0 totalstats[NR_SCANSTATS]; =A0 /* hiera= rchical */ >> > +}; I wonder why not extending the mem_cgroup_stat_cpu struct, and then we can use the per-cpu counters like others. diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b7d2d79..5b8bbe9 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -138,6 +138,7 @@ struct mem_cgroup_stat_cpu { long count[MEM_CGROUP_STAT_NSTATS]; unsigned long events[MEM_CGROUP_EVENTS_NSTATS]; unsigned long targets[MEM_CGROUP_NTARGETS]; + unsigned long reclaim_stats[MEMCG_RECLAIM_NSTATS]; }; /* @@ -557,6 +558,101 @@ static void __mem_cgroup_target_update(struct mem_cgroup *mem, int target) this_cpu_write(mem->stat->targets[target], next); } +void mem_cgroup_update_reclaim_stat(struct mem_cgroup *mem, + enum mem_cgroup_reclaim_stat_index idx, + unsigned long num) +{ + this_cpu_add(mem->stat->reclaim_stats[idx], num); +} >> > + >> > +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? >> >> > +}; >> > + >> > +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 "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 contr= ols >> > both >> > =A0* page cache and RSS per cgroup. We would eventually like to provid= e >> > @@ -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; Can we add this to mem_cgroup_stat_cpu ? >> > =A0 =A0 =A0 =A0/* >> > =A0 =A0 =A0 =A0 * Should we move charges of a task when a task is move= d into 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_free= d; >> > + =A0 =A0 =A0 mem->scanstat.stats[context + __ELAPSED] +=3D rec->elapp= sed; >> > >> elapsed? >> >> >> + =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->nr= _freed; >> > + =A0 =A0 =A0 mem->scanstat.totalstats[context + __ELAPSED] +=3D rec->= elappsed; >> > >> >> elapsed? >> >> > + =A0 =A0 =A0 spin_unlock(&mem->scanstat.lock); >> > +} >> > + >> > =A0/* >> > =A0* Scan the hierarchy if needed to reclaim memory. We remember the l= ast >> > child >> > =A0* we reclaimed from, so that we don't end up penalizing one child >> > extensively >> > @@ -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; >> > >> >> >> >> > + >> > =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/* 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_shri= nk_node_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_s= canned; >> > + =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_scanned; >> > =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= _cgroup_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_page= s(mem, GFP_KERNEL, >> > false); >> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 progress =3D try_to_free_mem_cgroup_page= s(mem, >> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 GFP_KERN= EL, false, NULL); >> > >> >> So we don't record the stat for force_empty case? >> > > yes, now. force_empty is used only for rmdir(). I don't think log is > necessary for cgroup disappearing. we might need to add that case later, since force_empty can also being used as adding external pressure to the memcg. > > >> >> > =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 c= ftype *cft, >> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct c= group_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->sc= anstat.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->scanstat.sta= ts)); >> > + =A0 =A0 =A0 memset(&mem->scanstat.totalstats, 0, >> > sizeof(mem->scanstat.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 w= e can 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 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 =A0trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_recla= imed); >> > >> > - =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_c= ont, >> > =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 wh= ere 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, &s= hrink); >> > + =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 do_try_to_free_pages(). we need to reset it to total_scanned be= fore >> return. I am looking at v3.0-rc3 . >> > > Hm. ok, then, total_reclaimed in softlimit is buggy, too. > I'll check. Thanks --Ying > > Thanks, > -Kame > > -- 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