All of lore.kernel.org
 help / color / mirror / Atom feed
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: Fri, 20 Jan 2023 09:25:00 +0100	[thread overview]
Message-ID: <Y8pP3CD1PQ4KWhXF@linutronix.de> (raw)
In-Reply-To: <20230119174101.rddtxk5xlamlnquh@techsingularity.net>

On 2023-01-19 17:41:01 [+0000], Mel Gorman wrote:
> 
> Yes, it makes your concern much clearer but I'm not sure it actually matters
> in terms of preventing write starvation or in terms of correctness. At
> worst, a writer is blocked that could have acquired the lock during a tiny
> race but that's a timing issue rather than a correctness issue.

Correct. My concern is that one reader may need to wait 4ms+ for the
lock while a following reader (that one that sees the timeout) does not.
This can lead to confusion later on.

> Lets say the race hits
> 
> 									reader sees waiter_timeout == 0
> 	writer acquires wait_lock
> 	__rwbase_write_trylock fails
> 	update waiter_timeout
> 	rwbase_schedule
> 
> Each reader that hits the race goes ahead at a point in time but anything
> readers after that observe the timeout and eventually the writer goes ahead.
> 
> If the waiter_timeout was updated before atomic_sub(READER_BIAS),
> it doesn't close the race as atomic_sub is unordered so barriers would
> also be needed and clearing of waiter_timeout moves to out_unlock in case
> __rwbase_write_trylock succeeds. That's possible but the need for barriers
> makes it more complicated than is necessary.

yes...

> The race could be closed by moving wait_lock acquisition before the
> atomic_sub in rwbase_write_lock() but it expands the scope of the wait_lock
> and I'm not sure that's necessary for either correctness or preventing
> writer starvation. It's a more straight-forward fix but expanding the
> scope of a lock unnecessarily has been unpopular in the past.
> 
> I think we can close the race that concerns you but I'm not convinced we
> need to and changing the scope of wait_lock would need a big comment and
> probably deserves a separate patch.

would it work to check the timeout vs 0 before and only apply the
timeout check if it is != zero? The writer would need to unconditionally
or the lowest bit. That should close gaps at a low price. The timeout
variable is always read within the lock so there shouldn't be need for
any additional barriers.

> Sorry if I'm still missing something stupid and thanks for your patience
> reviewing this.
thank that it is patience and not pain in the ass ;)

Sebastian

  parent reply	other threads:[~2023-01-20  8:25 UTC|newest]

Thread overview: 26+ 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
2023-01-18 17:31       ` Mel Gorman
2023-01-19  1:15         ` Hillf Danton
2023-01-19  8:32           ` Sebastian Andrzej Siewior
2023-01-19 13:59             ` Hillf Danton
2023-01-19 16:36               ` Sebastian Andrzej Siewior
2023-01-20  9:37                 ` Hillf Danton
2023-01-20 18:34                   ` Sebastian Andrzej Siewior
2023-01-21  3:46                     ` Hillf Danton
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 [this message]
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=Y8pP3CD1PQ4KWhXF@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 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.