From: Mel Gorman <mgorman@techsingularity.net>
To: Hillf Danton <hdanton@sina.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
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: Tue, 17 Jan 2023 12:18:39 +0000 [thread overview]
Message-ID: <20230117121839.vnubhcrlms7pt2ab@techsingularity.net> (raw)
In-Reply-To: <20230117105031.2512-1-hdanton@sina.com>
On Tue, Jan 17, 2023 at 06:50:31PM +0800, Hillf Danton wrote:
> On Tue, 17 Jan 2023 08:38:17 +0000 Mel Gorman <mgorman@techsingularity.net>
> > +/*
> > + * Allow reader bias with a pending writer for a minimum of 4ms or 1 tick.
> > + * The granularity is not exact as the lowest bit in rwbase_rt->waiter_blocked
> > + * is used to detect recent rt/dl tasks taking a read lock.
> > + */
> > +#define RW_CONTENTION_THRESHOLD (HZ/250+1)
> > +
> > +static void __sched update_dlrt_reader(struct rwbase_rt *rwb)
> > +{
> > + /* No update required if dl/rt tasks already identified. */
> > + if (rwb->waiter_blocked & 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 (dl_task(current) || rt_task(current)) {
> > + struct rt_mutex_base *rtm = &rwb->rtmutex;
> > + unsigned long flags;
> > +
> > + raw_spin_lock_irqsave(&rtm->wait_lock, flags);
> > + rwb->waiter_blocked |= 1;
> > + raw_spin_unlock_irqrestore(&rtm->wait_lock, flags);
> > + }
> > +}
> > +
> > +/* rtmutex->wait_lock must be held. */
> > +static void __sched set_writer_blocked(struct rwbase_rt *rwb)
> > +{
> > + /*
> > + * Lowest bit preserved to identify recent rt/dl tasks acquiring
> > + * the lock for read so guarantee at least one tick delay.
> > + */
> > + rwb->waiter_blocked |= (jiffies + 2) & ~1UL;
> > +}
> > +
> > +static bool __sched rwbase_allow_reader_bias(struct rwbase_rt *rwb)
> > +{
> > + /*
> > + * Allow reader bias if a dl or rt task took the lock for read
> > + * since the last write unlock. Such tasks should be designed
> > + * to avoid heavy writer contention or indefinite starvation.
> > + */
> > + if (rwb->waiter_blocked & 1)
> > + return true;
>
> This true opens a window for two tons of readers, no?
I don't understand the question or what you mean by two tons of readers.
In case you mean that the threshold is not precise, it's noted earlier
in a comment.
* The granularity is not exact as the lowest bit in rwbase_rt->waiter_blocked
* is used to detect recent rt/dl tasks taking a read lock.
> > +
> > + /*
> > + * Allow reader bias unless a writer has been blocked for more
> > + * than RW_CONTENTION_THRESHOLD jiffies.
> > + */
> > + return jiffies - rwb->waiter_blocked < RW_CONTENTION_THRESHOLD;
>
> Why pure 4ms deadline fails to work without taking care of dlrt tasks?
>
I don't understand the question. For DL/RT tasks taking the lock for read,
indefinite writer starvation is still possible. It is assumed DL/RT tasks
take care to avoid the scenario. For other tasks, 4 ms is an arbitrary
cutoff so forward progress is made.
> Given it would take 88 seconds to complete the test, is it going to
> take 100 seconds or more for the 4ms deadline?
It took 88 seconds to complete the test. Without the patch, the test
never finishes and is eventually killed after a timeout and marked as
failure. Actual time to completion will vary depending on the machine,
number of CPUs and speed of storage. The point isn't how fast the test
completes, the point is that the test completes successfully.
--
Mel Gorman
SUSE Labs
next prev parent reply other threads:[~2023-01-17 12:18 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 [this message]
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
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=20230117121839.vnubhcrlms7pt2ab@techsingularity.net \
--to=mgorman@techsingularity.net \
--cc=bigeasy@linutronix.de \
--cc=dave@stgolabs.net \
--cc=hdanton@sina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--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