workqueue: Make alloc_workqueue() unbound by default
Subsystems (2)
cover workqueue: Make alloc_workqueue() unbound by default
Hi,
This is a proposed change about the defualt behavior of alloc_workqueue(). Currently we enforce the use of WQ_PERCPU or WQ_UNBOUND. The pourpose of this change is make the default behavior unbound so that calling alloc_workqueue() without WQ_PERCPU results in an unbound workqueue.
After this step it would be possible remove WQ_UNBOUND from every alloc_workqueue().
I tested the code with a small crafted driver, and to me it looks good. Do you spot something I'm missed?
Thanks!
Marco Crivellari (2):
workqueue: Make unbound the default alloc_workqueue() behavior
docs: workqueue: Update WQ_PERCPU documentation
Documentation/core-api/workqueue.rst | 3 +- include/linux/workqueue.h | 8 ++-- kernel/workqueue.c | 68 ++++++++++------------------ 3 files changed, 30 insertions(+), 49 deletions(-)
Signature · 1 line
2.54.0
RFC PATCH 1/2 workqueue: Make unbound the default alloc_workqueue() behavior
The original behavior of alloc_workqueue() was to be per-CPU when WQ_UNBOUND was not specified.
Currently when alloc_workqueue() is called one among WQ_PERCPU or WQ_UNBOUND must be specified, this is enforced by a WARN_ON() and properly flag settings.
Move forwared the Workqueue refactoring changing the default Workqueue behavior from per-CPU to unbound when WQ_PERCPU is not present.
WQ_UNBOUND will be later removed from every alloc_workqueue() caller.
--- include/linux/workqueue.h | 8 ++--- kernel/workqueue.c | 68 ++++++++++++++------------------------- 2 files changed, 29 insertions(+), 47 deletions(-)
include/linux/workqueue.h +4 -4
@@ -577,7 +577,7 @@ alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, int max_active,* Pointer to the allocated workqueue on success, %NULL on failure. */ #define alloc_ordered_workqueue_lockdep_map(fmt, flags, lockdep_map, args...) \ - alloc_hooks(alloc_workqueue_lockdep_map(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags),\ + alloc_hooks(alloc_workqueue_lockdep_map(fmt, __WQ_ORDERED | (flags),\ 1, lockdep_map, ##args))#endif
@@ -595,14 +595,14 @@ alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, int max_active,* Pointer to the allocated workqueue on success, %NULL on failure. */ #define alloc_ordered_workqueue(fmt, flags, args...) \ - alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), 1, ##args) + alloc_workqueue(fmt, __WQ_ORDERED | (flags), 1, ##args) #define devm_alloc_ordered_workqueue(dev, fmt, flags, args...) \ - devm_alloc_workqueue(dev, fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), 1, ##args) + devm_alloc_workqueue(dev, fmt, __WQ_ORDERED | (flags), 1, ##args)#define create_workqueue (name) \ alloc_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_PERCPU, 1, (name))#define create_freezable_workqueue (name) \ - alloc_workqueue("%s", __WQ_LEGACY | WQ_FREEZABLE | WQ_UNBOUND | \ + alloc_workqueue("%s", __WQ_LEGACY | WQ_FREEZABLE | \ WQ_MEM_RECLAIM, 1, (name))#define create_singlethread_workqueue (name) \ alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name)
kernel/workqueue.c +25 -43
214 lines not on this page · raw message
Signature · 1 line
2.54.0
RFC PATCH 2/2 docs: workqueue: Update WQ_PERCPU documentation
In reply to Marco CrivellariUpdate WQ_PERCPU documentation putting toghether the unbound description, but removing the WQ_UNBOUND title, because this will now be the default workqueue behavior.
--- Documentation/core-api/workqueue.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/core-api/workqueue.rst +1 -2
@@ -187,9 +187,8 @@ resources, scheduled and executed. Work items queued to a per-cpu wq are bound to a specific CPU. This flag is the right choice when cpu locality is important. - This flag is the complement of ``WQ_UNBOUND``. + Workqueue allocated without ``WQ_PERCPU`` are unbound by default. -``WQ_UNBOUND`` Work items queued to an unbound wq are served by the special worker-pools which host workers which are not bound to any specific CPU. This makes the wq behave as a simple execution
Signature · 1 line
2.54.0
Tejun Heo
maintainerHello, Marco.
Can we hold off on the next tree-wide sweep until we settle the direction on the percpu/unbound unification? The change itself is behavior-neutral and dropping WQ_UNBOUND eventually makes sense, so no objection to the goal, I'd just rather not do another mass conversion before that's resolved.
As for the patch, why not start by just defaulting to WQ_UNBOUND when neither flag is specified, instead of inverting all the internal tests now?
Thanks.
--
tejun
Hello Tejun,
Quoted 5 lines · Tejun Heo
Hello, Marco.
Can we hold off on the next tree-wide sweep until we settle the direction on the percpu/unbound unification?
Yeah, no objections!
Quoted 3 lines
As for the patch, why not start by just defaulting to
WQ_UNBOUNDwhen neither flag is specified, instead of inverting all the internal tests now?
Ok, I will do as you suggested when we move forward with this.
Thanks!
Signature · 3 lines
Marco Crivellari SUSE Labs