debugobjects: install CPU hotplug callback
Subsystems (3)
PATCH v3 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.
v2->v3:
In CPU hotplug callback func, add clear percpu pool "obj_free" operation. capitalize 'CPU', and use shorter preprocessor sequence.
include/linux/cpuhotplug.h | 1 + lib/debugobjects.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)
include/linux/cpuhotplug.h +1 -0
@@ -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 +24 -0
@@ -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,24 @@ static void free_object(struct debug_obj *obj) } } +#ifdef 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); + } + percpu_pool->obj_free =0 ; + +return 0 ; +} +#endif +/* * We run out of memory. That means we probably have tons of objects * allocated.
@@ -1367,6 +1386,11 @@ void __init debug_objects_mem_init(void) }else debug_objects_selftest (); +#ifdef 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
Quoted 51 lines · On 9/8/20 2:27 AM, [email protected] wrote:
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.
Signed-off-by Zqiang <[email protected]>---
v1->v2:
Modify submission information.
v2->v3:
In CPU hotplug callback func, add clear percpu pool "obj_free" operation. capitalize 'CPU', and use shorter preprocessor sequence.include/linux/cpuhotplug.h | 1 + lib/debugobjects.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)include/linux/cpuhotplug.h +1
-0@@ -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 +4
-0@@ -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,24 @@ static void free_object(struct debug_obj *obj) } } +#ifdef CONFIG_HOTPLUG_CPU +static int object_cpu_offline (unsigned int cpu) +{
lib/debugobjects.c static void free_object(struct debug_obj *obj) · line 449
Quoted 10 lines
lib/debugobjects.c +10
-0+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); + } + percpu_pool->obj_free =0 ;
For pointer, it is better to use NULL for clarity.
Cheers,
Longman
Quoted 20 lines
lib/debugobjects.c +10
-0+ + return 0; +} +#endif +/* * We run out of memory. That means we probably have tons of objects * allocated. @@ -1367,6 +1386,11 @@ void __init debug_objects_mem_init(void) }else debug_objects_selftest (); +#ifdef 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.
________________________________________
发件人: Waiman Long <[email protected]>
发送时间: 2020年9月9日 2:23
收件人: Zhang, Qiang; [email protected]; [email protected]; [email protected] 抄送: [email protected]
主题: Re: [PATCH v3] debugobjects: install CPU hotplug callback
Quoted 64 lines · On 9/8/20 2:27 AM, [email protected] wrote:
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.
Signed-off-by Zqiang <[email protected]>---
v1->v2:
Modify submission information.
v2->v3:
In CPU hotplug callback func, add clear percpu pool "obj_free" operation. capitalize 'CPU', and use shorter preprocessor sequence.include/linux/cpuhotplug.h | 1 + lib/debugobjects.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)include/linux/cpuhotplug.h +1
-0@@ -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 +14
-0@@ -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,24 @@ static void free_object(struct debug_obj *obj) } } +#ifdef 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); + } + percpu_pool->obj_free =0 ;Quoted 1 line
For pointer, it is better to use NULL for clarity.
Quoted 2 lines
Quoted 2 lines
Cheers,
Longman
Do you mean "->obj_free" variable ? this represents the number of free objects in percpu_pool .
Quoted 20 lines
lib/debugobjects.c +10
-0+ + return 0; +} +#endif +/* * We run out of memory. That means we probably have tons of objects * allocated. @@ -1367,6 +1386,11 @@ void __init debug_objects_mem_init(void) }else debug_objects_selftest (); +#ifdef 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.
Quoted 70 lines · Qiang
________________________________________
发件人: Waiman Long <[email protected]>
发送时间: 2020年9月9日 2:23
收件人: Zhang, Qiang; [email protected]; [email protected]; [email protected] 抄送: [email protected]
主题: Re: [PATCH v3] debugobjects: install CPU hotplug callbackQuoted 61 lines · On 9/8/20 2:27 AM, [email protected] wrote:
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.
Signed-off-by Zqiang <[email protected]>---
v1->v2:
Modify submission information.
v2->v3:
In CPU hotplug callback func, add clear percpu pool "obj_free" operation. capitalize 'CPU', and use shorter preprocessor sequence.include/linux/cpuhotplug.h | 1 + lib/debugobjects.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)include/linux/cpuhotplug.h +1
-0@@ -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 +14
-0@@ -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,24 @@ static void free_object(struct debug_obj *obj) } } +#ifdef 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); + } + percpu_pool->obj_free =0 ;
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
For pointer, it is better to use NULL for clarity. Cheers,
LongmanDo you mean "->obj_free" variable ? this represents the number of free objects in
percpu_pool.
You are right. I got confused. Sorry for the noise.
Cheers,
Longman
________________________________________
发件人: Waiman Long <[email protected]>
发送时间: 2020年9月10日 10:50
收件人: Zhang, Qiang; [email protected]; [email protected]; [email protected] 抄送: [email protected]
主题: Re: 回复: [PATCH v3] debugobjects: install CPU hotplug callback
Quoted 70 lines · Qiang
________________________________________
发件人: Waiman Long <[email protected]>
发送时间: 2020年9月9日 2:23
收件人: Zhang, Qiang; [email protected]; [email protected]; [email protected] 抄送: [email protected]
主题: Re: [PATCH v3] debugobjects: install CPU hotplug callbackQuoted 61 lines · On 9/8/20 2:27 AM, [email protected] wrote:
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.
Signed-off-by Zqiang <[email protected]>---
v1->v2:
Modify submission information.
v2->v3:
In CPU hotplug callback func, add clear percpu pool "obj_free" operation. capitalize 'CPU', and use shorter preprocessor sequence.include/linux/cpuhotplug.h | 1 + lib/debugobjects.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)include/linux/cpuhotplug.h +1
-0@@ -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 +14
-0@@ -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,24 @@ static void free_object(struct debug_obj *obj) } } +#ifdef 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); + } + percpu_pool->obj_free =0 ;
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
For pointer, it is better to use NULL for clarity. Cheers,
LongmanDo you mean "->obj_free" variable ? this represents the number of free objects in
percpu_pool.Quoted 4 lines
You are right. I got confused. Sorry for the noise.
Cheers,
Longman
Hello tglx, mingo
Is this patch acceptable?
Thanks
Qiang
[tip: core/debugobjects] debugobjects: Free per CPU pool after CPU unplug
In reply to [email protected]The following commit has been merged into the core/debugobjects branch of tip:
The following commit has been merged into the core/debugobjects branch of tip:
Commit-ID: 88451f2cd3cec2abc30debdf129422d2699d1eba Gitweb: https://git.kernel.org/tip/88451f2cd3cec2abc30debdf129422d2699d1eba Author: Zqiang <[email protected]> AuthorDate: Tue, 08 Sep 2020 14:27:09 +08:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 01 Oct 2020 16:13:54 +02:00
debugobjects: Free per CPU pool after CPU unplug
If a CPU is offlined the debug objects per CPU pool is not cleaned up. If the CPU is never onlined again then the objects in the pool are wasted.
Add a CPU hotplug callback which is invoked after the CPU is dead to free the pool.
[ tglx: Massaged changelog and added comment about remote access safety ]
--- include/linux/cpuhotplug.h | 1 + lib/debugobjects.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+)
include/linux/cpuhotplug.h +1 -0
@@ -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 +25 -0
@@ -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,25 @@ static void free_object(struct debug_obj *obj) } } +#ifdef 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; + +/* Remote access is safe as the CPU is dead already */ + 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); + } + percpu_pool->obj_free =0 ; + +return 0 ; +} +#endif +/* * We run out of memory. That means we probably have tons of objects * allocated.
@@ -1367,6 +1387,11 @@ void __init debug_objects_mem_init(void) }else debug_objects_selftest (); +#ifdef 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.