[RHEL7,COMMIT] mm: Add RCU read brackets into memcg_uncharge_kmem()

Submitted by Konstantin Khorenko on May 7, 2020, 6:30 p.m.

Details

Message ID 202005071830.047IU817007722@finist-ce7.sw.ru
State New
Series "mm: Move memcg_uncharge_kmem() to bottom of __memcg_uncharge_slab()"
Headers show

Commit Message

Konstantin Khorenko May 7, 2020, 6:30 p.m.
The commit is pushed to "branch-rh7-3.10.0-1127.vz7.150.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.vz7.150.8
------>
commit cd3eaf13e6373f690b75dd17a0bed42521475b46
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Thu May 7 21:30:07 2020 +0300

    mm: Add RCU read brackets into memcg_uncharge_kmem()
    
    Potentially, here can be last css refcnt, so we should
    have stable memory to access parent pointer.
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 mm/memcontrol.c | 7 +++++++
 1 file changed, 7 insertions(+)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 797cb8e6df6d7..e82c59f6a9840 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3525,7 +3525,13 @@  void memcg_uncharge_kmem(struct mem_cgroup *memcg,
 	 *
 	 * The memory barrier imposed by test&clear is paired with the
 	 * explicit one in memcg_kmem_mark_dead().
+	 *
+	 * We take RCU to remain memcg memory stable for parent dereferencing.
+	 * Parent's memory is stable even in case of page_counter_uncharge()
+	 * has decremented its last charged memory, because child dentry owns
+	 * parents's dentry refcnt.
 	 */
+	rcu_read_lock();
 	if (memcg_kmem_test_and_clear_dead(memcg))
 		css_put(&memcg->css);
 
@@ -3541,6 +3547,7 @@  void memcg_uncharge_kmem(struct mem_cgroup *memcg,
 		else
 			break;
 	}
+	rcu_read_unlock();
 }
 
 int __memcg_charge_slab(struct kmem_cache *s, gfp_t gfp, unsigned int nr_pages)