All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@develer.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Suleiman Souhlal <suleiman@google.com>,
	Vivek Goyal <vgoyal@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	containers@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] memcg: dirty pages instrumentation
Date: Tue, 23 Feb 2010 10:46:58 +0100	[thread overview]
Message-ID: <20100223094658.GE1882@linux> (raw)
In-Reply-To: <1266862809.6122.436.camel@laptop>

On Mon, Feb 22, 2010 at 07:20:09PM +0100, Peter Zijlstra wrote:
> On Sun, 2010-02-21 at 16:18 +0100, Andrea Righi wrote:
> > @@ -137,10 +137,11 @@ static struct prop_descriptor vm_dirties;
> >   */
> >  static int calc_period_shift(void)
> >  {
> > -       unsigned long dirty_total;
> > +       unsigned long dirty_total, dirty_bytes;
> >  
> > -       if (vm_dirty_bytes)
> > -               dirty_total = vm_dirty_bytes / PAGE_SIZE;
> > +       dirty_bytes = mem_cgroup_dirty_bytes();
> > +       if (dirty_bytes)
> > +               dirty_total = dirty_bytes / PAGE_SIZE;
> >         else
> >                 dirty_total = (vm_dirty_ratio * determine_dirtyable_memory()) /
> >                                 100;
> > @@ -406,14 +407,20 @@ static unsigned long highmem_dirtyable_memory(unsigned long total)
> >   */
> >  unsigned long determine_dirtyable_memory(void)
> >  {
> > -       unsigned long x;
> > -
> > -       x = global_page_state(NR_FREE_PAGES) + global_reclaimable_pages();
> > -
> > +       unsigned long memcg_memory, memory;
> > +
> > +       memory = global_page_state(NR_FREE_PAGES) + global_reclaimable_pages();
> > +       memcg_memory = mem_cgroup_page_state(MEMCG_NR_FREE_PAGES);
> > +       if (memcg_memory > 0) {
> > +               memcg_memory +=
> > +                       mem_cgroup_page_state(MEMCG_NR_RECLAIMABLE_PAGES);
> > +               if (memcg_memory < memory)
> > +                       return memcg_memory;
> > +       }
> >         if (!vm_highmem_is_dirtyable)
> > -               x -= highmem_dirtyable_memory(x);
> > +               memory -= highmem_dirtyable_memory(memory);
> >  
> > -       return x + 1;   /* Ensure that we never return 0 */
> > +       return memory + 1;      /* Ensure that we never return 0 */
> >  }
> >  
> >  void
> > @@ -421,12 +428,13 @@ get_dirty_limits(unsigned long *pbackground, unsigned long *pdirty,
> >                  unsigned long *pbdi_dirty, struct backing_dev_info *bdi)
> >  {
> >         unsigned long background;
> > -       unsigned long dirty;
> > +       unsigned long dirty, dirty_bytes;
> >         unsigned long available_memory = determine_dirtyable_memory();
> >         struct task_struct *tsk;
> >  
> > -       if (vm_dirty_bytes)
> > -               dirty = DIV_ROUND_UP(vm_dirty_bytes, PAGE_SIZE);
> > +       dirty_bytes = mem_cgroup_dirty_bytes();
> > +       if (dirty_bytes)
> > +               dirty = DIV_ROUND_UP(dirty_bytes, PAGE_SIZE);
> >         else {
> >                 int dirty_ratio;
> >  
> > @@ -505,9 +513,17 @@ static void balance_dirty_pages(struct address_space *mapping,
> >                 get_dirty_limits(&background_thresh, &dirty_thresh,
> >                                 &bdi_thresh, bdi);
> >  
> > -               nr_reclaimable = global_page_state(NR_FILE_DIRTY) +
> > +               nr_reclaimable = mem_cgroup_page_state(MEMCG_NR_FILE_DIRTY);
> > +               if (nr_reclaimable == 0) {
> > +                       nr_reclaimable = global_page_state(NR_FILE_DIRTY) +
> >                                         global_page_state(NR_UNSTABLE_NFS);
> > -               nr_writeback = global_page_state(NR_WRITEBACK);
> > +                       nr_writeback = global_page_state(NR_WRITEBACK);
> > +               } else {
> > +                       nr_reclaimable +=
> > +                               mem_cgroup_page_state(MEMCG_NR_UNSTABLE_NFS);
> > +                       nr_writeback =
> > +                               mem_cgroup_page_state(MEMCG_NR_WRITEBACK);
> > +               }
> >  
> >                 bdi_nr_reclaimable = bdi_stat(bdi, BDI_RECLAIMABLE);
> >                 bdi_nr_writeback = bdi_stat(bdi, BDI_WRITEBACK);
> > @@ -660,6 +676,8 @@ void throttle_vm_writeout(gfp_t gfp_mask)
> >         unsigned long dirty_thresh;
> >  
> >          for ( ; ; ) {
> > +               unsigned long dirty;
> > +
> >                 get_dirty_limits(&background_thresh, &dirty_thresh, NULL, NULL);
> >  
> >                  /*
> > @@ -668,10 +686,15 @@ void throttle_vm_writeout(gfp_t gfp_mask)
> >                   */
> >                  dirty_thresh += dirty_thresh / 10;      /* wheeee... */
> >  
> > -                if (global_page_state(NR_UNSTABLE_NFS) +
> > -                       global_page_state(NR_WRITEBACK) <= dirty_thresh)
> > -                               break;
> > -                congestion_wait(BLK_RW_ASYNC, HZ/10);
> > +               dirty = mem_cgroup_page_state(MEMCG_NR_WRITEBACK);
> > +               if (dirty < 0)
> > +                       dirty = global_page_state(NR_UNSTABLE_NFS) +
> > +                               global_page_state(NR_WRITEBACK);
> > +               else
> > +                       dirty += mem_cgroup_page_state(MEMCG_NR_UNSTABLE_NFS);
> > +               if (dirty <= dirty_thresh)
> > +                       break;
> > +               congestion_wait(BLK_RW_ASYNC, HZ/10);
> >  
> >                 /*
> >                  * The caller might hold locks which can prevent IO completion 
> 
> 
> This stuff looks really rather horrible, 
> 
> Relying on these cgroup functions returning 0 seems fragile, some of
> them can really be 0. Also sprinkling all that if cgroup foo all over
> the place leads to these ugly indentation problems you have.
> 
> How about pulling all these things into separate functions, and using a
> proper mem_cgroup_has_dirty() function to select on?

Agreed. Will do in the next version of the patch.

Thanks,
-Andrea

  parent reply	other threads:[~2010-02-23  9:47 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-21 15:18 [RFC] [PATCH 0/2] memcg: per cgroup dirty limit Andrea Righi
2010-02-21 15:18 ` [PATCH 1/2] memcg: dirty pages accounting and limiting infrastructure Andrea Righi
2010-02-21 21:28   ` David Rientjes
2010-02-21 22:17     ` Andrea Righi
2010-02-22 18:07       ` Vivek Goyal
     [not found]         ` <20100222180732.GC3096-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-23 11:58           ` Andrea Righi
2010-02-23 11:58             ` Andrea Righi
2010-02-25 15:36             ` Minchan Kim
     [not found]               ` <28c262361002250736k57543379j8291e0dfb8df194e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-26  0:23                 ` KAMEZAWA Hiroyuki
2010-02-26  0:23               ` KAMEZAWA Hiroyuki
     [not found]                 ` <20100226092339.1f639cbf.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2010-02-26  4:50                   ` Minchan Kim
2010-02-26  4:50                 ` Minchan Kim
2010-02-26  5:01                   ` KAMEZAWA Hiroyuki
2010-02-26  5:53                     ` Minchan Kim
2010-02-26  6:15                       ` KAMEZAWA Hiroyuki
2010-02-26  6:35                         ` Minchan Kim
     [not found]                         ` <20100226151506.c78b4312.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2010-02-26  6:35                           ` Minchan Kim
     [not found]                       ` <28c262361002252153s587b70ecxf89eda9a642e527c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-26  6:15                         ` KAMEZAWA Hiroyuki
     [not found]                     ` <20100226140135.23c32a8d.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2010-02-26  5:53                       ` Minchan Kim
     [not found]                   ` <28c262361002252050r29f54ea2u6c6e87f1f702d195-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-26  5:01                     ` KAMEZAWA Hiroyuki
2010-02-25 15:36             ` Minchan Kim
2010-02-22 18:07       ` Vivek Goyal
2010-02-22  0:22   ` KAMEZAWA Hiroyuki
2010-02-22 18:00     ` Andrea Righi
2010-02-22 21:21       ` David Rientjes
2010-02-22 21:21       ` David Rientjes
     [not found]     ` <20100222092242.98df82e4.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2010-02-22 18:00       ` Andrea Righi
2010-02-22 19:31     ` Vivek Goyal
     [not found]       ` <20100222193113.GE3096-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-23  9:58         ` Andrea Righi
2010-02-23  9:58       ` Andrea Righi
2010-02-22 15:58   ` Vivek Goyal
2010-02-22 17:29     ` Balbir Singh
     [not found]     ` <20100222155840.GC13823-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-22 17:29       ` Balbir Singh
2010-02-23  9:26       ` Andrea Righi
2010-02-23  9:26     ` Andrea Righi
     [not found]   ` <1266765525-30890-2-git-send-email-arighi-vWjgImWzx8FBDgjK7y7TUQ@public.gmane.org>
2010-02-22  0:22     ` KAMEZAWA Hiroyuki
2010-02-22 15:58     ` Vivek Goyal
2010-02-22 16:14     ` Balbir Singh
2010-02-22 16:14   ` Balbir Singh
2010-02-23  9:28     ` Andrea Righi
2010-02-24  0:09       ` KAMEZAWA Hiroyuki
2010-02-24  0:09       ` KAMEZAWA Hiroyuki
     [not found]     ` <20100222161442.GE3063-SINUvgVNF2CyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2010-02-23  9:28       ` Andrea Righi
2010-02-21 15:18 ` [PATCH 2/2] memcg: dirty pages instrumentation Andrea Righi
2010-02-21 21:38   ` David Rientjes
2010-02-21 22:33     ` Andrea Righi
2010-02-22  0:32   ` KAMEZAWA Hiroyuki
     [not found]     ` <20100222093221.eaaff1b4.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2010-02-22 17:57       ` Andrea Righi
2010-02-22 17:57     ` Andrea Righi
2010-02-22 16:52   ` Vivek Goyal
2010-02-23  9:40     ` Andrea Righi
2010-02-23  9:45       ` Andrea Righi
2010-02-23  9:45       ` Andrea Righi
2010-02-23 19:56       ` Vivek Goyal
2010-02-23 22:22         ` David Rientjes
2010-02-25 14:34           ` Andrea Righi
2010-02-26  0:14             ` KAMEZAWA Hiroyuki
2010-02-26  0:14             ` KAMEZAWA Hiroyuki
     [not found]           ` <alpine.DEB.2.00.1002231419450.8693-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2010-02-25 14:34             ` Andrea Righi
     [not found]         ` <20100223195606.GD11930-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-23 22:22           ` David Rientjes
2010-02-23 19:56       ` Vivek Goyal
     [not found]     ` <20100222165215.GA3096-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-23  9:40       ` Andrea Righi
     [not found]   ` <1266765525-30890-3-git-send-email-arighi-vWjgImWzx8FBDgjK7y7TUQ@public.gmane.org>
2010-02-22  0:32     ` KAMEZAWA Hiroyuki
2010-02-22 16:52     ` Vivek Goyal
2010-02-22 18:20     ` Peter Zijlstra
2010-02-23 21:29     ` Vivek Goyal
2010-02-22 18:20   ` Peter Zijlstra
2010-02-23  9:46     ` Andrea Righi
2010-02-23  9:46     ` Andrea Righi [this message]
2010-02-23 21:29   ` Vivek Goyal
     [not found]     ` <20100223212943.GF11930-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-25 15:12       ` Andrea Righi
2010-02-25 15:12     ` Andrea Righi
2010-02-26 21:48       ` Vivek Goyal
2010-02-26 22:21         ` Andrea Righi
2010-02-26 22:28           ` Vivek Goyal
2010-02-26 22:28           ` Vivek Goyal
     [not found]         ` <20100226214811.GB7498-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-26 22:21           ` Andrea Righi
2010-03-01  0:47           ` KAMEZAWA Hiroyuki
2010-03-01  0:47         ` KAMEZAWA Hiroyuki
2010-02-26 21:48       ` Vivek Goyal
2010-02-22 14:27 ` [RFC] [PATCH 0/2] memcg: per cgroup dirty limit Vivek Goyal
2010-02-22 17:36   ` Balbir Singh
     [not found]     ` <20100222173640.GG3063-SINUvgVNF2CyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2010-02-22 17:58       ` Vivek Goyal
2010-02-22 17:58     ` Vivek Goyal
2010-02-23  0:07       ` KAMEZAWA Hiroyuki
     [not found]         ` <20100223090704.839d8bef.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2010-02-23 15:12           ` Vivek Goyal
2010-02-23 15:12         ` Vivek Goyal
     [not found]           ` <20100223151201.GB11930-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-24  0:19             ` KAMEZAWA Hiroyuki
2010-02-24  0:19           ` KAMEZAWA Hiroyuki
     [not found]       ` <20100222175833.GB3096-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-23  0:07         ` KAMEZAWA Hiroyuki
     [not found]   ` <20100222142744.GB13823-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-22 17:36     ` Balbir Singh
2010-02-22 18:12     ` Andrea Righi
2010-02-22 18:12   ` Andrea Righi
2010-02-22 18:29     ` Vivek Goyal
2010-02-22 21:15       ` David Rientjes
2010-02-23  9:55       ` Andrea Righi
2010-02-23 20:01         ` Vivek Goyal
2010-02-23 20:01         ` Vivek Goyal
     [not found]       ` <20100222182934.GD3096-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-02-22 21:15         ` David Rientjes
2010-02-23  9:55         ` Andrea Righi
2010-02-22 18:29     ` Vivek Goyal
     [not found] ` <1266765525-30890-1-git-send-email-arighi-vWjgImWzx8FBDgjK7y7TUQ@public.gmane.org>
2010-02-21 23:48   ` KAMEZAWA Hiroyuki
2010-02-21 23:48     ` KAMEZAWA Hiroyuki
2010-02-22 14:27   ` Vivek Goyal

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=20100223094658.GE1882@linux \
    --to=arighi@develer.com \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=suleiman@google.com \
    --cc=vgoyal@redhat.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 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.