From: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Andrew Morton
<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
KAMEZAWA Hiroyuki
<kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>,
Michal Hocko <mhocko-AlSwsSmVLrQ@public.gmane.org>,
Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>,
LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Cgroups <cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org
Subject: [PATCH v4 3/8] cgroup: implement cgroup_from_id()
Date: Wed, 31 Jul 2013 09:51:31 +0800 [thread overview]
Message-ID: <51F86DA3.6050406@huawei.com> (raw)
In-Reply-To: <51F86D69.2030907-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
This will be used as a replacement for css_lookup().
There's a difference with cgroup id and css id. cgroup id starts with 0,
while css id starts with 1.
v4:
- also check if cggroup_mutex is held.
- make it an inline function.
Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Reviewed-by: Michal Hocko <mhocko-AlSwsSmVLrQ@public.gmane.org>
---
include/linux/cgroup.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 8c107e9..4ef8452 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -720,6 +720,24 @@ static inline struct cgroup* task_cgroup(struct task_struct *task,
return task_subsys_state(task, subsys_id)->cgroup;
}
+/**
+ * cgroup_from_id - lookup cgroup by id
+ * @ss: cgroup subsys to be looked into
+ * @id: the cgroup id
+ *
+ * Returns the cgroup if there's valid one with @id, otherwise returns NULL.
+ * Should be called under rcu_read_lock().
+ */
+static inline struct cgroup *cgroup_from_id(struct cgroup_subsys *ss, int id)
+{
+#ifdef CONFIG_PROVE_RCU
+ rcu_lockdep_assert(rcu_read_lock_held() ||
+ lockdep_is_held(&cgroup_mutex),
+ "cgroup_from_id() needs proper protection");
+#endif
+ return idr_find(&ss->root->cgroup_idr, id);
+}
+
struct cgroup *cgroup_next_sibling(struct cgroup *pos);
/**
--
1.8.0.2
WARNING: multiple messages have this Message-ID (diff)
From: Li Zefan <lizefan@huawei.com>
To: Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Michal Hocko <mhocko@suse.cz>,
Johannes Weiner <hannes@cmpxchg.org>,
LKML <linux-kernel@vger.kernel.org>,
Cgroups <cgroups@vger.kernel.org>,
linux-mm@kvack.org
Subject: [PATCH v4 3/8] cgroup: implement cgroup_from_id()
Date: Wed, 31 Jul 2013 09:51:31 +0800 [thread overview]
Message-ID: <51F86DA3.6050406@huawei.com> (raw)
In-Reply-To: <51F86D69.2030907@huawei.com>
This will be used as a replacement for css_lookup().
There's a difference with cgroup id and css id. cgroup id starts with 0,
while css id starts with 1.
v4:
- also check if cggroup_mutex is held.
- make it an inline function.
Signed-off-by: Li Zefan <lizefan@huawei.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
---
include/linux/cgroup.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 8c107e9..4ef8452 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -720,6 +720,24 @@ static inline struct cgroup* task_cgroup(struct task_struct *task,
return task_subsys_state(task, subsys_id)->cgroup;
}
+/**
+ * cgroup_from_id - lookup cgroup by id
+ * @ss: cgroup subsys to be looked into
+ * @id: the cgroup id
+ *
+ * Returns the cgroup if there's valid one with @id, otherwise returns NULL.
+ * Should be called under rcu_read_lock().
+ */
+static inline struct cgroup *cgroup_from_id(struct cgroup_subsys *ss, int id)
+{
+#ifdef CONFIG_PROVE_RCU
+ rcu_lockdep_assert(rcu_read_lock_held() ||
+ lockdep_is_held(&cgroup_mutex),
+ "cgroup_from_id() needs proper protection");
+#endif
+ return idr_find(&ss->root->cgroup_idr, id);
+}
+
struct cgroup *cgroup_next_sibling(struct cgroup *pos);
/**
--
1.8.0.2
--
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>
WARNING: multiple messages have this Message-ID (diff)
From: Li Zefan <lizefan@huawei.com>
To: Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Michal Hocko <mhocko@suse.cz>,
Johannes Weiner <hannes@cmpxchg.org>,
LKML <linux-kernel@vger.kernel.org>,
Cgroups <cgroups@vger.kernel.org>, <linux-mm@kvack.org>
Subject: [PATCH v4 3/8] cgroup: implement cgroup_from_id()
Date: Wed, 31 Jul 2013 09:51:31 +0800 [thread overview]
Message-ID: <51F86DA3.6050406@huawei.com> (raw)
In-Reply-To: <51F86D69.2030907@huawei.com>
This will be used as a replacement for css_lookup().
There's a difference with cgroup id and css id. cgroup id starts with 0,
while css id starts with 1.
v4:
- also check if cggroup_mutex is held.
- make it an inline function.
Signed-off-by: Li Zefan <lizefan@huawei.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
---
include/linux/cgroup.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 8c107e9..4ef8452 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -720,6 +720,24 @@ static inline struct cgroup* task_cgroup(struct task_struct *task,
return task_subsys_state(task, subsys_id)->cgroup;
}
+/**
+ * cgroup_from_id - lookup cgroup by id
+ * @ss: cgroup subsys to be looked into
+ * @id: the cgroup id
+ *
+ * Returns the cgroup if there's valid one with @id, otherwise returns NULL.
+ * Should be called under rcu_read_lock().
+ */
+static inline struct cgroup *cgroup_from_id(struct cgroup_subsys *ss, int id)
+{
+#ifdef CONFIG_PROVE_RCU
+ rcu_lockdep_assert(rcu_read_lock_held() ||
+ lockdep_is_held(&cgroup_mutex),
+ "cgroup_from_id() needs proper protection");
+#endif
+ return idr_find(&ss->root->cgroup_idr, id);
+}
+
struct cgroup *cgroup_next_sibling(struct cgroup *pos);
/**
--
1.8.0.2
next prev parent reply other threads:[~2013-07-31 1:51 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-31 1:50 [PATCH v4 0/8] memcg, cgroup: kill css_id Li Zefan
2013-07-31 1:50 ` Li Zefan
2013-07-31 1:50 ` Li Zefan
2013-07-31 1:50 ` [PATCH v4 1/8] cgroup: convert cgroup_ida to cgroup_idr Li Zefan
2013-07-31 1:50 ` Li Zefan
2013-07-31 1:51 ` [PATCH v4 2/8] cgroup: document how cgroup IDs are assigned Li Zefan
2013-07-31 1:51 ` Li Zefan
[not found] ` <51F86D69.2030907-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-07-31 1:51 ` Li Zefan [this message]
2013-07-31 1:51 ` [PATCH v4 3/8] cgroup: implement cgroup_from_id() Li Zefan
2013-07-31 1:51 ` Li Zefan
2013-07-31 1:51 ` [PATCH v4 4/8] memcg: convert to use cgroup_is_descendant() Li Zefan
2013-07-31 1:51 ` Li Zefan
2013-07-31 1:51 ` Li Zefan
2013-07-31 1:52 ` [PATCH v4 7/8] memcg: stop using css id Li Zefan
2013-07-31 1:52 ` Li Zefan
2013-07-31 1:52 ` Li Zefan
2013-07-31 1:52 ` [PATCH v4 5/8] memcg: convert to use cgroup id Li Zefan
2013-07-31 1:52 ` Li Zefan
2013-07-31 1:52 ` [PATCH v4 6/8] memcg: fail to create cgroup if the cgroup id is too big Li Zefan
2013-07-31 1:52 ` Li Zefan
2013-07-31 1:53 ` [PATCH v4 8/8] cgroup: kill css_id Li Zefan
2013-07-31 1:53 ` Li Zefan
2013-07-31 11:49 ` Tejun Heo
2013-07-31 11:49 ` Tejun Heo
2013-07-31 11:48 ` [PATCH v4 0/8] memcg, " Tejun Heo
2013-07-31 11:48 ` Tejun Heo
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=51F86DA3.6050406@huawei.com \
--to=lizefan-hv44wf8li93qt0dzr+alfa@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
--cc=kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
--cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/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.