From: Waiman Long <longman@redhat.com>
To: Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
Joe Mario <jmario@redhat.com>, Sebastian Jug <sejug@redhat.com>,
Yosry Ahmed <yosryahmed@google.com>,
Waiman Long <longman@redhat.com>
Subject: [PATCH v4 3/3] cgroup: Avoid false cacheline sharing of read mostly rstat_cpu
Date: Mon, 6 Nov 2023 16:05:43 -0500 [thread overview]
Message-ID: <20231106210543.717486-4-longman@redhat.com> (raw)
In-Reply-To: <20231106210543.717486-1-longman@redhat.com>
The rstat_cpu and also rstat_css_list of the cgroup structure are read
mostly variables. However, they may share the same cacheline as the
subsequent rstat_flush_next and *bstat variables which can be updated
frequently. That will slow down the cgroup_rstat_cpu() call which is
called pretty frequently in the rstat code. Add a CACHELINE_PADDING()
line in between them to avoid false cacheline sharing.
A parallel kernel build on a 2-socket x86-64 server is used as the
benchmarking tool for measuring the lock hold time. Below were the lock
hold time frequency distribution before and after the patch:
Run time Before patch After patch
-------- ------------ -----------
0-01 us 14,594,545 15,484,707
01-05 us 439,926 207,382
05-10 us 5,960 3,174
10-15 us 3,543 3,006
15-20 us 1,397 1,066
20-25 us 25 15
25-30 us 12 10
It can be seen that the patch further pushes the lock hold time towards
the lower end.
Signed-off-by: Waiman Long <longman@redhat.com>
---
include/linux/cgroup-defs.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index ff4b4c590f32..a4adc0580135 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -491,6 +491,13 @@ struct cgroup {
struct cgroup_rstat_cpu __percpu *rstat_cpu;
struct list_head rstat_css_list;
+ /*
+ * Add padding to separate the read mostly rstat_cpu and
+ * rstat_css_list into a different cacheline from the following
+ * rstat_flush_next and *bstat fields which can have frequent updates.
+ */
+ CACHELINE_PADDING(_pad_);
+
/*
* A singly-linked list of cgroup structures to be rstat flushed.
* This is a scratch field to be used exclusively by
--
2.39.3
prev parent reply other threads:[~2023-11-06 21:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-06 21:05 [PATCH v4 0/3] cgroup/rstat: Reduce cpu_lock hold time in cgroup_rstat_flush_locked() Waiman Long
2023-11-06 21:05 ` [PATCH v4 1/3] " Waiman Long
2023-11-06 21:05 ` [PATCH v4 2/3] cgroup/rstat: Optimize cgroup_rstat_updated_list() Waiman Long
2023-11-28 4:01 ` Waiman Long
2023-11-28 16:43 ` Tejun Heo
2023-11-28 16:46 ` Waiman Long
2023-11-06 21:05 ` Waiman Long [this message]
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=20231106210543.717486-4-longman@redhat.com \
--to=longman@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=jmario@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=sejug@redhat.com \
--cc=tj@kernel.org \
--cc=yosryahmed@google.com \
/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).