linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memcg: drain all stocks for the cgroup before read usage
@ 2011-09-04  1:15 Kirill A. Shutemov
  2011-09-04  7:20 ` Paul Menage
  2011-09-04 23:59 ` KAMEZAWA Hiroyuki
  0 siblings, 2 replies; 9+ messages in thread
From: Kirill A. Shutemov @ 2011-09-04  1:15 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Balbir Singh, Daisuke Nishimura, KAMEZAWA Hiroyuki, linux-mm,
	linux-kernel, Kirill A. Shutemov

From: "Kirill A. Shutemov" <kirill@shutemov.name>

Currently, mem_cgroup_usage() for non-root cgroup returns usage
including stocks.

Let's drain all socks before read resource counter value. It makes
memory{,.memcg}.usage_in_bytes and memory.stat consistent.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 mm/memcontrol.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ebd1e86..e091022 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3943,6 +3943,7 @@ static inline u64 mem_cgroup_usage(struct mem_cgroup *mem, bool swap)
 	u64 val;
 
 	if (!mem_cgroup_is_root(mem)) {
+		drain_all_stock_sync(mem);
 		if (!swap)
 			return res_counter_read_u64(&mem->res, RES_USAGE);
 		else
-- 
1.7.5.4

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] memcg: drain all stocks for the cgroup before read usage
  2011-09-04  1:15 [PATCH] memcg: drain all stocks for the cgroup before read usage Kirill A. Shutemov
@ 2011-09-04  7:20 ` Paul Menage
  2011-09-04 23:59 ` KAMEZAWA Hiroyuki
  1 sibling, 0 replies; 9+ messages in thread
From: Paul Menage @ 2011-09-04  7:20 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Andrew Morton, Balbir Singh, Daisuke Nishimura, KAMEZAWA Hiroyuki,
	linux-mm, linux-kernel

On Sat, Sep 3, 2011 at 6:15 PM, Kirill A. Shutemov <kirill@shutemov.name> wrote:
> From: "Kirill A. Shutemov" <kirill@shutemov.name>
>
> Currently, mem_cgroup_usage() for non-root cgroup returns usage
> including stocks.
>
> Let's drain all socks before read resource counter value. It makes
> memory{,.memcg}.usage_in_bytes and memory.stat consistent.

Isn't that quite an expensive operation, and bear in mind that
resource control trackers may be reading this file very frequently,
maybe every second or so.

How about having a trigger file that can be written to force the drain
for cases where the consistency is really desired? Or a separate
usage_in_bytes_consistent file that does the drain.

Paul

>
> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> ---
>  mm/memcontrol.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index ebd1e86..e091022 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3943,6 +3943,7 @@ static inline u64 mem_cgroup_usage(struct mem_cgroup *mem, bool swap)
>        u64 val;
>
>        if (!mem_cgroup_is_root(mem)) {
> +               drain_all_stock_sync(mem);
>                if (!swap)
>                        return res_counter_read_u64(&mem->res, RES_USAGE);
>                else
> --
> 1.7.5.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] memcg: drain all stocks for the cgroup before read usage
  2011-09-04  1:15 [PATCH] memcg: drain all stocks for the cgroup before read usage Kirill A. Shutemov
  2011-09-04  7:20 ` Paul Menage
@ 2011-09-04 23:59 ` KAMEZAWA Hiroyuki
  2011-09-05  1:16   ` Daisuke Nishimura
  1 sibling, 1 reply; 9+ messages in thread
From: KAMEZAWA Hiroyuki @ 2011-09-04 23:59 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Andrew Morton, Balbir Singh, Daisuke Nishimura, linux-mm,
	linux-kernel

On Sun,  4 Sep 2011 04:15:33 +0300
"Kirill A. Shutemov" <kirill@shutemov.name> wrote:

> From: "Kirill A. Shutemov" <kirill@shutemov.name>
> 
> Currently, mem_cgroup_usage() for non-root cgroup returns usage
> including stocks.
> 
> Let's drain all socks before read resource counter value. It makes
> memory{,.memcg}.usage_in_bytes and memory.stat consistent.
> 
> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>

Hmm. This seems costly to me. 

If a user chesk usage_in_bytes in a memcg once per 1sec, 
the kernel will call schedule_work on cpus once per 1sec.
So, IMHO, I don't like this.

But if some other guys want this, I'll ack.

BTW, how this affects memory.stat ?

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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] memcg: drain all stocks for the cgroup before read usage
  2011-09-04 23:59 ` KAMEZAWA Hiroyuki
@ 2011-09-05  1:16   ` Daisuke Nishimura
  2011-09-07 21:33     ` Kirill A. Shutemov
  0 siblings, 1 reply; 9+ messages in thread
From: Daisuke Nishimura @ 2011-09-05  1:16 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki
  Cc: Kirill A. Shutemov, Andrew Morton, Balbir Singh, linux-mm,
	linux-kernel, Daisuke Nishimura

On Mon, 5 Sep 2011 08:59:13 +0900
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:

> On Sun,  4 Sep 2011 04:15:33 +0300
> "Kirill A. Shutemov" <kirill@shutemov.name> wrote:
> 
> > From: "Kirill A. Shutemov" <kirill@shutemov.name>
> > 
> > Currently, mem_cgroup_usage() for non-root cgroup returns usage
> > including stocks.
> > 
> > Let's drain all socks before read resource counter value. It makes
> > memory{,.memcg}.usage_in_bytes and memory.stat consistent.
> > 
> > Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> 
> Hmm. This seems costly to me. 
> 
> If a user chesk usage_in_bytes in a memcg once per 1sec, 
> the kernel will call schedule_work on cpus once per 1sec.
> So, IMHO, I don't like this.
> 
I agree.

We discussed a similar topic on the thread https://lkml.org/lkml/2011/3/18/212.
And, we added the memory.txt:
---
5.5 usage_in_bytes

For efficiency, as other kernel components, memory cgroup uses some optimization
to avoid unnecessary cacheline false sharing. usage_in_bytes is affected by the
method and doesn't show 'exact' value of memory(and swap) usage, it's an fuzz
value for efficient access. (Of course, when necessary, it's synchronized.)
If you want to know more exact memory usage, you should use RSS+CACHE(+SWAP)
value in memory.stat(see 5.2).
---

Thanks,
Daisuke Nishimura.

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] memcg: drain all stocks for the cgroup before read usage
  2011-09-05  1:16   ` Daisuke Nishimura
@ 2011-09-07 21:33     ` Kirill A. Shutemov
  2011-09-08  0:19       ` KAMEZAWA Hiroyuki
  0 siblings, 1 reply; 9+ messages in thread
From: Kirill A. Shutemov @ 2011-09-07 21:33 UTC (permalink / raw)
  To: Daisuke Nishimura
  Cc: KAMEZAWA Hiroyuki, Andrew Morton, Balbir Singh, linux-mm,
	linux-kernel

On Mon, Sep 05, 2011 at 10:16:07AM +0900, Daisuke Nishimura wrote:
> On Mon, 5 Sep 2011 08:59:13 +0900
> KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:
> 
> > On Sun,  4 Sep 2011 04:15:33 +0300
> > "Kirill A. Shutemov" <kirill@shutemov.name> wrote:
> > 
> > > From: "Kirill A. Shutemov" <kirill@shutemov.name>
> > > 
> > > Currently, mem_cgroup_usage() for non-root cgroup returns usage
> > > including stocks.
> > > 
> > > Let's drain all socks before read resource counter value. It makes
> > > memory{,.memcg}.usage_in_bytes and memory.stat consistent.
> > > 
> > > Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> > 
> > Hmm. This seems costly to me. 
> > 
> > If a user chesk usage_in_bytes in a memcg once per 1sec, 
> > the kernel will call schedule_work on cpus once per 1sec.
> > So, IMHO, I don't like this.
> > 
> I agree.
> 
> We discussed a similar topic on the thread https://lkml.org/lkml/2011/3/18/212.
> And, we added the memory.txt:
> ---
> 5.5 usage_in_bytes
> 
> For efficiency, as other kernel components, memory cgroup uses some optimization
> to avoid unnecessary cacheline false sharing. usage_in_bytes is affected by the
> method and doesn't show 'exact' value of memory(and swap) usage, it's an fuzz
> value for efficient access. (Of course, when necessary, it's synchronized.)
> If you want to know more exact memory usage, you should use RSS+CACHE(+SWAP)
> value in memory.stat(see 5.2).
> ---

Agree, thanks.

Should we have field 'ram' (or 'memory') for rss+cache in memory.stat?

-- 
 Kirill A. Shutemov

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] memcg: drain all stocks for the cgroup before read usage
  2011-09-07 21:33     ` Kirill A. Shutemov
@ 2011-09-08  0:19       ` KAMEZAWA Hiroyuki
  2011-09-08  0:49         ` Kirill A. Shutemov
  0 siblings, 1 reply; 9+ messages in thread
From: KAMEZAWA Hiroyuki @ 2011-09-08  0:19 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Daisuke Nishimura, Andrew Morton, Balbir Singh, linux-mm,
	linux-kernel

On Thu, 8 Sep 2011 00:33:40 +0300
"Kirill A. Shutemov" <kirill@shutemov.name> wrote:

> On Mon, Sep 05, 2011 at 10:16:07AM +0900, Daisuke Nishimura wrote:
> > On Mon, 5 Sep 2011 08:59:13 +0900
> > KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:
> > 
> > > On Sun,  4 Sep 2011 04:15:33 +0300
> > > "Kirill A. Shutemov" <kirill@shutemov.name> wrote:
> > > 
> > > > From: "Kirill A. Shutemov" <kirill@shutemov.name>
> > > > 
> > > > Currently, mem_cgroup_usage() for non-root cgroup returns usage
> > > > including stocks.
> > > > 
> > > > Let's drain all socks before read resource counter value. It makes
> > > > memory{,.memcg}.usage_in_bytes and memory.stat consistent.
> > > > 
> > > > Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> > > 
> > > Hmm. This seems costly to me. 
> > > 
> > > If a user chesk usage_in_bytes in a memcg once per 1sec, 
> > > the kernel will call schedule_work on cpus once per 1sec.
> > > So, IMHO, I don't like this.
> > > 
> > I agree.
> > 
> > We discussed a similar topic on the thread https://lkml.org/lkml/2011/3/18/212.
> > And, we added the memory.txt:
> > ---
> > 5.5 usage_in_bytes
> > 
> > For efficiency, as other kernel components, memory cgroup uses some optimization
> > to avoid unnecessary cacheline false sharing. usage_in_bytes is affected by the
> > method and doesn't show 'exact' value of memory(and swap) usage, it's an fuzz
> > value for efficient access. (Of course, when necessary, it's synchronized.)
> > If you want to know more exact memory usage, you should use RSS+CACHE(+SWAP)
> > value in memory.stat(see 5.2).
> > ---
> 
> Agree, thanks.
> 
> Should we have field 'ram' (or 'memory') for rss+cache in memory.stat?
> 

Why do you think so ?

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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] memcg: drain all stocks for the cgroup before read usage
  2011-09-08  0:19       ` KAMEZAWA Hiroyuki
@ 2011-09-08  0:49         ` Kirill A. Shutemov
  2011-09-08  9:21           ` KAMEZAWA Hiroyuki
  2011-09-08 10:09           ` Johannes Weiner
  0 siblings, 2 replies; 9+ messages in thread
From: Kirill A. Shutemov @ 2011-09-08  0:49 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki
  Cc: Daisuke Nishimura, Andrew Morton, Balbir Singh, linux-mm,
	linux-kernel

On Thu, Sep 08, 2011 at 09:19:14AM +0900, KAMEZAWA Hiroyuki wrote:
> > Should we have field 'ram' (or 'memory') for rss+cache in memory.stat?
> > 
> 
> Why do you think so ?

It may be useful for scripting purpose. Just an idea.

-- 
 Kirill A. Shutemov

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] memcg: drain all stocks for the cgroup before read usage
  2011-09-08  0:49         ` Kirill A. Shutemov
@ 2011-09-08  9:21           ` KAMEZAWA Hiroyuki
  2011-09-08 10:09           ` Johannes Weiner
  1 sibling, 0 replies; 9+ messages in thread
From: KAMEZAWA Hiroyuki @ 2011-09-08  9:21 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Daisuke Nishimura, Andrew Morton, Balbir Singh, linux-mm,
	linux-kernel

On Thu, 8 Sep 2011 03:49:07 +0300
"Kirill A. Shutemov" <kirill@shutemov.name> wrote:

> On Thu, Sep 08, 2011 at 09:19:14AM +0900, KAMEZAWA Hiroyuki wrote:
> > > Should we have field 'ram' (or 'memory') for rss+cache in memory.stat?
> > > 
> > 
> > Why do you think so ?
> 
> It may be useful for scripting purpose. Just an idea.
> 

Hmm, if you really want, please post a patch.
(in other thread)
I have no strong objection.

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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] memcg: drain all stocks for the cgroup before read usage
  2011-09-08  0:49         ` Kirill A. Shutemov
  2011-09-08  9:21           ` KAMEZAWA Hiroyuki
@ 2011-09-08 10:09           ` Johannes Weiner
  1 sibling, 0 replies; 9+ messages in thread
From: Johannes Weiner @ 2011-09-08 10:09 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: KAMEZAWA Hiroyuki, Daisuke Nishimura, Andrew Morton, Balbir Singh,
	linux-mm, linux-kernel

On Thu, Sep 08, 2011 at 03:49:07AM +0300, Kirill A. Shutemov wrote:
> On Thu, Sep 08, 2011 at 09:19:14AM +0900, KAMEZAWA Hiroyuki wrote:
> > > Should we have field 'ram' (or 'memory') for rss+cache in memory.stat?
> > 
> > Why do you think so ?
> 
> It may be useful for scripting purpose. Just an idea.

$ awk '/^cache/{mem+=$2} /^rss/{mem+=$2} END{print(mem)}' /sys/fs/cgroup/memory/memory.stat 
1904500736

Am I missing something here?

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-09-08 10:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-04  1:15 [PATCH] memcg: drain all stocks for the cgroup before read usage Kirill A. Shutemov
2011-09-04  7:20 ` Paul Menage
2011-09-04 23:59 ` KAMEZAWA Hiroyuki
2011-09-05  1:16   ` Daisuke Nishimura
2011-09-07 21:33     ` Kirill A. Shutemov
2011-09-08  0:19       ` KAMEZAWA Hiroyuki
2011-09-08  0:49         ` Kirill A. Shutemov
2011-09-08  9:21           ` KAMEZAWA Hiroyuki
2011-09-08 10:09           ` Johannes Weiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).