From: Oleg Nesterov <oleg@redhat.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: Peter Zijlstra <peterz@infradead.org>,
mingo@kernel.org, john.stultz@linaro.org, dimitrysh@google.com,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>
Subject: Re: [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer wakeups
Date: Wed, 23 Nov 2016 15:43:06 +0100 [thread overview]
Message-ID: <20161123144306.GA23738@redhat.com> (raw)
In-Reply-To: <20161122035911.GA17027@linux-80c1.suse>
On 11/21, Davidlohr Bueso wrote:
>
> On Mon, 21 Nov 2016, Oleg Nesterov wrote:
>
>> On 11/21, Oleg Nesterov wrote:
>>>
>>> No, no, I meant that afaics both readers can see per_cpu_sum() != 0 and
>>> thus the writer won't be woken up. Till the next down_read/up_read.
>>>
>>> Suppose that we have 2 CPU's, both counters == 1, both readers decrement.
>>> its counter at the same time.
>>>
>>> READER_ON_CPU_0 READER_ON_CPU_1
>>>
>>> --ctr_0; --ctr_1;
>>>
>>> if (ctr_0 + ctr_1) if (ctr_0 + ctr_1)
>>> wakeup(); wakeup();
>>>
>>> Why we can't miss a wakeup?
>
> But the patch is really: if (!(ctr_0 + ctr_1)).
Of course, I meant if (ctr_0 + ctr_1 == 0).
>> And in fact I am not sure this optimization makes sense... But it would be
>> nice to avoid wake_up() when the writer sleeps in rcu_sync_enter(). Or this
>> is the "slow mode" sem (cgroup_threadgroup_rwsem).
>
> Why do you think using per_cpu_sum() does not make sense? As mentioned in the
> changelog it optimizes for incoming readers while the writer is doing sync_enter
> and getting the regular rwsem. What am I missing?
And this does make sense, but see below,
>> I need to re-check, but what do you think about the change below?
>
> While optimizing for multiple writers (rcu_sync_enter) is certainly valid
> (at least considering the cgroups rwsem you mention),
No, it is not for multiple writers. rcu_sync_enter() is slow, the new
readers can come and acquire/release this lock. And if it is a "slow mode"
sem then every up() does wakeup which we want to eliminate.
But after sem->readers_block is already true, I am not sure the additional
per_cpu_sum() is a win (even if it was correct), the new readers can't come.
Except __percpu_down_read()->__percpu_up_read() which we want to optimize
too, but in this case we do not need per_cpu_sum() too.
I'll try to make a patch this week... I had this optimization in mind from
the very beginning, I event mentioned it during the last discussion, but
never had time. Basically we should not inc if readers_block == T.
Oleg.
prev parent reply other threads:[~2016-11-23 14:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-18 18:54 [PATCH -tip 0/3] locking/percpu-rwsem: writer-side optimizations Davidlohr Bueso
2016-11-18 18:54 ` [PATCH 1/3] locking/percpu-rwsem: Move text file into Documentation/locking/ Davidlohr Bueso
2016-11-18 18:54 ` [PATCH 2/3] locking/percpu-rwsem: Replace bulky wait-queues with swait Davidlohr Bueso
2016-11-21 12:55 ` Oleg Nesterov
2016-11-21 17:26 ` Davidlohr Bueso
2016-12-03 2:18 ` [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake to not use wait-queues Davidlohr Bueso
2016-12-05 8:36 ` Peter Zijlstra
2016-12-05 11:26 ` Oleg Nesterov
2016-12-05 11:32 ` Oleg Nesterov
2016-12-05 17:37 ` Davidlohr Bueso
2016-12-05 17:19 ` Oleg Nesterov
2016-12-05 17:13 ` Oleg Nesterov
2016-11-18 18:54 ` [PATCH 3/3] locking/percpu-rwsem: Avoid unnecessary writer wakeups Davidlohr Bueso
2016-11-21 12:23 ` Oleg Nesterov
2016-11-21 12:29 ` Peter Zijlstra
2016-11-21 12:47 ` Oleg Nesterov
2016-11-21 15:07 ` Oleg Nesterov
2016-11-22 3:59 ` Davidlohr Bueso
2016-11-23 14:43 ` Oleg Nesterov [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=20161123144306.GA23738@redhat.com \
--to=oleg@redhat.com \
--cc=dave@stgolabs.net \
--cc=dbueso@suse.de \
--cc=dimitrysh@google.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.