From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Yury Norov <yury.norov@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org,
Valentin Schneider <vschneid@redhat.com>,
Mel Gorman <mgorman@suse.de>,
Steven Rostedt <rostedt@goodmis.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Ben Segall <bsegall@google.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Dmitry Vyukov <dvyukov@google.com>,
Marco Elver <elver@google.com>
Subject: Re: [RFC PATCH 2/2] sched: Improve cache locality of RSEQ concurrency IDs for intermittent workloads
Date: Wed, 4 Sep 2024 14:28:05 -0400 [thread overview]
Message-ID: <1a1e06d4-7f41-4f37-a9b5-d1610e8d8669@efficios.com> (raw)
In-Reply-To: <46d08f8e-bd68-44a3-9b33-ba029c7e2a10@efficios.com>
On 2024-09-04 11:50, Mathieu Desnoyers wrote:
> On 2024-09-04 11:24, Yury Norov wrote:
[...]
>>
>> This all doesn't look like a hot path. And anyways, speculating around
>> performance without numbers on hands sounds cheap.
>
> This is done whenever userspace invokes sched_setaffinity, or changes
> its cgroup cpuset. It may not be the most important fast-path in the
> world, but I expect some workloads to issue sched_setaffinity whenever
> they create a thread, so it's not a purely slow-path either.
>
>> In my experience, iterators with a very lightweight payload are ~100
>> times slower comparing to dedicated bitmap ops. Check this for example:
>> 3cea8d4753277.
>>
>> If you're really cared about performance here, I'd suggest you to
>> compare your iterators approach with something like this:
>>
>> cpumask_or(mm_allowed, mm_allowed, cpumask);
>> atomic_set(&mm->nr_cpus_allowed, cpumask_weight(mm_allowed);
Here are the benchmark results. Each test use two entirely filled
bitmaps as input to mimic the common scenario for cpus allowed
being updated with a subset of the original process CPUs allowed,
and also the common case where the initial cpumask is filled.
#define BITMAP_LEN (4096UL * 8 * 10)
(len = BITMAP_LEN)
* Approach 1:
int nr_set = 0;
for_each_andnot_bit(bit, bitmap, bitmap2, len)
nr_set += !test_and_set_bit(bit, bitmap2);
if (nr_set)
atomic_add(nr_set, &total);
Time: 4680 ns
* Approach 2:
int nr_set = 0;
for_each_set_bit(bit, bitmap, len)
nr_set += !test_and_set_bit(bit, bitmap2);
if (nr_set)
atomic_add(nr_set, &total);
Time: 1791537 ns
* Approach 3:
mutex_lock(&lock);
bitmap_or(bitmap2, bitmap, bitmap2, len);
atomic_set(&total, bitmap_weight(bitmap2, len));
mutex_unlock(&lock);
Time: 79591 ns
So approach 1 is 382 times faster than approach 2, and 17 times
faster than approach 3. And this is only single-threaded,
I expect approaches 2&3 to perform even worse when contended
due to the many fully ordered test_and_set_bit (2) and due to
locking (3).
The test hardware is a AMD EPYC 9654 96-Core Processor.
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
next prev parent reply other threads:[~2024-09-04 18:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-03 19:06 [RFC PATCH 0/2] sched: Improve cache locality of RSEQ concurrency IDs Mathieu Desnoyers
2024-09-03 19:06 ` [RFC PATCH 1/2] cpumask: Implement cpumask_next_andnot Mathieu Desnoyers
2024-09-03 19:28 ` Yury Norov
2024-09-04 0:47 ` Mathieu Desnoyers
2024-09-03 19:06 ` [RFC PATCH 2/2] sched: Improve cache locality of RSEQ concurrency IDs for intermittent workloads Mathieu Desnoyers
2024-09-03 19:59 ` Yury Norov
2024-09-03 23:22 ` Mathieu Desnoyers
2024-09-04 15:24 ` Yury Norov
2024-09-04 15:50 ` Mathieu Desnoyers
2024-09-04 18:28 ` Mathieu Desnoyers [this message]
2024-09-05 13:36 ` Mathieu Desnoyers
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=1a1e06d4-7f41-4f37-a9b5-d1610e8d8669@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yury.norov@gmail.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
all inboxes | Powered by JetHome®