* [PATCH v2] memcg: add mem_cgroup_from_css() helper
@ 2012-07-23 1:44 Wanpeng Li
2012-07-23 2:08 ` Gavin Shan
2012-07-23 2:08 ` Gavin Shan
0 siblings, 2 replies; 4+ messages in thread
From: Wanpeng Li @ 2012-07-23 1:44 UTC (permalink / raw)
To: Andrew Morton
Cc: Fengguang Wu, Seth Jennings, Kirill A. Shutemov, linux-mm,
Michal Hocko, Johannes Weiner, KAMEZAWAHiroyuki, Gavin Shan,
linux-kernel, Wanpeng Li
Changelog v2:
* fix too many args to mem_cgroup_from_css() (spotted by Kirill A. Shutemov)
* fix kernel build failed (spotted by Fengguang)
Add a mem_cgroup_from_css() helper to replace open-coded invokations of
container_of(). To clarify the code and to add a little more type safety.
Acked-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
---
mm/memcontrol.c | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 883283d..f0c7639 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -407,6 +407,12 @@ enum charge_type {
static void mem_cgroup_get(struct mem_cgroup *memcg);
static void mem_cgroup_put(struct mem_cgroup *memcg);
+static inline
+struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s)
+{
+ return container_of(s, struct mem_cgroup, css);
+}
+
/* Writing them here to avoid exposing memcg's inner layout */
#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
#include <net/sock.h>
@@ -864,9 +870,8 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page)
struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
{
- return container_of(cgroup_subsys_state(cont,
- mem_cgroup_subsys_id), struct mem_cgroup,
- css);
+ return mem_cgroup_from_css(cgroup_subsys_state(cont,
+ mem_cgroup_subsys_id));
}
struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
@@ -879,8 +884,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
if (unlikely(!p))
return NULL;
- return container_of(task_subsys_state(p, mem_cgroup_subsys_id),
- struct mem_cgroup, css);
+ return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
}
struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
@@ -966,8 +970,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
css = css_get_next(&mem_cgroup_subsys, id + 1, &root->css, &id);
if (css) {
if (css == &root->css || css_tryget(css))
- memcg = container_of(css,
- struct mem_cgroup, css);
+ memcg = mem_cgroup_from_css(css);
} else
id = 0;
rcu_read_unlock();
@@ -2429,7 +2432,7 @@ static struct mem_cgroup *mem_cgroup_lookup(unsigned short id)
css = css_lookup(&mem_cgroup_subsys, id);
if (!css)
return NULL;
- return container_of(css, struct mem_cgroup, css);
+ return mem_cgroup_from_css(css);
}
struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
--
1.7.7.6
--
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] memcg: add mem_cgroup_from_css() helper
2012-07-23 1:44 [PATCH v2] memcg: add mem_cgroup_from_css() helper Wanpeng Li
2012-07-23 2:08 ` Gavin Shan
@ 2012-07-23 2:08 ` Gavin Shan
2012-07-23 2:26 ` Wanpeng Li
1 sibling, 1 reply; 4+ messages in thread
From: Gavin Shan @ 2012-07-23 2:08 UTC (permalink / raw)
To: Wanpeng Li
Cc: Andrew Morton, Fengguang Wu, Seth Jennings, Kirill A. Shutemov,
linux-mm, Michal Hocko, Johannes Weiner, KAMEZAWAHiroyuki,
Gavin Shan, linux-kernel
For this case, we usually fix the build error on top of linux-next.
It seems that you're changing the original patch and send again, which
isn't reasonable, man :-)
Thanks,
Gavin
>Changelog v2:
>* fix too many args to mem_cgroup_from_css() (spotted by Kirill A. Shutemov)
>* fix kernel build failed (spotted by Fengguang)
>
>Add a mem_cgroup_from_css() helper to replace open-coded invokations of
>container_of(). To clarify the code and to add a little more type safety.
>
>Acked-by: Michal Hocko <mhocko@suse.cz>
>Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
>
>---
> mm/memcontrol.c | 19 +++++++++++--------
> 1 files changed, 11 insertions(+), 8 deletions(-)
>
>diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>index 883283d..f0c7639 100644
>--- a/mm/memcontrol.c
>+++ b/mm/memcontrol.c
>@@ -407,6 +407,12 @@ enum charge_type {
> static void mem_cgroup_get(struct mem_cgroup *memcg);
> static void mem_cgroup_put(struct mem_cgroup *memcg);
>
>+static inline
>+struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s)
>+{
>+ return container_of(s, struct mem_cgroup, css);
>+}
>+
> /* Writing them here to avoid exposing memcg's inner layout */
> #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
> #include <net/sock.h>
>@@ -864,9 +870,8 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page)
>
> struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
> {
>- return container_of(cgroup_subsys_state(cont,
>- mem_cgroup_subsys_id), struct mem_cgroup,
>- css);
>+ return mem_cgroup_from_css(cgroup_subsys_state(cont,
>+ mem_cgroup_subsys_id));
> }
>
> struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
>@@ -879,8 +884,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
> if (unlikely(!p))
> return NULL;
>
>- return container_of(task_subsys_state(p, mem_cgroup_subsys_id),
>- struct mem_cgroup, css);
>+ return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
> }
>
> struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
>@@ -966,8 +970,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
> css = css_get_next(&mem_cgroup_subsys, id + 1, &root->css, &id);
> if (css) {
> if (css == &root->css || css_tryget(css))
>- memcg = container_of(css,
>- struct mem_cgroup, css);
>+ memcg = mem_cgroup_from_css(css);
> } else
> id = 0;
> rcu_read_unlock();
>@@ -2429,7 +2432,7 @@ static struct mem_cgroup *mem_cgroup_lookup(unsigned short id)
> css = css_lookup(&mem_cgroup_subsys, id);
> if (!css)
> return NULL;
>- return container_of(css, struct mem_cgroup, css);
>+ return mem_cgroup_from_css(css);
> }
>
> struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
>--
>1.7.7.6
>
--
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] memcg: add mem_cgroup_from_css() helper
2012-07-23 1:44 [PATCH v2] memcg: add mem_cgroup_from_css() helper Wanpeng Li
@ 2012-07-23 2:08 ` Gavin Shan
2012-07-23 2:08 ` Gavin Shan
1 sibling, 0 replies; 4+ messages in thread
From: Gavin Shan @ 2012-07-23 2:08 UTC (permalink / raw)
To: Wanpeng Li
Cc: Andrew Morton, Fengguang Wu, Seth Jennings, Kirill A. Shutemov,
linux-mm, Michal Hocko, Johannes Weiner, KAMEZAWAHiroyuki,
Gavin Shan, linux-kernel
For this case, we usually fix the build error on top of linux-next.
It seems that you're changing the original patch and send again, which
isn't reasonable, man :-)
Thanks,
Gavin
>Changelog v2:
>* fix too many args to mem_cgroup_from_css() (spotted by Kirill A. Shutemov)
>* fix kernel build failed (spotted by Fengguang)
>
>Add a mem_cgroup_from_css() helper to replace open-coded invokations of
>container_of(). To clarify the code and to add a little more type safety.
>
>Acked-by: Michal Hocko <mhocko@suse.cz>
>Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
>
>---
> mm/memcontrol.c | 19 +++++++++++--------
> 1 files changed, 11 insertions(+), 8 deletions(-)
>
>diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>index 883283d..f0c7639 100644
>--- a/mm/memcontrol.c
>+++ b/mm/memcontrol.c
>@@ -407,6 +407,12 @@ enum charge_type {
> static void mem_cgroup_get(struct mem_cgroup *memcg);
> static void mem_cgroup_put(struct mem_cgroup *memcg);
>
>+static inline
>+struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s)
>+{
>+ return container_of(s, struct mem_cgroup, css);
>+}
>+
> /* Writing them here to avoid exposing memcg's inner layout */
> #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
> #include <net/sock.h>
>@@ -864,9 +870,8 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page)
>
> struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
> {
>- return container_of(cgroup_subsys_state(cont,
>- mem_cgroup_subsys_id), struct mem_cgroup,
>- css);
>+ return mem_cgroup_from_css(cgroup_subsys_state(cont,
>+ mem_cgroup_subsys_id));
> }
>
> struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
>@@ -879,8 +884,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
> if (unlikely(!p))
> return NULL;
>
>- return container_of(task_subsys_state(p, mem_cgroup_subsys_id),
>- struct mem_cgroup, css);
>+ return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
> }
>
> struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
>@@ -966,8 +970,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
> css = css_get_next(&mem_cgroup_subsys, id + 1, &root->css, &id);
> if (css) {
> if (css == &root->css || css_tryget(css))
>- memcg = container_of(css,
>- struct mem_cgroup, css);
>+ memcg = mem_cgroup_from_css(css);
> } else
> id = 0;
> rcu_read_unlock();
>@@ -2429,7 +2432,7 @@ static struct mem_cgroup *mem_cgroup_lookup(unsigned short id)
> css = css_lookup(&mem_cgroup_subsys, id);
> if (!css)
> return NULL;
>- return container_of(css, struct mem_cgroup, css);
>+ return mem_cgroup_from_css(css);
> }
>
> struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
>--
>1.7.7.6
>
--
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] memcg: add mem_cgroup_from_css() helper
2012-07-23 2:08 ` Gavin Shan
@ 2012-07-23 2:26 ` Wanpeng Li
0 siblings, 0 replies; 4+ messages in thread
From: Wanpeng Li @ 2012-07-23 2:26 UTC (permalink / raw)
To: Gavin Shan
Cc: Andrew Morton, Fengguang Wu, Seth Jennings, Kirill A. Shutemov,
linux-mm, Michal Hocko, Johannes Weiner, KAMEZAWAHiroyuki,
linux-kernel
On Mon, Jul 23, 2012 at 10:08:56AM +0800, Gavin Shan wrote:
>
>For this case, we usually fix the build error on top of linux-next.
>It seems that you're changing the original patch and send again, which
>isn't reasonable, man :-)
OK, I will send a patch just fix build error against linux-next.
Regards,
Wanpeng Li
>
>Thanks,
>Gavin
>
>>Changelog v2:
>>* fix too many args to mem_cgroup_from_css() (spotted by Kirill A. Shutemov)
>>* fix kernel build failed (spotted by Fengguang)
>>
>>Add a mem_cgroup_from_css() helper to replace open-coded invokations of
>>container_of(). To clarify the code and to add a little more type safety.
>>
>>Acked-by: Michal Hocko <mhocko@suse.cz>
>>Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
>>
>>---
>> mm/memcontrol.c | 19 +++++++++++--------
>> 1 files changed, 11 insertions(+), 8 deletions(-)
>>
>>diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>>index 883283d..f0c7639 100644
>>--- a/mm/memcontrol.c
>>+++ b/mm/memcontrol.c
>>@@ -407,6 +407,12 @@ enum charge_type {
>> static void mem_cgroup_get(struct mem_cgroup *memcg);
>> static void mem_cgroup_put(struct mem_cgroup *memcg);
>>
>>+static inline
>>+struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s)
>>+{
>>+ return container_of(s, struct mem_cgroup, css);
>>+}
>>+
>> /* Writing them here to avoid exposing memcg's inner layout */
>> #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
>> #include <net/sock.h>
>>@@ -864,9 +870,8 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page)
>>
>> struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
>> {
>>- return container_of(cgroup_subsys_state(cont,
>>- mem_cgroup_subsys_id), struct mem_cgroup,
>>- css);
>>+ return mem_cgroup_from_css(cgroup_subsys_state(cont,
>>+ mem_cgroup_subsys_id));
>> }
>>
>> struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
>>@@ -879,8 +884,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
>> if (unlikely(!p))
>> return NULL;
>>
>>- return container_of(task_subsys_state(p, mem_cgroup_subsys_id),
>>- struct mem_cgroup, css);
>>+ return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
>> }
>>
>> struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
>>@@ -966,8 +970,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
>> css = css_get_next(&mem_cgroup_subsys, id + 1, &root->css, &id);
>> if (css) {
>> if (css == &root->css || css_tryget(css))
>>- memcg = container_of(css,
>>- struct mem_cgroup, css);
>>+ memcg = mem_cgroup_from_css(css);
>> } else
>> id = 0;
>> rcu_read_unlock();
>>@@ -2429,7 +2432,7 @@ static struct mem_cgroup *mem_cgroup_lookup(unsigned short id)
>> css = css_lookup(&mem_cgroup_subsys, id);
>> if (!css)
>> return NULL;
>>- return container_of(css, struct mem_cgroup, css);
>>+ return mem_cgroup_from_css(css);
>> }
>>
>> struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
>>--
>>1.7.7.6
>>
--
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-07-23 2:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-23 1:44 [PATCH v2] memcg: add mem_cgroup_from_css() helper Wanpeng Li
2012-07-23 2:08 ` Gavin Shan
2012-07-23 2:08 ` Gavin Shan
2012-07-23 2:26 ` Wanpeng Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox