Skip to content

Commit fdc4161

Browse files
nhatsmrtakpm00
authored andcommitted
memcontrol: implement mem_cgroup_tryget_online()
This patch implements a helper function that try to get a reference to an memcg's css, as well as checking if it is online. This new function is almost exactly the same as the existing mem_cgroup_tryget(), except for the onlineness check. In the !CONFIG_MEMCG case, it always returns true, analogous to mem_cgroup_tryget(). This is useful for e.g to the new zswap writeback scheme, where we need to select the next online memcg as a candidate for the global limit reclaim. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Nhat Pham <[email protected]> Tested-by: Bagas Sanjaya <[email protected]> Reviewed-by: Yosry Ahmed <[email protected]> Cc: Chris Li <[email protected]> Cc: Dan Streetman <[email protected]> Cc: Domenico Cerasuolo <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Seth Jennings <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Vitaly Wool <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 0a97c01 commit fdc4161

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/linux/memcontrol.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@ static inline bool mem_cgroup_tryget(struct mem_cgroup *memcg)
821821
return !memcg || css_tryget(&memcg->css);
822822
}
823823

824+
static inline bool mem_cgroup_tryget_online(struct mem_cgroup *memcg)
825+
{
826+
return !memcg || css_tryget_online(&memcg->css);
827+
}
828+
824829
static inline void mem_cgroup_put(struct mem_cgroup *memcg)
825830
{
826831
if (memcg)
@@ -1349,6 +1354,11 @@ static inline bool mem_cgroup_tryget(struct mem_cgroup *memcg)
13491354
return true;
13501355
}
13511356

1357+
static inline bool mem_cgroup_tryget_online(struct mem_cgroup *memcg)
1358+
{
1359+
return true;
1360+
}
1361+
13521362
static inline void mem_cgroup_put(struct mem_cgroup *memcg)
13531363
{
13541364
}

0 commit comments

Comments
 (0)