From: Hillf Danton <hdanton@sina.com>
To: Doug Anderson <dianders@chromium.org>
Cc: Waiman Long <longman@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Will Deacon <will@kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>, MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
Date: Fri, 22 Jul 2022 19:55:10 +0800 [thread overview]
Message-ID: <20220722115510.2101-1-hdanton@sina.com> (raw)
In-Reply-To: <CAD=FV=Xng_Mcd-9SaK29XSbsthDWLTR6sz53VEktAQFng6a27A@mail.gmail.com>
On Tue, 19 Jul 2022 08:30:02 -0700 Doug Anderson wrote:
>
> I haven't done any stress testing other than my test case, though, so
> I can't speak to whether there might be any other unintended issues.
The diff below is prepared for any regressions I can imagine in stress
tests by adding changes to both read and write acquirer slow pathes.
On the read side, make lock stealing more aggressive; on the other hand,
write acquirers try to set HANDOFF after a RWSEM_WAIT_TIMEOUT nap to
force the reader acquirers to take the slow path.
Hillf
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -992,13 +992,7 @@ rwsem_down_read_slowpath(struct rw_semap
struct rwsem_waiter waiter;
DEFINE_WAKE_Q(wake_q);
- /*
- * To prevent a constant stream of readers from starving a sleeping
- * waiter, don't attempt optimistic lock stealing if the lock is
- * currently owned by readers.
- */
- if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) &&
- (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED))
+ if (WARN_ON_ONCE(count & RWSEM_FLAG_READFAIL))
goto queue;
/*
@@ -1169,7 +1163,11 @@ rwsem_down_write_slowpath(struct rw_sema
goto trylock_again;
}
- schedule();
+ if (RWSEM_FLAG_HANDOFF & atomic_long_read(&sem->count))
+ schedule();
+ else
+ schedule_timeout(1 + RWSEM_WAIT_TIMEOUT);
+
lockevent_inc(rwsem_sleep_writer);
set_current_state(state);
trylock_again:
--
next prev parent reply other threads:[~2022-07-22 11:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20211116012912.723980-1-longman@redhat.com>
[not found] ` <CAD=FV=URCo5xv3k3jWbxV1uRkUU5k6bcnuB1puZhxayEyVc6-A@mail.gmail.com>
2022-07-19 10:41 ` Hillf Danton
2022-07-19 15:30 ` Doug Anderson
2022-07-22 11:55 ` Hillf Danton [this message]
2022-07-22 14:02 ` Doug Anderson
2022-07-23 0:17 ` Hillf Danton
2022-07-23 1:27 ` Hillf Danton
2022-08-05 17:14 ` Doug Anderson
2022-08-05 19:02 ` Waiman Long
2022-08-05 19:16 ` Doug Anderson
2022-08-30 16:18 ` Doug Anderson
2022-08-31 11:08 ` Hillf Danton
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=20220722115510.2101-1-hdanton@sina.com \
--to=hdanton@sina.com \
--cc=dave@stgolabs.net \
--cc=dianders@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=peterz@infradead.org \
--cc=will@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