linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@develer.com>
To: Greg Thelen <gthelen@google.com>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Suleiman Souhlal <suleiman@google.com>,
	Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>,
	"Kirill A. Shutemov" <kirill@shutemov.name>,
	Andrew Morton <akpm@linux-foundation.org>,
	containers@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH -mmotm 2/3] memcg: dirty pages accounting and limiting infrastructure
Date: Tue, 2 Mar 2010 23:24:55 +0100	[thread overview]
Message-ID: <20100302222455.GE2369@linux> (raw)
In-Reply-To: <49b004811003021008t4fae71bbu8d56192e48c32f39@mail.gmail.com>

On Tue, Mar 02, 2010 at 10:08:17AM -0800, Greg Thelen wrote:
> Comments below.  Yet to be tested on my end, but I will test it.
> 
> On Mon, Mar 1, 2010 at 1:23 PM, Andrea Righi <arighi@develer.com> wrote:
> > Infrastructure to account dirty pages per cgroup and add dirty limit
> > interfaces in the cgroupfs:
> >
> >  - Direct write-out: memory.dirty_ratio, memory.dirty_bytes
> >
> >  - Background write-out: memory.dirty_background_ratio, memory.dirty_background_bytes
> >
> > Signed-off-by: Andrea Righi <arighi@develer.com>
> > ---
> >  include/linux/memcontrol.h |   77 ++++++++++-
> >  mm/memcontrol.c            |  336 ++++++++++++++++++++++++++++++++++++++++----
> >  2 files changed, 384 insertions(+), 29 deletions(-)
> >
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index 1f9b119..cc88b2e 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -19,12 +19,50 @@
> >
> >  #ifndef _LINUX_MEMCONTROL_H
> >  #define _LINUX_MEMCONTROL_H
> > +
> > +#include <linux/writeback.h>
> >  #include <linux/cgroup.h>
> > +
> >  struct mem_cgroup;
> >  struct page_cgroup;
> >  struct page;
> >  struct mm_struct;
> >
> > +/* Cgroup memory statistics items exported to the kernel */
> > +enum mem_cgroup_page_stat_item {
> > +       MEMCG_NR_DIRTYABLE_PAGES,
> > +       MEMCG_NR_RECLAIM_PAGES,
> > +       MEMCG_NR_WRITEBACK,
> > +       MEMCG_NR_DIRTY_WRITEBACK_PAGES,
> > +};
> > +
> > +/*
> > + * Statistics for memory cgroup.
> > + */
> > +enum mem_cgroup_stat_index {
> > +       /*
> > +        * For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss.
> > +        */
> > +       MEM_CGROUP_STAT_CACHE,     /* # of pages charged as cache */
> > +       MEM_CGROUP_STAT_RSS,       /* # of pages charged as anon rss */
> > +       MEM_CGROUP_STAT_FILE_MAPPED,  /* # of pages charged as file rss */
> > +       MEM_CGROUP_STAT_PGPGIN_COUNT,   /* # of pages paged in */
> > +       MEM_CGROUP_STAT_PGPGOUT_COUNT,  /* # of pages paged out */
> > +       MEM_CGROUP_STAT_EVENTS, /* sum of pagein + pageout for internal use */
> > +       MEM_CGROUP_STAT_SWAPOUT, /* # of pages, swapped out */
> > +       MEM_CGROUP_STAT_SOFTLIMIT, /* decrements on each page in/out.
> > +                                       used by soft limit implementation */
> > +       MEM_CGROUP_STAT_THRESHOLDS, /* decrements on each page in/out.
> > +                                       used by threshold implementation */
> > +       MEM_CGROUP_STAT_FILE_DIRTY,   /* # of dirty pages in page cache */
> > +       MEM_CGROUP_STAT_WRITEBACK,   /* # of pages under writeback */
> > +       MEM_CGROUP_STAT_WRITEBACK_TEMP,   /* # of pages under writeback using
> > +                                               temporary buffers */
> > +       MEM_CGROUP_STAT_UNSTABLE_NFS,   /* # of NFS unstable pages */
> > +
> > +       MEM_CGROUP_STAT_NSTATS,
> > +};
> > +
> >  #ifdef CONFIG_CGROUP_MEM_RES_CTLR
> >  /*
> >  * All "charge" functions with gfp_mask should use GFP_KERNEL or
> > @@ -117,6 +155,13 @@ extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
> >  extern int do_swap_account;
> >  #endif
> >
> > +extern long mem_cgroup_dirty_ratio(void);
> > +extern unsigned long mem_cgroup_dirty_bytes(void);
> > +extern long mem_cgroup_dirty_background_ratio(void);
> > +extern unsigned long mem_cgroup_dirty_background_bytes(void);
> > +
> > +extern s64 mem_cgroup_page_stat(enum mem_cgroup_page_stat_item item);
> > +
> >  static inline bool mem_cgroup_disabled(void)
> >  {
> >        if (mem_cgroup_subsys.disabled)
> > @@ -125,7 +170,8 @@ static inline bool mem_cgroup_disabled(void)
> >  }
> >
> >  extern bool mem_cgroup_oom_called(struct task_struct *task);
> > -void mem_cgroup_update_file_mapped(struct page *page, int val);
> > +void mem_cgroup_update_stat(struct page *page,
> > +                       enum mem_cgroup_stat_index idx, int val);
> >  unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
> >                                                gfp_t gfp_mask, int nid,
> >                                                int zid);
> > @@ -300,8 +346,8 @@ mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
> >  {
> >  }
> >
> > -static inline void mem_cgroup_update_file_mapped(struct page *page,
> > -                                                       int val)
> > +static inline void mem_cgroup_update_stat(struct page *page,
> > +                       enum mem_cgroup_stat_index idx, int val)
> >  {
> >  }
> >
> > @@ -312,6 +358,31 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
> >        return 0;
> >  }
> >
> > +static inline long mem_cgroup_dirty_ratio(void)
> > +{
> > +       return vm_dirty_ratio;
> > +}
> > +
> > +static inline unsigned long mem_cgroup_dirty_bytes(void)
> > +{
> > +       return vm_dirty_bytes;
> > +}
> > +
> > +static inline long mem_cgroup_dirty_background_ratio(void)
> > +{
> > +       return dirty_background_ratio;
> > +}
> > +
> > +static inline unsigned long mem_cgroup_dirty_background_bytes(void)
> > +{
> > +       return dirty_background_bytes;
> > +}
> > +
> > +static inline s64 mem_cgroup_page_stat(enum mem_cgroup_page_stat_item item)
> > +{
> > +       return -ENOMEM;
> > +}
> > +
> >  #endif /* CONFIG_CGROUP_MEM_CONT */
> >
> >  #endif /* _LINUX_MEMCONTROL_H */
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index a443c30..e74cf66 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -66,31 +66,16 @@ static int really_do_swap_account __initdata = 1; /* for remember boot option*/
> >  #define SOFTLIMIT_EVENTS_THRESH (1000)
> >  #define THRESHOLDS_EVENTS_THRESH (100)
> >
> > -/*
> > - * Statistics for memory cgroup.
> > - */
> > -enum mem_cgroup_stat_index {
> > -       /*
> > -        * For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss.
> > -        */
> > -       MEM_CGROUP_STAT_CACHE,     /* # of pages charged as cache */
> > -       MEM_CGROUP_STAT_RSS,       /* # of pages charged as anon rss */
> > -       MEM_CGROUP_STAT_FILE_MAPPED,  /* # of pages charged as file rss */
> > -       MEM_CGROUP_STAT_PGPGIN_COUNT,   /* # of pages paged in */
> > -       MEM_CGROUP_STAT_PGPGOUT_COUNT,  /* # of pages paged out */
> > -       MEM_CGROUP_STAT_SWAPOUT, /* # of pages, swapped out */
> > -       MEM_CGROUP_STAT_SOFTLIMIT, /* decrements on each page in/out.
> > -                                       used by soft limit implementation */
> > -       MEM_CGROUP_STAT_THRESHOLDS, /* decrements on each page in/out.
> > -                                       used by threshold implementation */
> > -
> > -       MEM_CGROUP_STAT_NSTATS,
> > -};
> > -
> >  struct mem_cgroup_stat_cpu {
> >        s64 count[MEM_CGROUP_STAT_NSTATS];
> >  };
> >
> > +/* Per cgroup page statistics */
> > +struct mem_cgroup_page_stat {
> > +       enum mem_cgroup_page_stat_item item;
> > +       s64 value;
> > +};
> > +
> >  /*
> >  * per-zone information in memory controller.
> >  */
> > @@ -157,6 +142,15 @@ struct mem_cgroup_threshold_ary {
> >  static bool mem_cgroup_threshold_check(struct mem_cgroup *mem);
> >  static void mem_cgroup_threshold(struct mem_cgroup *mem);
> >
> > +enum mem_cgroup_dirty_param {
> > +       MEM_CGROUP_DIRTY_RATIO,
> > +       MEM_CGROUP_DIRTY_BYTES,
> > +       MEM_CGROUP_DIRTY_BACKGROUND_RATIO,
> > +       MEM_CGROUP_DIRTY_BACKGROUND_BYTES,
> > +
> > +       MEM_CGROUP_DIRTY_NPARAMS,
> > +};
> > +
> >  /*
> >  * The memory controller data structure. The memory controller controls both
> >  * page cache and RSS per cgroup. We would eventually like to provide
> > @@ -205,6 +199,9 @@ struct mem_cgroup {
> >
> >        unsigned int    swappiness;
> >
> > +       /* control memory cgroup dirty pages */
> > +       unsigned long dirty_param[MEM_CGROUP_DIRTY_NPARAMS];
> > +
> >        /* set when res.limit == memsw.limit */
> >        bool            memsw_is_minimum;
> >
> > @@ -1021,6 +1018,164 @@ static unsigned int get_swappiness(struct mem_cgroup *memcg)
> >        return swappiness;
> >  }
> >
> > +static unsigned long get_dirty_param(struct mem_cgroup *memcg,
> > +                       enum mem_cgroup_dirty_param idx)
> > +{
> > +       unsigned long ret;
> > +
> > +       VM_BUG_ON(idx >= MEM_CGROUP_DIRTY_NPARAMS);
> > +       spin_lock(&memcg->reclaim_param_lock);
> > +       ret = memcg->dirty_param[idx];
> > +       spin_unlock(&memcg->reclaim_param_lock);
> > +
> > +       return ret;
> > +}
> > +
> 
> > +long mem_cgroup_dirty_ratio(void)
> > +{
> > +       struct mem_cgroup *memcg;
> > +       long ret = vm_dirty_ratio;
> > +
> > +       if (mem_cgroup_disabled())
> > +               return ret;
> > +       /*
> > +        * It's possible that "current" may be moved to other cgroup while we
> > +        * access cgroup. But precise check is meaningless because the task can
> > +        * be moved after our access and writeback tends to take long time.
> > +        * At least, "memcg" will not be freed under rcu_read_lock().
> > +        */
> > +       rcu_read_lock();
> > +       memcg = mem_cgroup_from_task(current);
> > +       if (likely(memcg))
> > +               ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_RATIO);
> > +       rcu_read_unlock();
> > +
> > +       return ret;
> > +}
> > +
> > +unsigned long mem_cgroup_dirty_bytes(void)
> > +{
> > +       struct mem_cgroup *memcg;
> > +       unsigned long ret = vm_dirty_bytes;
> > +
> > +       if (mem_cgroup_disabled())
> > +               return ret;
> > +       rcu_read_lock();
> > +       memcg = mem_cgroup_from_task(current);
> > +       if (likely(memcg))
> > +               ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_BYTES);
> > +       rcu_read_unlock();
> > +
> > +       return ret;
> > +}
> > +
> > +long mem_cgroup_dirty_background_ratio(void)
> > +{
> > +       struct mem_cgroup *memcg;
> > +       long ret = dirty_background_ratio;
> > +
> > +       if (mem_cgroup_disabled())
> > +               return ret;
> > +       rcu_read_lock();
> > +       memcg = mem_cgroup_from_task(current);
> > +       if (likely(memcg))
> > +               ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_BACKGROUND_RATIO);
> > +       rcu_read_unlock();
> > +
> > +       return ret;
> > +}
> > +
> > +unsigned long mem_cgroup_dirty_background_bytes(void)
> > +{
> > +       struct mem_cgroup *memcg;
> > +       unsigned long ret = dirty_background_bytes;
> > +
> > +       if (mem_cgroup_disabled())
> > +               return ret;
> > +       rcu_read_lock();
> > +       memcg = mem_cgroup_from_task(current);
> > +       if (likely(memcg))
> > +               ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_BACKGROUND_BYTES);
> > +       rcu_read_unlock();
> > +
> > +       return ret;
> > +}
> 
> Given that mem_cgroup_dirty_[background_]{ratio,bytes}() are similar,
> should we refactor the majority of them into a single routine?

Agreed.

Thanks,
-Andrea

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

  reply	other threads:[~2010-03-02 22:25 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-01 21:23 [PATCH -mmotm 0/3] memcg: per cgroup dirty limit (v3) Andrea Righi
2010-03-01 21:23 ` [PATCH -mmotm 1/3] memcg: dirty memory documentation Andrea Righi
2010-03-01 21:23 ` [PATCH -mmotm 2/3] memcg: dirty pages accounting and limiting infrastructure Andrea Righi
2010-03-02  0:20   ` KAMEZAWA Hiroyuki
2010-03-02 10:04   ` Kirill A. Shutemov
2010-03-02 11:00     ` Andrea Righi
2010-03-02 13:02   ` Balbir Singh
2010-03-02 21:50     ` Andrea Righi
2010-03-02 18:08   ` Greg Thelen
2010-03-02 22:24     ` Andrea Righi [this message]
2010-03-01 21:23 ` [PATCH -mmotm 3/3] memcg: dirty pages instrumentation Andrea Righi
2010-03-01 22:02   ` Vivek Goyal
2010-03-01 22:18     ` Andrea Righi
2010-03-02 15:05       ` Vivek Goyal
2010-03-02 22:22         ` Andrea Righi
2010-03-02 23:59           ` Vivek Goyal
2010-03-03 11:47             ` Andrea Righi
2010-03-03 11:56               ` Andrea Righi
2010-03-02  0:23   ` KAMEZAWA Hiroyuki
2010-03-02  8:01     ` Andrea Righi
2010-03-02  8:12       ` Daisuke Nishimura
2010-03-02  8:23       ` KAMEZAWA Hiroyuki
2010-03-02 13:50         ` Balbir Singh
2010-03-02 22:18           ` Andrea Righi
2010-03-02 23:21             ` Daisuke Nishimura
2010-03-03 11:48               ` Andrea Righi
2010-03-02 10:11   ` Kirill A. Shutemov
2010-03-02 11:02     ` Andrea Righi
2010-03-02 11:09       ` Kirill A. Shutemov
2010-03-02 11:34         ` Andrea Righi
2010-03-02 13:47   ` Balbir Singh
2010-03-02 13:56     ` Kirill A. Shutemov
2010-03-02 13:48   ` Peter Zijlstra
2010-03-02 15:26     ` Balbir Singh
2010-03-02 15:49     ` Trond Myklebust
2010-03-02 22:14     ` Andrea Righi
2010-03-03 10:07       ` Peter Zijlstra
2010-03-03 12:05         ` Andrea Righi
2010-03-03  2:12   ` Daisuke Nishimura
2010-03-03  3:29     ` KAMEZAWA Hiroyuki
2010-03-03  6:01       ` Daisuke Nishimura
2010-03-03  6:15         ` KAMEZAWA Hiroyuki
2010-03-03  8:21           ` KAMEZAWA Hiroyuki
2010-03-03 11:50             ` Andrea Righi
2010-03-03 22:03             ` Andrea Righi
2010-03-03 23:25               ` Daisuke Nishimura
2010-03-04  3:45               ` 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=20100302222455.GE2369@linux \
    --to=arighi@develer.com \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=gthelen@google.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nishimura@mxp.nes.nec.co.jp \
    --cc=suleiman@google.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).