[Devel] [PATCH v2] mm: Add RCU read brackets into memcg_uncharge_kmem()

Kirill Tkhai ktkhai at virtuozzo.com
Thu May 7 12:25:24 MSK 2020


Potentially, here can be last css refcnt, so we should
have stable memory to access parent pointer.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 mm/memcontrol.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 797cb8e6df6d..2fcfe7abaafc 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3508,6 +3508,7 @@ void memcg_uncharge_kmem(struct mem_cgroup *memcg,
 {
 	u64 kmem;
 
+	rcu_read_lock();
 	kmem = page_counter_uncharge(&memcg->kmem, nr_pages);
 
 	page_counter_uncharge(&memcg->memory, nr_pages);
@@ -3516,7 +3517,7 @@ void memcg_uncharge_kmem(struct mem_cgroup *memcg,
 
 	/* Not down to 0 */
 	if (kmem)
-		return;
+		goto unlock;
 
 	/*
 	 * Releases a reference taken in memcg_deactivate_kmem in case
@@ -3541,6 +3542,8 @@ void memcg_uncharge_kmem(struct mem_cgroup *memcg,
 		else
 			break;
 	}
+unlock:
+	rcu_read_unlock();
 }
 
 int __memcg_charge_slab(struct kmem_cache *s, gfp_t gfp, unsigned int nr_pages)




More information about the Devel mailing list