The patch titled Subject: mm/memcontrol.c: convert mem_cgroup_id::ref to refcount_t type has been added to the -mm tree. Its filename is mm-convert-mem_cgroup_id-ref-to-refcount_t-type.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-convert-mem_cgroup_id-ref-to-refcount_t-type.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-convert-mem_cgroup_id-ref-to-refcount_t-type.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx> Subject: mm/memcontrol.c: convert mem_cgroup_id::ref to refcount_t type This will allow to use generic refcount_t interfaces to check counters overflow instead of currently existing VM_BUG_ON(). The only difference after the patch is VM_BUG_ON() may cause BUG(), while refcount_t fires with WARN(). But this seems not to be significant here, since such the problems are usually caught by syzbot with panic-on-warn enabled. Link: http://lkml.kernel.org/r/153910718919.7006.13400779039257185427.stgit@localhost.localdomain Signed-off-by: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx> Reviewed-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Vladimir Davydov <vdavydov.dev@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/memcontrol.h | 2 +- mm/memcontrol.c | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) --- a/include/linux/memcontrol.h~mm-convert-mem_cgroup_id-ref-to-refcount_t-type +++ a/include/linux/memcontrol.h @@ -78,7 +78,7 @@ struct mem_cgroup_reclaim_cookie { struct mem_cgroup_id { int id; - atomic_t ref; + refcount_t ref; }; /* --- a/mm/memcontrol.c~mm-convert-mem_cgroup_id-ref-to-refcount_t-type +++ a/mm/memcontrol.c @@ -4299,14 +4299,12 @@ static void mem_cgroup_id_remove(struct static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n) { - VM_BUG_ON(atomic_read(&memcg->id.ref) <= 0); - atomic_add(n, &memcg->id.ref); + refcount_add(n, &memcg->id.ref); } static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n) { - VM_BUG_ON(atomic_read(&memcg->id.ref) < n); - if (atomic_sub_and_test(n, &memcg->id.ref)) { + if (refcount_sub_and_test(n, &memcg->id.ref)) { mem_cgroup_id_remove(memcg); /* Memcg ID pins CSS */ @@ -4523,7 +4521,7 @@ static int mem_cgroup_css_online(struct } /* Online state pins memcg ID, memcg ID pins CSS */ - atomic_set(&memcg->id.ref, 1); + refcount_set(&memcg->id.ref, 1); css_get(css); return 0; } @@ -6357,7 +6355,7 @@ subsys_initcall(mem_cgroup_init); #ifdef CONFIG_MEMCG_SWAP static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg) { - while (!atomic_inc_not_zero(&memcg->id.ref)) { + while (!refcount_inc_not_zero(&memcg->id.ref)) { /* * The root cgroup cannot be destroyed, so it's refcount must * always be >= 1. _ Patches currently in -mm which might be from ktkhai@xxxxxxxxxxxxx are scripts-tags-add-declare_hashtable.patch mm-convert-mem_cgroup_id-ref-to-refcount_t-type.patch