Skip to contentSkip to conversation

debugobjects: install cpu hotplug callback

PATCH Superseded [email protected] 3 participants 4 messages Aug 27, 2020 – Sep 4, 2020

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 debugobjects: install cpu hotplug callback

From: Zqiang <[email protected]>

Due to cpu hotplug, it may never be online after it's offline, some objects in percpu pool is never free, in order to avoid this happening, install cpu hotplug callback, call this callback func to free objects in percpu pool when cpu going offline.

---
v1->v2:
Modify submission information.

 include/linux/cpuhotplug.h |  1 +
 lib/debugobjects.c         | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
include/linux/cpuhotplug.h +1 -0
index a2710e654b64..2e77db655cfa 100644
@@ -36,6 +36,7 @@ enum cpuhp_state {
 	CPUHP_X86_MCE_DEAD,
 	CPUHP_VIRT_NET_DEAD,
 	CPUHP_SLUB_DEAD,
+	CPUHP_DEBUG_OBJ_DEAD,
 	CPUHP_MM_WRITEBACK_DEAD,
 	CPUHP_MM_VMSTAT_DEAD,
 	CPUHP_SOFTIRQ_DEAD,
lib/debugobjects.c +23 -0
index fe4557955d97..50e21ed0519e 100644
@@ -19,6 +19,7 @@
 #include <linux/slab.h>
 #include <linux/hash.h>
 #include <linux/kmemleak.h>
+#include <linux/cpu.h>
 
 #define ODEBUG_HASH_BITS	14
 #define ODEBUG_HASH_SIZE	(1 << ODEBUG_HASH_BITS)
@@ -433,6 +434,23 @@ static void free_object(struct debug_obj *obj)
 	}
 }
 
+#if defined(CONFIG_HOTPLUG_CPU)
+static int object_cpu_offline(unsigned int cpu)
+{
+	struct debug_percpu_free *percpu_pool;
+	struct hlist_node *tmp;
+	struct debug_obj *obj;
+
+	percpu_pool = per_cpu_ptr(&percpu_obj_pool, cpu);
+	hlist_for_each_entry_safe(obj, tmp, &percpu_pool->free_objs, node) {
+		hlist_del(&obj->node);
+		kmem_cache_free(obj_cache, obj);
+	}
+
+	return 0;
+}
+#endif
+
 /*
  * We run out of memory. That means we probably have tons of objects
  * allocated.
@@ -1367,6 +1385,11 @@ void __init debug_objects_mem_init(void)
 	} else
 		debug_objects_selftest();
 
+#if defined(CONFIG_HOTPLUG_CPU)
+	cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
+					object_cpu_offline);
+#endif
+
 	/*
 	 * Increase the thresholds for allocating and freeing objects
 	 * according to the number of possible CPUs available in the system.
Signature · 1 line
2.17.1
#1 lore raw

tglx please review.

Thanks
Qiang
________________________________________
发件人: [email protected] <[email protected]> 代表 [email protected] <[email protected]> 发送时间: 2020年8月27日 13:06
收件人: [email protected]; [email protected]; [email protected]
抄送: [email protected]
主题: [PATCH v2] debugobjects: install cpu hotplug callback

From: Zqiang <[email protected]>

Due to cpu hotplug, it may never be online after it's offline, some objects in percpu pool is never free, in order to avoid this happening, install cpu hotplug callback, call this callback func to free objects in percpu pool when cpu going offline.

---
v1->v2:
Modify submission information.

 include/linux/cpuhotplug.h |  1 +
 lib/debugobjects.c         | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
include/linux/cpuhotplug.h +1 -0
index a2710e654b64..2e77db655cfa 100644
@@ -36,6 +36,7 @@ enum cpuhp_state {
        CPUHP_X86_MCE_DEAD,
        CPUHP_VIRT_NET_DEAD,
        CPUHP_SLUB_DEAD,
+       CPUHP_DEBUG_OBJ_DEAD,
        CPUHP_MM_WRITEBACK_DEAD,
        CPUHP_MM_VMSTAT_DEAD,
        CPUHP_SOFTIRQ_DEAD,
lib/debugobjects.c +23 -0
index fe4557955d97..50e21ed0519e 100644
@@ -19,6 +19,7 @@
 #include <linux/slab.h>
 #include <linux/hash.h>
 #include <linux/kmemleak.h>
+#include <linux/cpu.h>
 
 #define ODEBUG_HASH_BITS       14
 #define ODEBUG_HASH_SIZE       (1 << ODEBUG_HASH_BITS)
@@ -433,6 +434,23 @@ static void free_object(struct debug_obj *obj)
        }
 }
 
+#if defined(CONFIG_HOTPLUG_CPU)
+static int object_cpu_offline(unsigned int cpu)
+{
+       struct debug_percpu_free *percpu_pool;
+       struct hlist_node *tmp;
+       struct debug_obj *obj;
+
+       percpu_pool = per_cpu_ptr(&percpu_obj_pool, cpu);
+       hlist_for_each_entry_safe(obj, tmp, &percpu_pool->free_objs, node) {
+               hlist_del(&obj->node);
+               kmem_cache_free(obj_cache, obj);
+       }
+
+       return 0;
+}
+#endif
+
 /*
  * We run out of memory. That means we probably have tons of objects
  * allocated.
@@ -1367,6 +1385,11 @@ void __init debug_objects_mem_init(void)
        } else
                debug_objects_selftest();
 
+#if defined(CONFIG_HOTPLUG_CPU)
+       cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
+                                       object_cpu_offline);
+#endif
+
        /*
         * Increase the thresholds for allocating and freeing objects
         * according to the number of possible CPUs available in the system.

--
2.17.1

#2 lore raw
Quoted 11 lines · Zhang, Qiang

tglx please review.

Thanks
Qiang
________________________________________
发件人: [email protected] <[email protected]> 代表 [email protected] <[email protected]> 发送时间: 2020年8月27日 13:06
收件人: [email protected]; [email protected]; [email protected]
抄送: [email protected]
主题: [PATCH v2] debugobjects: install cpu hotplug callback

Quoted 6 lines

From: Zqiang <[email protected]>

Due to cpu hotplug, it may never be online after it's offline, some objects in percpu pool is never free, in order to avoid this happening, install cpu hotplug callback, call this callback func to free objects in percpu pool when cpu going offline.

We capitalize 'CPU'. Also, please split this in at least two sentences.

Quoted 44 lines

---
v1->v2:
Modify submission information.

 include/linux/cpuhotplug.h |  1 +
 lib/debugobjects.c         | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
include/linux/cpuhotplug.h +1 -0
index a2710e654b64..2e77db655cfa 100644
@@ -36,6 +36,7 @@ enum cpuhp_state {
        CPUHP_X86_MCE_DEAD,
        CPUHP_VIRT_NET_DEAD,
        CPUHP_SLUB_DEAD,
+       CPUHP_DEBUG_OBJ_DEAD,
        CPUHP_MM_WRITEBACK_DEAD,
        CPUHP_MM_VMSTAT_DEAD,
        CPUHP_SOFTIRQ_DEAD,
lib/debugobjects.c +7 -0
index fe4557955d97..50e21ed0519e 100644
@@ -19,6 +19,7 @@
 #include <linux/slab.h>
 #include <linux/hash.h>
 #include <linux/kmemleak.h>
+#include <linux/cpu.h>
 
 #define ODEBUG_HASH_BITS       14
 #define ODEBUG_HASH_SIZE       (1 << ODEBUG_HASH_BITS)
@@ -433,6 +434,23 @@ static void free_object(struct debug_obj *obj)
        }
 }
 
+#if defined(CONFIG_HOTPLUG_CPU)
+static int object_cpu_offline(unsigned int cpu)
+{
+       struct debug_percpu_free *percpu_pool;
+       struct hlist_node *tmp;
+       struct debug_obj *obj;

lib/debugobjects.c static void free_object(struct debug_obj *obj) · line 452

Quoted 10 lines
lib/debugobjects.c +10 -0
+
+       percpu_pool = per_cpu_ptr(&percpu_obj_pool, cpu);
+       hlist_for_each_entry_safe(obj, tmp, &percpu_pool->free_objs, node) {
+               hlist_del(&obj->node);
+               kmem_cache_free(obj_cache, obj);
+       }
+
+       return 0;
+}
+#endif

What happens to ->obj_free, if the CPU is brought back online? Won't it be out of sync at that point?

lib/debugobjects.c static void free_object(struct debug_obj *obj) · line 453

Quoted 1 line
lib/debugobjects.c +1 -0
+#if defined(CONFIG_HOTPLUG_CPU)

There's a shorter preprocessor sequence for that pattern.

Thanks,

Ingo

#3 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 11 lines
lib/debugobjects.c +11 -0
+#if defined(CONFIG_HOTPLUG_CPU)
+static int object_cpu_offline(unsigned int cpu)
+{
+       struct debug_percpu_free *percpu_pool;
+       struct hlist_node *tmp;
+       struct debug_obj *obj;
+
+       percpu_pool = per_cpu_ptr(&percpu_obj_pool, cpu);
+       hlist_for_each_entry_safe(obj, tmp, &percpu_pool->free_objs, node) {
+               hlist_del(&obj->node);
+               kmem_cache_free(obj_cache, obj);
Quoted 8 lines

lib/debugobjects.c static void free_object(struct debug_obj *obj) · line 452

Quoted 5 lines
lib/debugobjects.c +5 -0
+       }
+
+       return 0;
+}
+#endif

What happens to ->obj_free, if the CPU is brought back online? Won't it be out of sync at that point?

Yes and it's going to do the completely wrong thing.

Thanks,

tglx