From: Kamezawa Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
To: Sha Zhengju <handai.szj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
mhocko-AlSwsSmVLrQ@public.gmane.org,
glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org,
mgorman-l3A5Bk7waGM@public.gmane.org,
Sha Zhengju <handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH 2/6] memcg: Don't account root memcg CACHE/RSS stats
Date: Wed, 13 Mar 2013 10:12:55 +0900 [thread overview]
Message-ID: <513FD297.3050100@jp.fujitsu.com> (raw)
In-Reply-To: <1363082977-3753-1-git-send-email-handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
(2013/03/12 19:09), Sha Zhengju wrote:
> If memcg is enabled and no non-root memcg exists, all allocated pages
> belong to root_mem_cgroup and go through root memcg statistics routines
> which brings some overheads.
>
> So for the sake of performance, we can give up accounting stats of root
> memcg for MEM_CGROUP_STAT_CACHE/RSS and instead we pay special attention
> to memcg_stat_show() while showing root memcg numbers:
> as we don't account root memcg stats anymore, the root_mem_cgroup->stat
> numbers are actually 0. So we fake these numbers by using stats of global
> state and all other memcg. That is for root memcg:
>
> nr(MEM_CGROUP_STAT_CACHE) = global_page_state(NR_FILE_PAGES) -
> sum_of_all_memcg(MEM_CGROUP_STAT_CACHE);
>
> Rss pages accounting are in the similar way.
>
> Signed-off-by: Sha Zhengju <handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
> ---
> mm/memcontrol.c | 50 ++++++++++++++++++++++++++++++++++----------------
> 1 file changed, 34 insertions(+), 16 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 735cd41..e89204f 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -958,26 +958,27 @@ static void mem_cgroup_charge_statistics(struct mem_cgroup *memcg,
> {
> preempt_disable();
>
> - /*
> - * Here, RSS means 'mapped anon' and anon's SwapCache. Shmem/tmpfs is
> - * counted as CACHE even if it's on ANON LRU.
> - */
> - if (anon)
> - __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_RSS],
> - nr_pages);
> - else
> - __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_CACHE],
> - nr_pages);
> -
> /* pagein of a big page is an event. So, ignore page size */
> if (nr_pages > 0)
> __this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGIN]);
> - else {
> + else
> __this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGOUT]);
> - nr_pages = -nr_pages; /* for event */
> - }
>
> - __this_cpu_add(memcg->stat->nr_page_events, nr_pages);
> + __this_cpu_add(memcg->stat->nr_page_events,
> + nr_pages < 0 ? -nr_pages : nr_pages);
> +
> + if (!mem_cgroup_is_root(memcg)) {
> + /*
> + * Here, RSS means 'mapped anon' and anon's SwapCache. Shmem/tmpfs is
> + * counted as CACHE even if it's on ANON LRU.
> + */
> + if (anon)
> + __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_RSS],
> + nr_pages);
> + else
> + __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_CACHE],
> + nr_pages);
> + }
Hmm. I don't like to add this check to this fast path. IIUC, with Costa's patch, root memcg
will not make any charges at all and never call this function. I like his one rather than
this patching.
Thanks,
-Kame
>
> preempt_enable();
> }
> @@ -5445,12 +5446,24 @@ static int memcg_stat_show(struct cgroup *cont, struct cftype *cft,
> struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
> struct mem_cgroup *mi;
> unsigned int i;
> + enum zone_stat_item global_stat[] = {NR_FILE_PAGES, NR_ANON_PAGES};
> + long root_stat[MEM_CGROUP_STAT_NSTATS] = {0};
>
> for (i = 0; i < MEM_CGROUP_STAT_NSTATS; i++) {
> + long val = 0;
> +
> if (i == MEM_CGROUP_STAT_SWAP && !do_swap_account)
> continue;
> +
> + if (mem_cgroup_is_root(memcg) && (i == MEM_CGROUP_STAT_CACHE
> + || i == MEM_CGROUP_STAT_RSS)) {
> + val = global_page_state(global_stat[i]) -
> + mem_cgroup_recursive_stat(memcg, i);
> + root_stat[i] = val = val < 0 ? 0 : val;
> + } else
> + val = mem_cgroup_read_stat(memcg, i);
> seq_printf(m, "%s %ld\n", mem_cgroup_stat_names[i],
> - mem_cgroup_read_stat(memcg, i) * PAGE_SIZE);
> + val * PAGE_SIZE);
> }
>
> for (i = 0; i < MEM_CGROUP_EVENTS_NSTATS; i++)
> @@ -5478,6 +5491,11 @@ static int memcg_stat_show(struct cgroup *cont, struct cftype *cft,
> continue;
> for_each_mem_cgroup_tree(mi, memcg)
> val += mem_cgroup_read_stat(mi, i) * PAGE_SIZE;
> +
> + /* Adding local stats of root memcg */
> + if (mem_cgroup_is_root(memcg))
> + val += root_stat[i] * PAGE_SIZE;
> +
> seq_printf(m, "total_%s %lld\n", mem_cgroup_stat_names[i], val);
> }
>
>
WARNING: multiple messages have this Message-ID (diff)
From: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: Sha Zhengju <handai.szj@gmail.com>
Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.cz,
glommer@parallels.com, akpm@linux-foundation.org,
mgorman@suse.de, Sha Zhengju <handai.szj@taobao.com>
Subject: Re: [PATCH 2/6] memcg: Don't account root memcg CACHE/RSS stats
Date: Wed, 13 Mar 2013 10:12:55 +0900 [thread overview]
Message-ID: <513FD297.3050100@jp.fujitsu.com> (raw)
In-Reply-To: <1363082977-3753-1-git-send-email-handai.szj@taobao.com>
(2013/03/12 19:09), Sha Zhengju wrote:
> If memcg is enabled and no non-root memcg exists, all allocated pages
> belong to root_mem_cgroup and go through root memcg statistics routines
> which brings some overheads.
>
> So for the sake of performance, we can give up accounting stats of root
> memcg for MEM_CGROUP_STAT_CACHE/RSS and instead we pay special attention
> to memcg_stat_show() while showing root memcg numbers:
> as we don't account root memcg stats anymore, the root_mem_cgroup->stat
> numbers are actually 0. So we fake these numbers by using stats of global
> state and all other memcg. That is for root memcg:
>
> nr(MEM_CGROUP_STAT_CACHE) = global_page_state(NR_FILE_PAGES) -
> sum_of_all_memcg(MEM_CGROUP_STAT_CACHE);
>
> Rss pages accounting are in the similar way.
>
> Signed-off-by: Sha Zhengju <handai.szj@taobao.com>
> ---
> mm/memcontrol.c | 50 ++++++++++++++++++++++++++++++++++----------------
> 1 file changed, 34 insertions(+), 16 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 735cd41..e89204f 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -958,26 +958,27 @@ static void mem_cgroup_charge_statistics(struct mem_cgroup *memcg,
> {
> preempt_disable();
>
> - /*
> - * Here, RSS means 'mapped anon' and anon's SwapCache. Shmem/tmpfs is
> - * counted as CACHE even if it's on ANON LRU.
> - */
> - if (anon)
> - __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_RSS],
> - nr_pages);
> - else
> - __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_CACHE],
> - nr_pages);
> -
> /* pagein of a big page is an event. So, ignore page size */
> if (nr_pages > 0)
> __this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGIN]);
> - else {
> + else
> __this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGOUT]);
> - nr_pages = -nr_pages; /* for event */
> - }
>
> - __this_cpu_add(memcg->stat->nr_page_events, nr_pages);
> + __this_cpu_add(memcg->stat->nr_page_events,
> + nr_pages < 0 ? -nr_pages : nr_pages);
> +
> + if (!mem_cgroup_is_root(memcg)) {
> + /*
> + * Here, RSS means 'mapped anon' and anon's SwapCache. Shmem/tmpfs is
> + * counted as CACHE even if it's on ANON LRU.
> + */
> + if (anon)
> + __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_RSS],
> + nr_pages);
> + else
> + __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_CACHE],
> + nr_pages);
> + }
Hmm. I don't like to add this check to this fast path. IIUC, with Costa's patch, root memcg
will not make any charges at all and never call this function. I like his one rather than
this patching.
Thanks,
-Kame
>
> preempt_enable();
> }
> @@ -5445,12 +5446,24 @@ static int memcg_stat_show(struct cgroup *cont, struct cftype *cft,
> struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
> struct mem_cgroup *mi;
> unsigned int i;
> + enum zone_stat_item global_stat[] = {NR_FILE_PAGES, NR_ANON_PAGES};
> + long root_stat[MEM_CGROUP_STAT_NSTATS] = {0};
>
> for (i = 0; i < MEM_CGROUP_STAT_NSTATS; i++) {
> + long val = 0;
> +
> if (i == MEM_CGROUP_STAT_SWAP && !do_swap_account)
> continue;
> +
> + if (mem_cgroup_is_root(memcg) && (i == MEM_CGROUP_STAT_CACHE
> + || i == MEM_CGROUP_STAT_RSS)) {
> + val = global_page_state(global_stat[i]) -
> + mem_cgroup_recursive_stat(memcg, i);
> + root_stat[i] = val = val < 0 ? 0 : val;
> + } else
> + val = mem_cgroup_read_stat(memcg, i);
> seq_printf(m, "%s %ld\n", mem_cgroup_stat_names[i],
> - mem_cgroup_read_stat(memcg, i) * PAGE_SIZE);
> + val * PAGE_SIZE);
> }
>
> for (i = 0; i < MEM_CGROUP_EVENTS_NSTATS; i++)
> @@ -5478,6 +5491,11 @@ static int memcg_stat_show(struct cgroup *cont, struct cftype *cft,
> continue;
> for_each_mem_cgroup_tree(mi, memcg)
> val += mem_cgroup_read_stat(mi, i) * PAGE_SIZE;
> +
> + /* Adding local stats of root memcg */
> + if (mem_cgroup_is_root(memcg))
> + val += root_stat[i] * PAGE_SIZE;
> +
> seq_printf(m, "total_%s %lld\n", mem_cgroup_stat_names[i], val);
> }
>
>
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2013-03-13 1:12 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-12 10:06 [PATCH 0/6] memcg: bypass root memcg page stat accounting Sha Zhengju
2013-03-12 10:06 ` Sha Zhengju
2013-03-12 10:08 ` [PATCH 1/6] memcg: use global stat directly for root memcg usage Sha Zhengju
[not found] ` <1363082920-3711-1-git-send-email-handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
2013-03-13 1:05 ` Kamezawa Hiroyuki
2013-03-13 1:05 ` Kamezawa Hiroyuki
[not found] ` <513FD0CB.4000407-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2013-03-13 8:50 ` Sha Zhengju
2013-03-13 8:50 ` Sha Zhengju
[not found] ` <1363082773-3598-1-git-send-email-handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
2013-03-12 10:09 ` [PATCH 2/6] memcg: Don't account root memcg CACHE/RSS stats Sha Zhengju
2013-03-12 10:09 ` Sha Zhengju
[not found] ` <1363082977-3753-1-git-send-email-handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
2013-03-13 1:12 ` Kamezawa Hiroyuki [this message]
2013-03-13 1:12 ` Kamezawa Hiroyuki
[not found] ` <513FD297.3050100-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2013-03-13 9:09 ` Sha Zhengju
2013-03-13 9:09 ` Sha Zhengju
2013-03-20 7:07 ` Glauber Costa
2013-03-20 7:07 ` Glauber Costa
2013-03-12 10:10 ` [PATCH 3/6] memcg: Don't account root memcg MEM_CGROUP_STAT_FILE_MAPPED stats Sha Zhengju
2013-03-12 10:10 ` Sha Zhengju
2013-03-12 10:10 ` [PATCH 4/6] memcg: Don't account root memcg swap stats Sha Zhengju
2013-03-12 10:10 ` Sha Zhengju
2013-03-12 10:11 ` [PATCH 5/6] memcg: Don't account root memcg PGFAULT/PGMAJFAULT events Sha Zhengju
2013-03-12 10:11 ` Sha Zhengju
2013-03-12 10:11 ` [PATCH 6/6] memcg: disable memcg page stat accounting Sha Zhengju
2013-03-12 10:11 ` Sha Zhengju
[not found] ` <1363083103-3907-1-git-send-email-handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
2013-03-20 7:09 ` Glauber Costa
2013-03-20 7:09 ` Glauber Costa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=513FD297.3050100@jp.fujitsu.com \
--to=kamezawa.hiroyu-+cum20s59erqfuhtdcdx3a@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org \
--cc=handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org \
--cc=handai.szj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
--cc=mgorman-l3A5Bk7waGM@public.gmane.org \
--cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.