workqueue: Use the kmem_cache_free() instead of kfree() to release pwq
PATCH 1/1 workqueue: Use the kmem_cache_free() instead of kfree() to release pwq
The pwq objects is allocated by kmem_cache_alloc(), this commit therefore use kmem_cache_free() instead of kfree() to release pwq objects and also make use the correct tracepoint("trace_kmem_cache_free") to trace the release of pwq.
--- kernel/workqueue.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/workqueue.c +6 -2
@@ -4610,8 +4610,12 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq) enomem:if (wq->cpu_pwq) { -for_each_possible_cpu (cpu) -kfree (*per_cpu_ptr (wq->cpu_pwq, cpu)); +for_each_possible_cpu (cpu) { +struct pool_workqueue *pwq = *per_cpu_ptr (wq->cpu_pwq, cpu); + +if (pwq) +kmem_cache_free (pwq_cache, pwq); + }free_percpu (wq->cpu_pwq); wq->cpu_pwq =NULL ; }
Signature · 1 line
2.17.1
Tejun Heo
maintainerQuoted 4 lines · Zqiang
The pwq objects is allocated by
kmem_cache_alloc(), this commit therefore usekmem_cache_free()instead ofkfree()to release pwq objects and also make use the correcttracepoint("trace_kmem_cache_free")to trace the release of pwq.
This isn't wrong. kfree() can be used for memory allocated with kmem_cache_alloc().
Thanks.
Signature · 1 line
tejun
Quoted 10 lines · Zqiang
Quoted 4 lines
The pwq objects is allocated by
kmem_cache_alloc(), this commit therefore usekmem_cache_free()instead ofkfree()to release pwq objects and also make use the correcttracepoint("trace_kmem_cache_free")to trace the release of pwq.This isn't wrong.
kfree()can be used for memory allocated withkmem_cache_alloc().
Yes, that's not wrong. but pwq is allocated by kmem_cache_alloc(), usually should use kmem_cache_free() to release, correspondingly, we can use 'trace_kmem_cache_alloc/trace_kmem_cache_free' to track, not using 'trace_kmem_cache_alloc/trace_kfree'.
And in rcu_free_pwq(), we use kmem_cache_free() to free pwq.
Thanks
Zqiang
Quoted 5 lines
Thanks.
--
tejun
Tejun Heo
maintainerQuoted 11 lines · Z qiang
Quoted 10 lines · Zqiang
Quoted 4 lines
The pwq objects is allocated by
kmem_cache_alloc(), this commit therefore usekmem_cache_free()instead ofkfree()to release pwq objects and also make use the correcttracepoint("trace_kmem_cache_free")to trace the release of pwq.This isn't wrong.
kfree()can be used for memory allocated withkmem_cache_alloc().
Quoted 5 lines
Yes, that's not wrong. but pwq is allocated by
kmem_cache_alloc(), usually should usekmem_cache_free()to release, correspondingly, we can use 'trace_kmem_cache_alloc/trace_kmem_cache_free' to track, not using 'trace_kmem_cache_alloc/trace_kfree'.
And inrcu_free_pwq(), we usekmem_cache_free()to free pwq.
Can you please update the patch description to clarify that the code is currently not broken but it's trying to make it nicer by unifying how they're freed?
Thanks.
Signature · 1 line
tejun