fixs/suggestions for workqueue subsystem.
cover fixs/suggestions for workqueue subsystem.
Here are several fixs/suggestions about workqueue subsystem.
I am a newcomer for workqueue, and have no idea about workqueue test. Do we have the better way (just like the test units)? These patches are very simple, and just come from code reading :).
wanghaibin (4):
workqueue: move the wq_update_unbound_numa_attrs_buf allocation
location.
workqueue: free the allocated memory resource when wq_numa_init
failed.
workqueue: remove the unbind workqueue attr sys_file before unregister
the workqueue device
workqueue: simplify the apply_workqueue_attrs_locked function.
kernel/workqueue.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
Signature · 1 line
1.8.3.1
RFC PATCH 1/4 workqueue: move the wq_update_unbound_numa_attrs_buf allocation location.
the wq_update_unbound_numa_attrs_buf will be useful, only when the wq_numa_enabled is true.
if there is something wrong to cause the wq_numa_enable false, it can just return without the wq_update_unbound_numa_attrs_buf allocation.
This doesn't introduce any functional changes.
--- kernel/workqueue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/workqueue.c +3 -3
@@ -5180,9 +5180,6 @@ static void __init wq_numa_init(void)return ; } - wq_update_unbound_numa_attrs_buf =alloc_workqueue_attrs (GFP_KERNEL ); -BUG_ON (!wq_update_unbound_numa_attrs_buf); -/* * We want masks of possible CPUs of each node which isn't readily * available. Build one from cpu_to_node() which should have been
@@ -5207,6 +5204,9 @@ static void __init wq_numa_init(void) wq_numa_possible_cpumask = tbl; wq_numa_enabled = true; + + wq_update_unbound_numa_attrs_buf =alloc_workqueue_attrs (GFP_KERNEL ); +BUG_ON (!wq_update_unbound_numa_attrs_buf); }static int __init init_workqueues (void )
Signature · 1 line
1.8.3.1
Tejun Heo
maintainerRe: [RFC PATCH 1/4] workqueue: move the wq_update_unbound_numa_attrs_buf allocation location.
Quoted 7 lines · wanghaibin
the
wq_update_unbound_numa_attrs_bufwill be useful, only when thewq_numa_enabledis true.
if there is something wrong to cause thewq_numa_enablefalse, it can just return without thewq_update_unbound_numa_attrs_bufallocation.This doesn't introduce any functional changes.
I don't see what the point is with this change.
Thanks.
Signature · 1 line
tejun
Re: [RFC PATCH 1/4] workqueue: move the wq_update_unbound_numa_attrs_buf allocation location.
Quoted 11 lines · Tejun Heo
Quoted 7 lines · wanghaibin
the
wq_update_unbound_numa_attrs_bufwill be useful, only when thewq_numa_enabledis true.
if there is something wrong to cause thewq_numa_enablefalse, it can just return without thewq_update_unbound_numa_attrs_bufallocation.This doesn't introduce any functional changes.
I don't see what the point is with this change.
What I Meant To Say, if (WARN_ON(node == NUMA_NO_NODE)) is true, this cause wq_numa_enabled to be set the false. That is, the wq_update_unbound_numa_attrs_buf will be useless.
It can free the the wq_update_unbound_numa_attrs_buf while the WARN_ON condition is true;
Or, better way is that only when the wq_numa_enabled is true, we will allocate the wq_update_unbound_numa_attrs_buf;
However, just like your said, the WARN_ON condition should never happen, Maybe this change is not useless too :) .
Quoted 2 lines
Thanks.
RFC PATCH 2/4 workqueue: free the allocated memory resource when wq_numa_init failed.
In reply to wanghaibinBefore the return that wq_numa_init failed, it will be bettet to free the numa node table to avoid the memory leaks.
--- kernel/workqueue.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/workqueue.c +4 -0
@@ -5195,6 +5195,10 @@ static void __init wq_numa_init(void)for_each_possible_cpu (cpu) { node =cpu_to_node (cpu);if (WARN_ON (node ==NUMA_NO_NODE )) { +for_each_node (node) +free_cpumask_var (tbl[node]); +kfree (tbl); +pr_warn ("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n" , cpu);/* happens iff arch is bonkers, let's just proceed */ return ;
Signature · 1 line
1.8.3.1
Tejun Heo
maintainerRe: [RFC PATCH 2/4] workqueue: free the allocated memory resource when wq_numa_init failed.
Quoted 2 lines · wanghaibin
Before the return that
wq_numa_initfailed, it will be bettet to free the numa node table to avoid the memory leaks.
That's a WARN_ON condition which should never happen. The system is already pretty messed up and just limping along. It really doesn't matter whether some memory is cleaned up or not. Let's keep it simple.
Thanks.
Signature · 1 line
tejun
Re: [RFC PATCH 2/4] workqueue: free the allocated memory resource when wq_numa_init failed.
Quoted 4 lines · Tejun Heo
Quoted 2 lines · wanghaibin
Before the return that
wq_numa_initfailed, it will be bettet to free the numa node table to avoid the memory leaks.
OK, I just expect that it can free the memory in all exception cases!
Quoted 4 lines
That's a
WARN_ONcondition which should never happen. The system is already pretty messed up and just limping along. It really doesn't matter whether some memory is cleaned up or not. Let's keep it simple.
OK, get it !
Quoted 3 lines
Thanks.
RFC PATCH 3/4 workqueue: remove the unbind workqueue attr sys_file before unregister the workqueue device
In reply to wanghaibinfor workqueue's flag with the WQ_SYSFS | WQ_UNBOUND, the wq_dev will create some sys_files for unbound attrs, so, remove the unbind workqueue attrs sys_files before unregister the workqueue device.
--- kernel/workqueue.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/workqueue.c +9 -1
@@ -5131,10 +5131,13 @@ int workqueue_sysfs_register(struct workqueue_struct *wq)if (wq->flags &WQ_UNBOUND ) {struct device_attribute *attr; +int cnt =0 , i; -for (attr = wq_sysfs_unbound_attrs; attr->attr.name; attr++) { +for (attr = wq_sysfs_unbound_attrs; attr->attr.name; attr++, cnt++) { ret =device_create_file (&wq_dev->dev, attr);if (ret) { +for (attr = wq_sysfs_unbound_attrs, i =0 ; i < cnt; attr++, i++) +device_remove_file (&wq_dev->dev, attr);device_unregister (&wq_dev->dev); wq->wq_dev =NULL ;return ret;
@@ -5160,6 +5163,11 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq)if (!wq->wq_dev)return ; +if (wq->flags &WQ_UNBOUND ) { +struct device_attribute *attr; +for (attr = wq_sysfs_unbound_attrs; attr->attr.name; attr++) +device_remove_file (&wq_dev->dev, attr); + } wq->wq_dev =NULL ;device_unregister (&wq_dev->dev); }
Signature · 1 line
1.8.3.1
Tejun Heo
maintainerRe: [RFC PATCH 3/4] workqueue: remove the unbind workqueue attr sys_file before unregister the workqueue device
Quoted 3 lines · wanghaibin
for workqueue's flag with the
WQ_SYSFS|WQ_UNBOUND, thewq_devwill create somesys_filesfor unbound attrs, so, remove the unbind workqueue attrssys_filesbefore unregister the workqueue device.
File removal on sysfs is recursive, right? Does explicitly removing file make any difference?
Signature · 1 line
tejun
Re: [RFC PATCH 3/4] workqueue: remove the unbind workqueue attr sys_file before unregister the workqueue device
Quoted 7 lines · Tejun Heo
Quoted 3 lines · wanghaibin
for workqueue's flag with the
WQ_SYSFS|WQ_UNBOUND, thewq_devwill create somesys_filesfor unbound attrs, so, remove the unbind workqueue attrssys_filesbefore unregister the workqueue device.File removal on sysfs is recursive, right? Does explicitly removing file make any difference?
Yes, It has been removed already, I made a mistake. Thanks.
Quoted 1 line
RFC PATCH 4/4 workqueue: simplify the apply_workqueue_attrs_locked function.
In reply to wanghaibinif the apply_wqattrs_prepare function return NULL, in its implement, it has already clear up the related resource, so, it can return failed directly, to avoid to call the clean up function again.
this doesn't introduce any functional changes, just a suggestion.
--- kernel/workqueue.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
kernel/workqueue.c +4 -7
@@ -3601,7 +3601,6 @@ static int apply_workqueue_attrs_locked(struct workqueue_struct *wq, const struct workqueue_attrs *attrs) {struct apply_wqattrs_ctx *ctx; -int ret = -ENOMEM ;/* only unbound workqueues can change attributes */ if (WARN_ON (!(wq->flags &WQ_UNBOUND )))
@@ -3612,16 +3611,14 @@ static int apply_workqueue_attrs_locked(struct workqueue_struct *wq,return -EINVAL ; ctx =apply_wqattrs_prepare (wq, attrs); +if (!ctx) +return -ENOMEM ;/* the ctx has been prepared successfully, let's commit it */ -if (ctx) { -apply_wqattrs_commit (ctx); - ret =0 ; - } - +apply_wqattrs_commit (ctx);apply_wqattrs_cleanup (ctx); -return ret; +return 0 ; }/**
Signature · 1 line
1.8.3.1
RFC PATCH 4/4 workqueue: simplify the apply_workqueue_attrs_locked function.
Hello,
Applied to wq/for-4.5 with some adjustments to patch title description.
Thanks.
------ 8< ------
Quoted 1 line
From
6201171e3b2c02992e62448636631a0dfe4e9d20Mon Sep 17 00:00:00 2001
From: wanghaibin <[email protected]>
Date: Thu, 7 Jan 2016 20:38:59 +0800
Subject: [PATCH] workqueue: simplify the apply_workqueue_attrs_locked()
If the apply_wqattrs_prepare() returns NULL, it has already cleaned up the related resources, so it can return directly and avoid calling the clean up function again.
This doesn't introduce any functional changes.
--- kernel/workqueue.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
kernel/workqueue.c +4 -7
@@ -3651,7 +3651,6 @@ static int apply_workqueue_attrs_locked(struct workqueue_struct *wq, const struct workqueue_attrs *attrs) {struct apply_wqattrs_ctx *ctx; -int ret = -ENOMEM ;/* only unbound workqueues can change attributes */ if (WARN_ON (!(wq->flags &WQ_UNBOUND )))
@@ -3662,16 +3661,14 @@ static int apply_workqueue_attrs_locked(struct workqueue_struct *wq,return -EINVAL ; ctx =apply_wqattrs_prepare (wq, attrs); +if (!ctx) +return -ENOMEM ;/* the ctx has been prepared successfully, let's commit it */ -if (ctx) { -apply_wqattrs_commit (ctx); - ret =0 ; - } - +apply_wqattrs_commit (ctx);apply_wqattrs_cleanup (ctx); -return ret; +return 0 ; }/**
Signature · 1 line
2.5.0