diff options
author | Tejun Heo <tj@kernel.org> | 2013-08-09 02:11:23 +0200 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-08-09 02:11:23 +0200 |
commit | a7c6d554aa01236ac2a9f851ab0f75704f76dfa2 (patch) | |
tree | fe62d07283a589daa39f843deaefafd11c572b84 /mm | |
parent | cgroup: add subsystem pointer to cgroup_subsys_state (diff) | |
download | linux-a7c6d554aa01236ac2a9f851ab0f75704f76dfa2.tar.xz linux-a7c6d554aa01236ac2a9f851ab0f75704f76dfa2.zip |
cgroup: add/update accessors which obtain subsys specific data from css
css (cgroup_subsys_state) is usually embedded in a subsys specific
data structure. Subsystems either use container_of() directly to cast
from css to such data structure or has an accessor function wrapping
such cast. As cgroup as whole is moving towards using css as the main
interface handle, add and update such accessors to ease dealing with
css's.
All accessors explicitly handle NULL input and return NULL in those
cases. While this looks like an extra branch in the code, as all
controllers specific data structures have css as the first field, the
casting doesn't involve any offsetting and the compiler can trivially
optimize out the branch.
* blkio, freezer, cpuset, cpu, cpuacct and net_cls didn't have such
accessor. Added.
* memory, hugetlb and devices already had one but didn't explicitly
handle NULL input. Updated.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/hugetlb_cgroup.c | 2 | ||||
-rw-r--r-- | mm/memcontrol.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index d2f9fc0b186e..95585a0b9c8d 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -36,7 +36,7 @@ static struct hugetlb_cgroup *root_h_cgroup __read_mostly; static inline struct hugetlb_cgroup *hugetlb_cgroup_from_css(struct cgroup_subsys_state *s) { - return container_of(s, struct hugetlb_cgroup, css); + return s ? container_of(s, struct hugetlb_cgroup, css) : NULL; } static inline diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b47bd3ad3c2b..11d659e3b08e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -486,7 +486,7 @@ static DEFINE_MUTEX(memcg_create_mutex); static inline struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s) { - return container_of(s, struct mem_cgroup, css); + return s ? container_of(s, struct mem_cgroup, css) : NULL; } /* Some nice accessors for the vmpressure. */ |