Skip to content

Commit 286deb7

Browse files
Sebastian Andrzej Siewioringomolnar
authored andcommitted
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> Signed-off-by: Ingo Molnar <mingo@kernel.org> 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 Cc: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0685506 commit 286deb7

1 file changed

Lines changed: 0 additions & 9 deletions

File tree

kernel/locking/rwbase_rt.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,6 @@ static int __sched __rwbase_read_lock(struct rwbase_rt *rwb,
7272
int ret;
7373

7474
raw_spin_lock_irq(&rtm->wait_lock);
75-
/*
76-
* Allow readers, as long as the writer has not completely
77-
* acquired the semaphore for write.
78-
*/
79-
if (atomic_read(&rwb->readers) != WRITER_BIAS) {
80-
atomic_inc(&rwb->readers);
81-
raw_spin_unlock_irq(&rtm->wait_lock);
82-
return 0;
83-
}
8475

8576
/*
8677
* Call into the slow lock path with the rtmutex->wait_lock

0 commit comments

Comments
 (0)