2020-06-01 08:48:31

by Lai Jiangshan

[permalink] [raw]
Subject: [PATCH 0/4] workqueue: reduce the sizeof pool_workqueue

The major memory ussage in workqueue is on the pool_workqueue.
The pool_workqueue has alignment requirement which often leads
to padding.

Reducing the memory usage for the pool_workqueue is valuable.

And 32bit system often has less memory, less workqueues,
less works, less concurrent flush_workqueue()s, so we can
slash the flush color on 32bit system to reduce memory usage

Before patch:
The sizeof the struct pool_workqueue is 256 bytes,
only 136 bytes is in use in 32bit system

After patch:
The sizeof the struct pool_workqueue is 128 bytes,
only 104 bytes is in use in 32bit system, there is still
room for future usage.

Setting WORK_STRUCT_COLOR_BITS to 3 can't reduce the sizeof
the struct pool_workqueue in 64bit system, unless combined
with big refactor for unbound pwq.

Lai Jiangshan (4):
workqueue: fix a piece of comment about reserved bits for work flags
workqueue: use BUILD_BUG_ON() for compile time test instead of
WARN_ON()
workqueue: add a BUILD_BUG_ON() to check the size of struct
pool_workqueue
workqueue: slash half memory usage in 32bit system

Cc: Tejun Heo <[email protected]>

include/linux/workqueue.h | 8 +++++++-
kernel/workqueue.c | 10 +++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)

--
2.20.1


2020-06-01 08:49:03

by Lai Jiangshan

[permalink] [raw]
Subject: [PATCH 2/4] workqueue: use BUILD_BUG_ON() for compile time test instead of WARN_ON()

Any runtime WARN_ON() has to be fixed, and BUILD_BUG_ON() can
help you nitice it earlier.

Signed-off-by: Lai Jiangshan <[email protected]>
---
kernel/workqueue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 7a1fc9fe6314..35120b909234 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5905,7 +5905,7 @@ void __init workqueue_init_early(void)
int hk_flags = HK_FLAG_DOMAIN | HK_FLAG_WQ;
int i, cpu;

- WARN_ON(__alignof__(struct pool_workqueue) < __alignof__(long long));
+ BUILD_BUG_ON(__alignof__(struct pool_workqueue) < __alignof__(long long));

BUG_ON(!alloc_cpumask_var(&wq_unbound_cpumask, GFP_KERNEL));
cpumask_copy(wq_unbound_cpumask, housekeeping_cpumask(hk_flags));
--
2.20.1

2020-06-01 08:49:28

by Lai Jiangshan

[permalink] [raw]
Subject: [PATCH 1/4] workqueue: fix a piece of comment about reserved bits for work flags

8a2e8e5dec7e("workqueue: fix cwq->nr_active underflow")
allocated one more bit from the work flags, and it updated
partial of the comments (128 bytes -> 256 bytes), but it
failed to update the info about the number of reserved bits.

Signed-off-by: Lai Jiangshan <[email protected]>
---
include/linux/workqueue.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 8b505d22fc0e..26de0cae2a0a 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -62,7 +62,7 @@ enum {
WORK_CPU_UNBOUND = NR_CPUS,

/*
- * Reserve 7 bits off of pwq pointer w/ debugobjects turned off.
+ * Reserve 8 bits off of pwq pointer w/ debugobjects turned off.
* This makes pwqs aligned to 256 bytes and allows 15 workqueue
* flush colors.
*/
--
2.20.1

2020-06-01 15:11:07

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH 2/4] workqueue: use BUILD_BUG_ON() for compile time test instead of WARN_ON()

On Mon, Jun 01, 2020 at 08:44:40AM +0000, Lai Jiangshan wrote:
> Any runtime WARN_ON() has to be fixed, and BUILD_BUG_ON() can
> help you nitice it earlier.
>
> Signed-off-by: Lai Jiangshan <[email protected]>

Applied 1-2 to wq/for-5.8.

Thanks.

--
tejun