linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@linux.alibaba.com>
To: linux-kernel@vger.kernel.org
Cc: Lai Jiangshan <laijs@linux.alibaba.com>,
	Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>
Subject: [PATCH 4/4] workqueue: slash half memory usage in 32bit system
Date: Mon,  1 Jun 2020 08:44:42 +0000	[thread overview]
Message-ID: <20200601084442.8284-5-laijs@linux.alibaba.com> (raw)
In-Reply-To: <20200601084442.8284-1-laijs@linux.alibaba.com>

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.

Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
---
 include/linux/workqueue.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 26de0cae2a0a..c0f311926d01 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -39,7 +39,11 @@ enum {
 	WORK_STRUCT_COLOR_SHIFT	= 4,	/* color for workqueue flushing */
 #endif
 
+#if BITS_PER_LONG == 32
+	WORK_STRUCT_COLOR_BITS	= 3,
+#else
 	WORK_STRUCT_COLOR_BITS	= 4,
+#endif
 
 	WORK_STRUCT_PENDING	= 1 << WORK_STRUCT_PENDING_BIT,
 	WORK_STRUCT_DELAYED	= 1 << WORK_STRUCT_DELAYED_BIT,
@@ -65,6 +69,8 @@ enum {
 	 * Reserve 8 bits off of pwq pointer w/ debugobjects turned off.
 	 * This makes pwqs aligned to 256 bytes and allows 15 workqueue
 	 * flush colors.
+	 * For 32 bit system, the numbers are 7 bits, 128 bytes, 7 colors
+	 * respectively.
 	 */
 	WORK_STRUCT_FLAG_BITS	= WORK_STRUCT_COLOR_SHIFT +
 				  WORK_STRUCT_COLOR_BITS,
-- 
2.20.1


  parent reply	other threads:[~2020-06-01  8:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-01  8:44 [PATCH 0/4] workqueue: reduce the sizeof pool_workqueue Lai Jiangshan
2020-06-01  8:44 ` [PATCH 1/4] workqueue: fix a piece of comment about reserved bits for work flags Lai Jiangshan
2020-06-01  8:44 ` [PATCH 2/4] workqueue: use BUILD_BUG_ON() for compile time test instead of WARN_ON() Lai Jiangshan
2020-06-01 15:08   ` Tejun Heo
2020-06-01  8:44 ` [PATCH 3/4] workqueue: add a BUILD_BUG_ON() to check the size of struct pool_workqueue Lai Jiangshan
2020-06-01  8:44 ` Lai Jiangshan [this message]
2020-06-01 15:07   ` [PATCH 4/4] workqueue: slash half memory usage in 32bit system Tejun Heo
2020-06-02  0:08     ` Lai Jiangshan
2020-06-02 16:18       ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200601084442.8284-5-laijs@linux.alibaba.com \
    --to=laijs@linux.alibaba.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).