Messages in this thread Patch in this message | | | Date | Wed, 22 Mar 2023 22:26:04 -0000 | From | "tip-bot2 for Sebastian Andrzej Siewior" <> | Subject | [tip: locking/core] locking/rwbase: Mitigate indefinite writer starvation. |
| |
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 9d29d8e36cd6448966d83ab1acf946a2df3c2833 Gitweb: https://git.kernel.org/tip/9d29d8e36cd6448966d83ab1acf946a2df3c2833 Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> AuthorDate: Tue, 21 Mar 2023 17:11:40 +01:00 Committer: Thomas Gleixner <tglx@linutronix.de> CommitterDate: Wed, 22 Mar 2023 23:17:38 +01:00
locking/rwbase: Mitigate indefinite writer starvation.
On PREEMPT_RT rw_semaphore and rwlock_t locks are unfair to writers. Readers can indefinitely acquire the lock unless the writer fully acquired the lock, which might never happen if there is always a reader in the critical section owning the lock.
Mel Gorman reported that since LTP-20220121 the dio_truncate test case went from having 1 reader to having 16 readers and that number of readers is sufficient to prevent the down_write ever succeeding while readers exist. Eventually the test is killed after 30 minutes as a failure.
Mel proposed a timeout to limit how long a writer can be blocked until the reader is forced into the slowpath.
Thomas argued that there is no added value by providing this timeout. From a PREEMPT_RT point of view, there are no critical rw_semaphore or rwlock_t locks left where the reader must be preferred.
Mitigate indefinite writer starvation by forcing the READER into the slowpath once the WRITER attempts to acquire the lock.
Reported-by: Mel Gorman <mgorman@techsingularity.net> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Mel Gorman <mgorman@techsingularity.net> Link: https://lore.kernel.org/877cwbq4cq.ffs@tglx Link: https://lore.kernel.org/r/20230321161140.HMcQEhHb@linutronix.de --- kernel/locking/rwbase_rt.c | 9 --------- 1 file changed, 9 deletions(-)
diff --git a/kernel/locking/rwbase_rt.c b/kernel/locking/rwbase_rt.c index c201aad..25ec023 100644 --- a/kernel/locking/rwbase_rt.c +++ b/kernel/locking/rwbase_rt.c @@ -72,15 +72,6 @@ static int __sched __rwbase_read_lock(struct rwbase_rt *rwb, int ret; raw_spin_lock_irq(&rtm->wait_lock); - /* - * Allow readers, as long as the writer has not completely - * acquired the semaphore for write. - */ - if (atomic_read(&rwb->readers) != WRITER_BIAS) { - atomic_inc(&rwb->readers); - raw_spin_unlock_irq(&rtm->wait_lock); - return 0; - } /* * Call into the slow lock path with the rtmutex->wait_lock
| |