linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sha Zhengju <handai.szj@gmail.com>
To: Michal Hocko <mhocko@suse.cz>
Cc: linux-fsdevel@vger.kernel.org,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	Cgroups <cgroups@vger.kernel.org>,
	Greg Thelen <gthelen@google.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Wu Fengguang <fengguang.wu@intel.com>,
	Mel Gorman <mgorman@suse.de>, Sha Zhengju <handai.szj@taobao.com>
Subject: Re: [PATCH V4 3/6] memcg: add per cgroup dirty pages accounting
Date: Fri, 12 Jul 2013 00:49:50 +0800	[thread overview]
Message-ID: <CAFj3OHWq87TK1_T3gPEORfPdoDkosA55La+W=W5C920Xi9Cs0A@mail.gmail.com> (raw)
In-Reply-To: <20130711143120.GI21667@dhcp22.suse.cz>

On Thu, Jul 11, 2013 at 10:31 PM, Michal Hocko <mhocko@suse.cz> wrote:
> Please also CC vfs people
>
> On Sat 06-07-13 01:30:09, Sha Zhengju wrote:
>> From: Sha Zhengju <handai.szj@taobao.com>
>>
>> This patch adds memcg routines to count dirty pages, which allows memory controller
>> to maintain an accurate view of the amount of its dirty memory.
>>
>> After Kame's commit 89c06bd5(memcg: use new logic for page stat accounting), we can
>> use 'struct page' flag to test page state instead of per page_cgroup flag. But memcg
>> has a feature to move a page from a cgroup to another one and may have race between
>> "move" and "page stat accounting". So in order to avoid the race we have designed a
>> bigger lock:
>
> Well, bigger lock is little bit an overstatement ;). It is full no-op for
> !CONFIG_MEMCG, almost no-op if memcg is disabled (but compiled in), rcu
> read lock in the most cases (no task is moving) and spin_lock_irqsave on
> top in the slow path.
>
> It would be good to mention this in the changelog for those who are not
> familiar.

Okay, good advise.

>
>>
>>          mem_cgroup_begin_update_page_stat()
>>          modify page information        -->(a)
>>          mem_cgroup_update_page_stat()  -->(b)
>
> Hmm, mem_cgroup_update_page_stat doesn't do any checking that we use a
> proper locking. Which would be hard but we could at least test for
> rcu_read_lock_held() because RCU is held if !mem_cgroup_disabled().
> This would be a nice preparatory patch. What do you think?

In patch 5/6 I've used static branch to patch out most of
mem_cgroup_begin/end_update_page_stat() including
rcu_read_lock/unlock, so the test may be false in that case. Well,
since I still need to think it over according to your opinion, it's
not bad to add the check patch next round.

>
>>          mem_cgroup_end_update_page_stat()
>> It requires both (a) and (b)(dirty pages accounting) to be pretected in
>> mem_cgroup_{begin/end}_update_page_stat().
>>
>> Server places should be added accounting:
>
> Server?

Oops.. I mean 'several'.....

>
>>         incrementing (3):
>>                 __set_page_dirty_buffers
>>                 __set_page_dirty_nobuffers
>>               mark_buffer_dirty
>>         decrementing (5):
>>                 clear_page_dirty_for_io
>>                 cancel_dirty_page
>>               delete_from_page_cache
>>               __delete_from_page_cache
>>               replace_page_cache_page
>>
>> The lock order between memcg lock and mapping lock is:
>>       --> memcg->move_lock
>>         --> mapping->private_lock
>>             --> mapping->tree_lock
>>
>> Signed-off-by: Sha Zhengju <handai.szj@taobao.com>
>> cc: Michal Hocko <mhocko@suse.cz>
>> cc: Greg Thelen <gthelen@google.com>
>> cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>> cc: Andrew Morton <akpm@linux-foundation.org>
>> cc: Fengguang Wu <fengguang.wu@intel.com>
>> cc: Mel Gorman <mgorman@suse.de>
>> ---
>>  fs/buffer.c                |    9 +++++++++
>>  include/linux/memcontrol.h |    1 +
>>  mm/filemap.c               |   14 ++++++++++++++
>>  mm/memcontrol.c            |   30 +++++++++++++++++++++++-------
>>  mm/page-writeback.c        |   24 ++++++++++++++++++++++--
>>  mm/truncate.c              |    6 ++++++
>>  6 files changed, 75 insertions(+), 9 deletions(-)
>>
>> diff --git a/fs/buffer.c b/fs/buffer.c
>> index 695eb14..7c537f4 100644
>> --- a/fs/buffer.c
>> +++ b/fs/buffer.c
>> @@ -694,10 +694,13 @@ int __set_page_dirty_buffers(struct page *page)
>>  {
>>       int newly_dirty;
>>       struct address_space *mapping = page_mapping(page);
>> +     bool locked;
>> +     unsigned long flags;
>>
>>       if (unlikely(!mapping))
>>               return !TestSetPageDirty(page);
>
> I guess it would be worth mentioning why we do not care about pages
> without mapping.

Actually what I concern is where both doing 'TestSetPageDirty' and
'account_pages_dirtied'. Since it doesn't do global counting here, I
also needn't do so.

>
>> +     mem_cgroup_begin_update_page_stat(page, &locked, &flags);
>>       spin_lock(&mapping->private_lock);
>>       if (page_has_buffers(page)) {
>>               struct buffer_head *head = page_buffers(page);
> [...]
>> diff --git a/mm/filemap.c b/mm/filemap.c
>> index 4b51ac1..5642de6 100644
>> --- a/mm/filemap.c
>> +++ b/mm/filemap.c
> [...]
>> @@ -144,6 +149,7 @@ void __delete_from_page_cache(struct page *page)
>
> This needs a comment that it has to be called from within
> mem_cgroup_{begin,end}_update_page_stat context. Btw. it seems that you
> are missing invalidate_complete_page2 and __remove_mapping

Sorry, yes, I'll add them next.

>
>>        * having removed the page entirely.
>>        */
>>       if (PageDirty(page) && mapping_cap_account_dirty(mapping)) {
>> +             mem_cgroup_dec_page_stat(page, MEM_CGROUP_STAT_FILE_DIRTY);
>>               dec_zone_page_state(page, NR_FILE_DIRTY);
>>               dec_bdi_stat(mapping->backing_dev_info, BDI_RECLAIMABLE);
>>       }
>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>> index f9acf49..1d31851 100644
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -91,6 +91,7 @@ static const char * const mem_cgroup_stat_names[] = {
>>       "rss_huge",
>>       "mapped_file",
>>       "swap",
>> +     "dirty",
>
> This doesn't match mem_cgroup_stat_index ordering.

Yes... I should be more careful. :(

>
>>  };
>>
>>  enum mem_cgroup_events_index {
> [...]
>> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
>> index 4514ad7..3900e62 100644
>> --- a/mm/page-writeback.c
>> +++ b/mm/page-writeback.c
>> @@ -1982,6 +1982,11 @@ int __set_page_dirty_no_writeback(struct page *page)
>>
>>  /*
>>   * Helper function for set_page_dirty family.
>> + *
>> + * The caller must hold mem_cgroup_begin/end_update_page_stat() lock
>> + * while modifying struct page state and accounting dirty pages.
>
> I think "while calling this function" would be sufficient.

Okay.
Thanks for reviewing!

>
>> + * See __set_page_dirty_{nobuffers,buffers} for example.
>> + *
>>   * NOTE: This relies on being atomic wrt interrupts.
>>   */
>>  void account_page_dirtied(struct page *page, struct address_space *mapping)
> [...]
>
> Thanks
> --
> Michal Hocko
> SUSE Labs



--
Thanks,
Sha

--
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:[~2013-07-11 16:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-05 17:18 [PATCH V4 0/6] Memcg dirty/writeback page accounting Sha Zhengju
2013-07-05 17:21 ` [PATCH V4 1/6] memcg: remove MEMCG_NR_FILE_MAPPED Sha Zhengju
2013-07-11 13:39   ` Michal Hocko
2013-07-11 15:53     ` Sha Zhengju
2013-07-05 17:26 ` [PATCH V4 2/6] fs/ceph: vfs __set_page_dirty_nobuffers interface instead of doing it inside filesystem Sha Zhengju
2013-07-05 17:30 ` [PATCH V4 3/6] memcg: add per cgroup dirty pages accounting Sha Zhengju
2013-07-11 14:31   ` Michal Hocko
2013-07-11 16:49     ` Sha Zhengju [this message]
2013-07-05 17:32 ` [PATCH V4 4/6] memcg: add per cgroup writeback " Sha Zhengju
2013-07-11 14:40   ` Michal Hocko
2013-07-11 16:56     ` Sha Zhengju
2013-07-05 17:33 ` [PATCH V4 5/6] memcg: patch mem_cgroup_{begin,end}_update_page_stat() out if only root memcg exists Sha Zhengju
2013-07-11 14:56   ` Michal Hocko
2013-07-12 12:59     ` Sha Zhengju
2013-07-12 13:13       ` Sha Zhengju
2013-07-15  6:32         ` Glauber Costa
2013-07-12 13:25       ` Michal Hocko
2013-07-13  4:15         ` Sha Zhengju
2013-07-15 17:58     ` Greg Thelen
2013-07-16  4:26       ` Sha Zhengju
2013-07-05 17:34 ` [PATCH V4 6/6] memcg: Document cgroup dirty/writeback memory statistics Sha Zhengju

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='CAFj3OHWq87TK1_T3gPEORfPdoDkosA55La+W=W5C920Xi9Cs0A@mail.gmail.com' \
    --to=handai.szj@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=fengguang.wu@intel.com \
    --cc=gthelen@google.com \
    --cc=handai.szj@taobao.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.cz \
    /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