Skip to contentSkip to conversation

workqueue: Use the kmem_cache_free() instead of kfree() to release pwq

PATCH Applied Zqiang 2 participants 2 messages Oct 11, 2023 – Oct 12, 2023 Workqueue

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH v2 1/1 workqueue: Use the kmem_cache_free() instead of kfree() to release pwq

Currently, the kfree() be used for pwq objects allocated with kmem_cache_alloc() in alloc_and_link_pwqs(), this isn't wrong. but usually, use "trace_kmem_cache_alloc/trace_kmem_cache_free" to track memory allocation and free. this commit therefore use kmem_cache_free() instead of kfree() in alloc_and_link_pwqs() and also consistent with release of the pwq in rcu_free_pwq().

---
 kernel/workqueue.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/workqueue.c +6 -2
index ebe24a5e1435..6f74cab2bd5a 100644
@@ -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
maintainer Applied
#1 lore raw
Quoted 8 lines · Zqiang

Currently, the kfree() be used for pwq objects allocated with kmem_cache_alloc() in alloc_and_link_pwqs(), this isn't wrong. but usually, use "trace_kmem_cache_alloc/trace_kmem_cache_free" to track memory allocation and free. this commit therefore use kmem_cache_free() instead of kfree() in alloc_and_link_pwqs() and also consistent with release of the pwq in rcu_free_pwq().

Applied to wq/for-6.6-fixes.

Thanks.

Signature · 1 line
tejun