All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Liu <jeff.liu@oracle.com>
To: linux-mm@kvack.org
Cc: Michal Hocko <mhocko@suse.cz>,
	Glauber Costa <glommer@parallels.com>,
	cgroups@vger.kernel.org
Subject: [PATCH v2 3/6] memcg: introduce memsw_accounting_users
Date: Mon, 28 Jan 2013 18:54:40 +0800	[thread overview]
Message-ID: <510658F0.9050802@oracle.com> (raw)

As we don't account the swap stat number for the root_mem_cgroup anymore,
here we can just return an invalid CSS ID if there is no non-root memcg
is alive.  Also, introduce memsw_accounting_users to track the number of
active non-root memcgs.

Signed-off-by: Jie Liu <jeff.liu@oracle.com>
CC: Glauber Costa <glommer@parallels.com>
CC: Michal Hocko <mhocko@suse.cz>
CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
CC: Johannes Weiner <hannes@cmpxchg.org>
CC: Mel Gorman <mgorman@suse.de>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Sha Zhengju <handai.szj@taobao.com>

---
 mm/page_cgroup.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/mm/page_cgroup.c b/mm/page_cgroup.c
index c945254..189fbf5 100644
--- a/mm/page_cgroup.c
+++ b/mm/page_cgroup.c
@@ -336,6 +336,8 @@ struct swap_cgroup {
 };
 #define SC_PER_PAGE	(PAGE_SIZE/sizeof(struct swap_cgroup))
 
+static atomic_t memsw_accounting_users = ATOMIC_INIT(0);
+
 /*
  * SwapCgroup implements "lookup" and "exchange" operations.
  * In typical usage, this swap_cgroup is accessed via memcg's charge/uncharge
@@ -389,6 +391,9 @@ static struct swap_cgroup *lookup_swap_cgroup(swp_entry_t ent,
 	struct page *mappage;
 	struct swap_cgroup *sc;
 
+	if (!atomic_read(&memsw_accounting_users))
+		return NULL;
+
 	ctrl = &swap_cgroup_ctrl[swp_type(ent)];
 	if (ctrlp)
 		*ctrlp = ctrl;
@@ -416,6 +421,8 @@ unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
 	unsigned short retval;
 
 	sc = lookup_swap_cgroup(ent, &ctrl);
+	if (!sc)
+		return 0;
 
 	spin_lock_irqsave(&ctrl->lock, flags);
 	retval = sc->id;
@@ -443,6 +450,8 @@ unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
 	unsigned long flags;
 
 	sc = lookup_swap_cgroup(ent, &ctrl);
+	if (!sc)
+		return 0;
 
 	spin_lock_irqsave(&ctrl->lock, flags);
 	old = sc->id;
@@ -460,7 +469,9 @@ unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
  */
 unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
 {
-	return lookup_swap_cgroup(ent, NULL)->id;
+	struct swap_cgroup *sc = lookup_swap_cgroup(ent, NULL);
+
+	return sc ? sc->id : 0;
 }
 
 int swap_cgroup_swapon(int type, unsigned long max_pages)
@@ -471,6 +482,9 @@ int swap_cgroup_swapon(int type, unsigned long max_pages)
 	if (!do_swap_account)
 		return 0;
 
+	if (!atomic_read(&memsw_accounting_users))
+		return 0;
+
 	length = DIV_ROUND_UP(max_pages, SC_PER_PAGE);
 
 	ctrl = &swap_cgroup_ctrl[type];
-- 
1.7.9.5

--
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-01-28 10:54 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-28 10:54 [PATCH v2 0/6] memcg: disable swap cgroup allocation at swapon Jeff Liu
2013-01-28 10:54 ` [PATCH v2 1/6] memcg: refactor swap_cgroup_swapon() Jeff Liu
     [not found]   ` <510658E6.9030108-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-01-29  9:15     ` Lord Glauber Costa of Sealand
2013-01-29  9:15       ` Lord Glauber Costa of Sealand
2013-01-29 13:41     ` Michal Hocko
2013-01-29 13:41       ` Michal Hocko
2013-01-28 10:54 ` [PATCH v2 2/6] memcg: bypass swap accounting for the root memcg Jeff Liu
2013-01-29 10:18   ` Lord Glauber Costa of Sealand
2013-01-31  6:18     ` Jeff Liu
2013-01-29 14:13   ` Michal Hocko
2013-01-30 16:01     ` Jeff Liu
2013-01-30 16:29       ` Michal Hocko
2013-01-31  4:00         ` Jeff Liu
2013-01-28 10:54 ` Jeff Liu [this message]
     [not found]   ` <510658F0.9050802-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-01-29  9:46     ` [PATCH v2 3/6] memcg: introduce memsw_accounting_users Lord Glauber Costa of Sealand
2013-01-29  9:46       ` Lord Glauber Costa of Sealand
2013-01-29 10:52       ` Jeff Liu
2013-01-29 14:26       ` Michal Hocko
2013-01-29 14:24     ` Michal Hocko
2013-01-29 14:24       ` Michal Hocko
2013-01-29 15:16       ` Jeff Liu
2013-01-28 10:54 ` [PATCH v2 4/6] memcg: export nr_swap_files Jeff Liu
     [not found]   ` <510658F6.4010504-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-01-29  9:47     ` Lord Glauber Costa of Sealand
2013-01-29  9:47       ` Lord Glauber Costa of Sealand
2013-01-29 14:31     ` Michal Hocko
2013-01-29 14:31       ` Michal Hocko
2013-01-29 15:17       ` Jeff Liu
2013-01-28 10:54 ` [PATCH v2 5/6] memcg: introduce swap_cgroup_init()/swap_cgroup_free() Jeff Liu
2013-01-29  9:57   ` Lord Glauber Costa of Sealand
2013-01-29 10:21     ` Jeff Liu
     [not found]   ` <510658F7.6050806-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-01-29 14:56     ` Michal Hocko
2013-01-29 14:56       ` Michal Hocko
2013-01-29 15:51       ` Jeff Liu
     [not found]         ` <5107F00E.7070302-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-01-29 16:09           ` Michal Hocko
2013-01-29 16:09             ` Michal Hocko
2013-01-28 10:54 ` [PATCH v2 6/6] memcg: init/free swap cgroup strucutres upon create/free child memcg Jeff Liu
     [not found]   ` <510658FC.50009-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-01-29  9:59     ` Lord Glauber Costa of Sealand
2013-01-29  9:59       ` Lord Glauber Costa of Sealand
2013-01-29 10:27       ` Jeff Liu
2013-01-29 15:11     ` Michal Hocko
2013-01-29 15:11       ` Michal Hocko
     [not found] ` <510658E3.1020306-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-01-29 15:15   ` [PATCH v2 0/6] memcg: disable swap cgroup allocation at swapon Michal Hocko
2013-01-29 15:15     ` Michal Hocko
2013-01-29 16:50     ` Jeff Liu

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=510658F0.9050802@oracle.com \
    --to=jeff.liu@oracle.com \
    --cc=cgroups@vger.kernel.org \
    --cc=glommer@parallels.com \
    --cc=linux-mm@kvack.org \
    --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 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.