From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Mel Gorman <mgorman@techsingularity.net>
Cc: Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>,
Linux-RT <linux-rt-users@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] locking/rwbase: Prevent indefinite writer starvation
Date: Wed, 18 Jan 2023 16:25:57 +0100 [thread overview]
Message-ID: <Y8gPhTGkfCbGwoUu@linutronix.de> (raw)
In-Reply-To: <20230117165021.t5m7c2d6frbbfzig@techsingularity.net>
On 2023-01-17 16:50:21 [+0000], Mel Gorman wrote:
> diff --git a/kernel/locking/rwbase_rt.c b/kernel/locking/rwbase_rt.c
> index c201aadb9301..99d81e8d1f25 100644
> --- a/kernel/locking/rwbase_rt.c
> +++ b/kernel/locking/rwbase_rt.c
> @@ -65,6 +69,64 @@ static __always_inline int rwbase_read_trylock(struct rwbase_rt *rwb)
> return 0;
> }
>
> +/*
> + * Allow reader bias with a pending writer for a minimum of 4ms or 1 tick.
> + * This matches RWSEM_WAIT_TIMEOUT for the generic RWSEM implementation.
> + * The granularity is not exact as the lowest bit in rwbase_rt->waiter_timeout
> + * is used to detect recent DL / RT tasks taking a read lock.
> + */
> +#define RWBASE_RT_WAIT_TIMEOUT DIV_ROUND_UP(HZ, 250)
> +
> +static void __sched update_dlrt_reader(struct rwbase_rt *rwb)
> +{
> + /* No update required if DL / RT tasks already identified. */
> + if (rwb->waiter_timeout & 1)
> + return;
> +
> + /*
> + * Record a DL / RT task acquiring the lock for read. This may result
> + * in indefinite writer starvation but DL / RT tasks should avoid such
> + * behaviour.
> + */
> + if (rt_task(current)) {
> + struct rt_mutex_base *rtm = &rwb->rtmutex;
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave(&rtm->wait_lock, flags);
> + rwb->waiter_timeout |= 1;
Let me see of I parsed the whole logic right:
_After_ the RT reader acquired the lock, the lowest bit is set. This may
be immediately if the timeout did not occur yet.
With this flag set, all following reader incl. SCHED_OTHER will acquire
the lock.
If so, then I don't know why this is a good idea.
If _only_ the RT reader is allowed to acquire the lock while the writer
is waiting then it make sense to prefer the RT tasks. (So the check is
on current and not on the lowest bit).
All other (SCHED_OTHER) reader would have to block on the rtmutex after
the timeout. This makes sense to avoid the starvation.
If we drop that "we prefer the RT reader" then it would block on the
RTmutex. It will _still_ be preferred over the writer because it will be
enqueued before the writer in the queue due to its RT priority. The only
downside is that it has to wait until all readers are left.
So by allowing the RT reader to always acquire the lock as long as the
WRITER_BIAS isn't set, we would allow to enter early while the other
reader are still in and after the timeout you would only have RT reader
going in and out. All SCHED_OTHER reader block on the RTmutex.
I think I like this.
> + raw_spin_unlock_irqrestore(&rtm->wait_lock, flags);
> + }
> +}
> +
Sebastian
next prev parent reply other threads:[~2023-01-18 15:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-17 8:38 [PATCH v2] locking/rwbase: Prevent indefinite writer starvation Mel Gorman
[not found] ` <20230117105031.2512-1-hdanton@sina.com>
2023-01-17 12:18 ` Mel Gorman
2023-01-17 14:22 ` Sebastian Andrzej Siewior
2023-01-17 16:50 ` Mel Gorman
2023-01-18 10:45 ` Ingo Molnar
2023-01-18 16:00 ` Mel Gorman
2023-01-18 15:25 ` Sebastian Andrzej Siewior [this message]
2023-01-18 17:31 ` Mel Gorman
2023-01-19 8:25 ` Sebastian Andrzej Siewior
2023-01-19 11:02 ` Mel Gorman
2023-01-19 16:28 ` Sebastian Andrzej Siewior
2023-01-19 17:41 ` Mel Gorman
2023-01-19 17:48 ` Davidlohr Bueso
2023-01-19 17:58 ` Davidlohr Bueso
2023-01-20 8:25 ` Sebastian Andrzej Siewior
2023-01-20 13:24 ` Mel Gorman
2023-01-20 13:38 ` Sebastian Andrzej Siewior
2023-01-20 14:07 ` Mel Gorman
2023-01-20 15:36 ` Davidlohr Bueso
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=Y8gPhTGkfCbGwoUu@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=dave@stgolabs.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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