Merge tag 'mm-stable-2023-11-01-14-33' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / mm / percpu.c
index 60ed078e4cd06ae59e90f4a29f04dc4008d51234..7b97d31df76766f830c1da97427d54d81cea319b 100644 (file)
@@ -1628,14 +1628,12 @@ static bool pcpu_memcg_pre_alloc_hook(size_t size, gfp_t gfp,
        if (!memcg_kmem_online() || !(gfp & __GFP_ACCOUNT))
                return true;
 
-       objcg = get_obj_cgroup_from_current();
+       objcg = current_obj_cgroup();
        if (!objcg)
                return true;
 
-       if (obj_cgroup_charge(objcg, gfp, pcpu_obj_full_size(size))) {
-               obj_cgroup_put(objcg);
+       if (obj_cgroup_charge(objcg, gfp, pcpu_obj_full_size(size)))
                return false;
-       }
 
        *objcgp = objcg;
        return true;
@@ -1649,6 +1647,7 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg,
                return;
 
        if (likely(chunk && chunk->obj_cgroups)) {
+               obj_cgroup_get(objcg);
                chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = objcg;
 
                rcu_read_lock();
@@ -1657,7 +1656,6 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg,
                rcu_read_unlock();
        } else {
                obj_cgroup_uncharge(objcg, pcpu_obj_full_size(size));
-               obj_cgroup_put(objcg);
        }
 }