From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
"nishimura@mxp.nes.nec.co.jp" <nishimura@mxp.nes.nec.co.jp>,
"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
gthelen@google.com, m-ikeda@ds.jp.nec.com,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [RFC][PATCH 2/7][memcg] cgroup arbitarary ID allocation
Date: Tue, 27 Jul 2010 16:54:17 +0900 [thread overview]
Message-ID: <20100727165417.dacbe199.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20100727165155.8b458b7f.kamezawa.hiroyu@jp.fujitsu.com>
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
When a subsystem want to make use of "id" more, it's necessary to
manage the id at cgroup subsystem creation time. But, now,
because of the order of cgroup creation callback, subsystem can't
declare the id it wants. This patch allows subsystem to use customized
ID for themselves.
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
Documentation/cgroups/cgroups.txt | 9 +++++++++
include/linux/cgroup.h | 3 ++-
kernel/cgroup.c | 17 ++++++++++++-----
3 files changed, 23 insertions(+), 6 deletions(-)
Index: mmotm-2.6.35-0719/include/linux/cgroup.h
===================================================================
--- mmotm-2.6.35-0719.orig/include/linux/cgroup.h
+++ mmotm-2.6.35-0719/include/linux/cgroup.h
@@ -475,7 +475,7 @@ struct cgroup_subsys {
struct cgroup *cgrp);
void (*post_clone)(struct cgroup_subsys *ss, struct cgroup *cgrp);
void (*bind)(struct cgroup_subsys *ss, struct cgroup *root);
-
+ int (*custom_id)(struct cgroup_subsys *ss, struct cgroup *cgrp);
int subsys_id;
int active;
int disabled;
@@ -483,6 +483,7 @@ struct cgroup_subsys {
/*
* True if this subsys uses ID. ID is not available before cgroup_init()
* (not available in early_init time.)
+ * You can detemine ID if you have custom_id() callback.
*/
bool use_id;
#define MAX_CGROUP_TYPE_NAMELEN 32
Index: mmotm-2.6.35-0719/kernel/cgroup.c
===================================================================
--- mmotm-2.6.35-0719.orig/kernel/cgroup.c
+++ mmotm-2.6.35-0719/kernel/cgroup.c
@@ -4526,10 +4526,11 @@ EXPORT_SYMBOL_GPL(free_css_id);
* always serialized (By cgroup_mutex() at create()).
*/
-static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth)
+static struct css_id *get_new_cssid(struct cgroup_subsys *ss,
+ int depth, struct cgroup *child)
{
struct css_id *newid;
- int myid, error, size;
+ int from_id, myid, error, size;
BUG_ON(!ss->use_id);
@@ -4542,9 +4543,13 @@ static struct css_id *get_new_cssid(stru
error = -ENOMEM;
goto err_out;
}
+ if (child && ss->custom_id)
+ from_id = ss->custom_id(ss, child);
+ else
+ from_id = 1;
spin_lock(&ss->id_lock);
/* Don't use 0. allocates an ID of 1-65535 */
- error = idr_get_new_above(&ss->idr, newid, 1, &myid);
+ error = idr_get_new_above(&ss->idr, newid, from_id, &myid);
spin_unlock(&ss->id_lock);
/* Returns error when there are no free spaces for new ID.*/
@@ -4552,6 +4557,8 @@ static struct css_id *get_new_cssid(stru
error = -ENOSPC;
goto err_out;
}
+ BUG_ON(ss->custom_id && from_id != myid);
+
if (myid > CSS_ID_MAX)
goto remove_idr;
@@ -4577,7 +4584,7 @@ static int __init_or_module cgroup_init_
spin_lock_init(&ss->id_lock);
idr_init(&ss->idr);
- newid = get_new_cssid(ss, 0);
+ newid = get_new_cssid(ss, 0 ,NULL);
if (IS_ERR(newid))
return PTR_ERR(newid);
@@ -4600,7 +4607,7 @@ static int alloc_css_id(struct cgroup_su
parent_id = parent_css->id;
depth = parent_id->depth + 1;
- child_id = get_new_cssid(ss, depth);
+ child_id = get_new_cssid(ss, depth, child);
if (IS_ERR(child_id))
return PTR_ERR(child_id);
Index: mmotm-2.6.35-0719/Documentation/cgroups/cgroups.txt
===================================================================
--- mmotm-2.6.35-0719.orig/Documentation/cgroups/cgroups.txt
+++ mmotm-2.6.35-0719/Documentation/cgroups/cgroups.txt
@@ -621,6 +621,15 @@ and root cgroup. Currently this will onl
the default hierarchy (which never has sub-cgroups) and a hierarchy
that is being created/destroyed (and hence has no sub-cgroups).
+void custom_id(struct cgroup_subsys *ss, struct cgroup *cgrp)
+
+Called at assigning a new ID to cgroup subsystem state struct. This
+is called when ss->use_id == true. If this function is not provided,
+a new ID is automatically assigned. If you enable ss->use_id,
+you can use css_lookup() and css_get_next() to access "css" objects
+via IDs.
+
+
4. Questions
============
--
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>
next prev parent reply other threads:[~2010-07-27 7:58 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-27 7:51 [RFC][PATCH 0/7][memcg] towards I/O aware memory cgroup KAMEZAWA Hiroyuki
2010-07-27 7:53 ` [RFC][PATCH 1/7][memcg] virtually indexed array library KAMEZAWA Hiroyuki
2010-07-27 18:29 ` Jonathan Corbet
2010-07-28 0:08 ` KAMEZAWA Hiroyuki
2010-07-28 19:45 ` Andrew Morton
2010-07-29 0:32 ` KAMEZAWA Hiroyuki
2010-07-29 4:27 ` KAMEZAWA Hiroyuki
2010-08-02 18:00 ` Balbir Singh
2010-08-02 23:45 ` KAMEZAWA Hiroyuki
2010-07-27 7:54 ` KAMEZAWA Hiroyuki [this message]
2010-07-28 2:30 ` [RFC][PATCH 2/7][memcg] cgroup arbitarary ID allocation Vivek Goyal
2010-07-28 2:35 ` KAMEZAWA Hiroyuki
2010-07-28 3:10 ` Vivek Goyal
2010-08-02 18:04 ` Balbir Singh
2010-08-02 23:45 ` KAMEZAWA Hiroyuki
2010-07-27 7:55 ` [RFC][PATCH 3/7][memcg] memcg on virt array for quick access via ID KAMEZAWA Hiroyuki
2010-07-27 7:56 ` [RFC][PATCH 4/7][memcg] memcg use ID in page_cgroup KAMEZAWA Hiroyuki
2010-07-28 2:39 ` Vivek Goyal
2010-07-28 2:44 ` KAMEZAWA Hiroyuki
2010-07-28 3:13 ` Vivek Goyal
2010-07-28 3:18 ` KAMEZAWA Hiroyuki
2010-07-28 3:21 ` KAMEZAWA Hiroyuki
2010-07-28 14:17 ` Vivek Goyal
2010-07-28 15:43 ` Munehiro Ikeda
2010-07-27 7:59 ` [RFC][PATCH 5/7][memcg] memcg lockless update of file mapped KAMEZAWA Hiroyuki
2010-07-28 7:09 ` Greg Thelen
2010-07-28 7:13 ` KAMEZAWA Hiroyuki
2010-07-27 8:00 ` [RFC][PATCH 6/7][memcg] generic file status update KAMEZAWA Hiroyuki
2010-07-28 7:12 ` Greg Thelen
2010-07-28 7:14 ` KAMEZAWA Hiroyuki
2010-07-27 8:02 ` [RFC][PATCH 7/7][memcg] use spin lock instead of bit_spin_lock in page_cgroup KAMEZAWA Hiroyuki
2010-07-28 6:16 ` Greg Thelen
2010-07-28 6:20 ` KAMEZAWA Hiroyuki
2010-08-02 18:09 ` Balbir Singh
2010-08-02 23:46 ` KAMEZAWA Hiroyuki
2010-07-28 0:13 ` [RFC][PATCH 0/7][memcg] towards I/O aware memory cgroup KAMEZAWA Hiroyuki
2010-07-28 14:42 ` Balbir Singh
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=20100727165417.dacbe199.kamezawa.hiroyu@jp.fujitsu.com \
--to=kamezawa.hiroyu@jp.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=gthelen@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=m-ikeda@ds.jp.nec.com \
--cc=nishimura@mxp.nes.nec.co.jp \
/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