linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ying Han <yinghan@google.com>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Minchan Kim <minchan.kim@gmail.com>,
	Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>,
	Balbir Singh <balbir@linux.vnet.ibm.com>,
	Tejun Heo <tj@kernel.org>, Pavel Emelyanov <xemul@openvz.org>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Li Zefan <lizf@cn.fujitsu.com>, Mel Gorman <mel@csn.ul.ie>,
	Christoph Lameter <cl@linux.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Rik van Riel <riel@redhat.com>, Hugh Dickins <hughd@google.com>,
	Michal Hocko <mhocko@suse.cz>,
	Dave Hansen <dave@linux.vnet.ibm.com>,
	Zhu Yanhai <zhu.yanhai@gmail.com>,
	linux-mm@kvack.org
Subject: Re: [PATCH] vmscan,memcg: memcg aware swap token
Date: Mon, 25 Apr 2011 10:13:25 -0700	[thread overview]
Message-ID: <BANLkTikCZpCZdLV7M_38MvnRYbZFS5zQGQ@mail.gmail.com> (raw)
In-Reply-To: <20110425112333.2662.A69D9226@jp.fujitsu.com>

On Sun, Apr 24, 2011 at 7:21 PM, KOSAKI Motohiro
<kosaki.motohiro@jp.fujitsu.com> wrote:
>> > > > > +             sc.priority = priority;
>> > > > > +             /* The swap token gets in the way of swapout... */
>> > > > > +             if (!priority)
>> > > > > +                     disable_swap_token();
>> > > >
>> > > > Why?
>> > > >
>> > > > disable swap token mean "Please devest swap preventation privilege from
>> > > > owner task. Instead we endure swap storm and performance hit".
>> > > > However I doublt memcg memory shortage is good situation to make swap
>> > > > storm.
>> > > >
>> > >
>> > > I am not sure about that either way. we probably can leave as it is and
>> > make
>> > > corresponding change if real problem is observed?
>> >
>> > Why?
>> > This is not only memcg issue, but also can lead to global swap ping-pong.
>> >
>> > But I give up. I have no time to persuade you.
>> >
>> > Thank you for pointing that out. I didn't pay much attention on the
>> swap_token but just simply inherited
>> it from the global logic. Now after reading a bit more, i think you were
>> right about it.  It would be a bad
>> idea to have memcg kswapds affecting much the global swap token being set.
>>
>> I will remove it from the next post.
>
> The better approach is swap-token recognize memcg and behave clever? :)

Ok, this makes sense for memcg case. Maybe I missed something on the
per-node balance_pgdat, where it seems it will blindly disable the
swap_token_mm if there is a one.

static inline int has_swap_token(struct mm_struct *mm)
{
>-------return (mm == swap_token_mm);
}

static inline void put_swap_token(struct mm_struct *mm)
{
>-------if (has_swap_token(mm))
>------->-------__put_swap_token(mm);
}

static inline void disable_swap_token(void)
{
>-------put_swap_token(swap_token_mm);
}


Should I include this patch into the per-memcg kswapd patset?

--Ying

>
>
>
> From 106c21d7f9cf8641592cbfe1416af66470af4f9a Mon Sep 17 00:00:00 2001
> From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Date: Mon, 25 Apr 2011 10:57:54 +0900
> Subject: [PATCH] vmscan,memcg: memcg aware swap token
>
> Currently, memcg reclaim can disable swap token even if the swap token
> mm doesn't belong in its memory cgroup. It's slightly riskly. If an
> admin makes very small mem-cgroup and silly guy runs contenious heavy
> memory pressure workloa, whole tasks in the system are going to lose
> swap-token and then system may become unresponsive. That's bad.
>
> This patch adds 'memcg' parameter into disable_swap_token(). and if
> the parameter doesn't match swap-token, VM doesn't put swap-token.
>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> ---
>  include/linux/memcontrol.h |    6 ++++++
>  include/linux/swap.h       |   24 +++++++++++++++++-------
>  mm/memcontrol.c            |    2 +-
>  mm/thrash.c                |   17 +++++++++++++++++
>  mm/vmscan.c                |    4 ++--
>  5 files changed, 43 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 6a0cffd..df572af 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -84,6 +84,7 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);
>
>  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
>  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
> +extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
>
>  static inline
>  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
> @@ -244,6 +245,11 @@ static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
>        return NULL;
>  }
>
> +static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
> +{
> +       return NULL;
> +}
> +
>  static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem)
>  {
>        return 1;
> diff --git a/include/linux/swap.h b/include/linux/swap.h
> index 384eb5f..ccea15d 100644
> --- a/include/linux/swap.h
> +++ b/include/linux/swap.h
> @@ -358,21 +358,31 @@ struct backing_dev_info;
>  extern struct mm_struct *swap_token_mm;
>  extern void grab_swap_token(struct mm_struct *);
>  extern void __put_swap_token(struct mm_struct *);
> +extern int has_swap_token_memcg(struct mm_struct *mm, struct mem_cgroup *memcg);
>
> -static inline int has_swap_token(struct mm_struct *mm)
> +static inline
> +int has_swap_token(struct mm_struct *mm)
>  {
> -       return (mm == swap_token_mm);
> +       return has_swap_token_memcg(mm, NULL);
>  }
>
> -static inline void put_swap_token(struct mm_struct *mm)
> +static inline
> +void put_swap_token_memcg(struct mm_struct *mm, struct mem_cgroup *memcg)
>  {
> -       if (has_swap_token(mm))
> +       if (has_swap_token_memcg(mm, memcg))
>                __put_swap_token(mm);
>  }
>
> -static inline void disable_swap_token(void)
> +static inline
> +void put_swap_token(struct mm_struct *mm)
> +{
> +       return put_swap_token_memcg(mm, NULL);
> +}
> +
> +static inline
> +void disable_swap_token(struct mem_cgroup *memcg)
>  {
> -       put_swap_token(swap_token_mm);
> +       put_swap_token_memcg(swap_token_mm, memcg);
>  }
>
>  #ifdef CONFIG_CGROUP_MEM_RES_CTLR
> @@ -500,7 +510,7 @@ static inline int has_swap_token(struct mm_struct *mm)
>        return 0;
>  }
>
> -static inline void disable_swap_token(void)
> +static inline void disable_swap_token(struct mem_cgroup *memcg)
>  {
>  }
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index c2776f1..5683c7a 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -735,7 +735,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
>                                struct mem_cgroup, css);
>  }
>
> -static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
> +struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
>  {
>        struct mem_cgroup *mem = NULL;
>
> diff --git a/mm/thrash.c b/mm/thrash.c
> index 2372d4e..f892a6e 100644
> --- a/mm/thrash.c
> +++ b/mm/thrash.c
> @@ -21,6 +21,7 @@
>  #include <linux/mm.h>
>  #include <linux/sched.h>
>  #include <linux/swap.h>
> +#include <linux/memcontrol.h>
>
>  static DEFINE_SPINLOCK(swap_token_lock);
>  struct mm_struct *swap_token_mm;
> @@ -75,3 +76,19 @@ void __put_swap_token(struct mm_struct *mm)
>                swap_token_mm = NULL;
>        spin_unlock(&swap_token_lock);
>  }
> +
> +int has_swap_token_memcg(struct mm_struct *mm, struct mem_cgroup *memcg)
> +{
> +       if (memcg) {
> +               struct mem_cgroup *swap_token_memcg;
> +
> +               /*
> +                * memcgroup reclaim can disable swap token only if token task
> +                * is in the same cgroup.
> +                */
> +               swap_token_memcg = try_get_mem_cgroup_from_mm(swap_token_mm);
> +               return ((mm == swap_token_mm) && (memcg == swap_token_memcg));
> +       } else
> +               return (mm == swap_token_mm);
> +}
> +
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index b3a569f..19e179b 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2044,7 +2044,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
>        for (priority = DEF_PRIORITY; priority >= 0; priority--) {
>                sc->nr_scanned = 0;
>                if (!priority)
> -                       disable_swap_token();
> +                       disable_swap_token(sc->mem_cgroup);
>                shrink_zones(priority, zonelist, sc);
>                /*
>                 * Don't shrink slabs when reclaiming memory from
> @@ -2353,7 +2353,7 @@ loop_again:
>
>                /* The swap token gets in the way of swapout... */
>                if (!priority)
> -                       disable_swap_token();
> +                       disable_swap_token(NULL);
>
>                all_zones_ok = 1;
>                balanced = 0;
> --
> 1.7.3.1
>
>
>
>

--
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>

  parent reply	other threads:[~2011-04-25 17:13 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-22  4:24 [RFC PATCH V7 0/9] memcg: per cgroup background reclaim Ying Han
2011-04-22  4:24 ` [PATCH V7 1/9] Add kswapd descriptor Ying Han
2011-04-22  4:31   ` KAMEZAWA Hiroyuki
2011-04-22  4:47   ` KOSAKI Motohiro
2011-04-22  5:55     ` Ying Han
2011-04-22  4:24 ` [PATCH V7 2/9] Add per memcg reclaim watermarks Ying Han
2011-04-22  4:24 ` [PATCH V7 3/9] New APIs to adjust per-memcg wmarks Ying Han
2011-04-22  4:32   ` KAMEZAWA Hiroyuki
2011-04-22  4:24 ` [PATCH V7 4/9] Add memcg kswapd thread pool Ying Han
2011-04-22  4:36   ` KAMEZAWA Hiroyuki
2011-04-22  4:49     ` Ying Han
2011-04-22  5:00       ` KAMEZAWA Hiroyuki
2011-04-22  5:53         ` Ying Han
2011-04-22  5:59           ` KAMEZAWA Hiroyuki
2011-04-22  6:10             ` Ying Han
2011-04-22  7:46               ` KAMEZAWA Hiroyuki
2011-04-22  7:59                 ` Ying Han
2011-04-22  8:02                   ` KAMEZAWA Hiroyuki
2011-04-24 23:26                   ` KAMEZAWA Hiroyuki
2011-04-25  2:08                     ` Ying Han
2011-04-22  6:02         ` Zhu Yanhai
2011-04-22  6:14           ` Ying Han
2011-04-22  5:39   ` KOSAKI Motohiro
2011-04-22  5:56     ` KAMEZAWA Hiroyuki
2011-04-22  4:24 ` [PATCH V7 5/9] Infrastructure to support per-memcg reclaim Ying Han
2011-04-22  4:38   ` KAMEZAWA Hiroyuki
2011-04-22  5:11   ` KOSAKI Motohiro
2011-04-22  5:59     ` Ying Han
2011-04-22  5:27   ` KOSAKI Motohiro
2011-04-22  6:00     ` Ying Han
2011-04-22  4:24 ` [PATCH V7 6/9] Implement the select_victim_node within memcg Ying Han
2011-04-22  4:39   ` KAMEZAWA Hiroyuki
2011-04-22  4:24 ` [PATCH V7 7/9] Per-memcg background reclaim Ying Han
2011-04-22  4:40   ` KAMEZAWA Hiroyuki
2011-04-22  6:00   ` KOSAKI Motohiro
2011-04-22  7:54     ` Ying Han
2011-04-22  8:44       ` KOSAKI Motohiro
2011-04-22 18:37         ` Ying Han
2011-04-25  2:21           ` [PATCH] vmscan,memcg: memcg aware swap token KOSAKI Motohiro
2011-04-25  9:47             ` KAMEZAWA Hiroyuki
2011-04-25 17:13             ` Ying Han [this message]
2011-04-26  2:08               ` KOSAKI Motohiro
2011-04-22  4:24 ` [PATCH V7 8/9] Add per-memcg zone "unreclaimable" Ying Han
2011-04-22  4:43   ` KAMEZAWA Hiroyuki
2011-04-22  6:13   ` KOSAKI Motohiro
2011-04-22  6:17     ` Ying Han
2011-04-22  4:24 ` [PATCH V7 9/9] Enable per-memcg background reclaim Ying Han
2011-04-22  4:44   ` KAMEZAWA Hiroyuki

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=BANLkTikCZpCZdLV7M_38MvnRYbZFS5zQGQ@mail.gmail.com \
    --to=yinghan@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=cl@linux.com \
    --cc=dave@linux.vnet.ibm.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mel@csn.ul.ie \
    --cc=mhocko@suse.cz \
    --cc=minchan.kim@gmail.com \
    --cc=nishimura@mxp.nes.nec.co.jp \
    --cc=riel@redhat.com \
    --cc=tj@kernel.org \
    --cc=xemul@openvz.org \
    --cc=zhu.yanhai@gmail.com \
    /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 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).