Re: [PATCH] mm/memcg: wrap mem_cgroup_from_css function
From: Andrew Morton
Date: Wed Jul 18 2012 - 17:36:09 EST
On Wed, 18 Jul 2012 11:05:30 +0800
Wanpeng Li <liwanp@xxxxxxxxxxxxxxxxxx> wrote:
> wrap mem_cgroup_from_css function to clarify get mem cgroup
> from cgroup_subsys_state.
This certainly adds clarity.
But it also adds a little more type-safety - these container_of() calls
can be invoked against *any* struct which has a field called "css".
With your patch, we add a check that the code is indeed using a
cgroup_subsys_state*. A small thing, but it's all good.
I changed the patch title to the more idiomatic "memcg: add
mem_cgroup_from_css() helper" and rewrote the changelog to
: 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.
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -396,6 +396,12 @@ static void mem_cgroup_put(struct mem_cgroup *memcg);
> #include <net/sock.h>
> #include <net/ip.h>
>
> +static inline
> +struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s)
> +{
> + return container_of(s, struct mem_cgroup, css);
> +}
And with great self-control, I avoided renaming this to
memcg_from_css(). Sigh. I guess all that extra typing has cardio
benefits.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/