All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch RT 0/4] rwsem/rt: Lift the single reader restriction
@ 2017-04-01 10:50 Thomas Gleixner
  2017-04-01 10:50 ` [patch RT 1/4] rtmutex: Make lock_killable work Thomas Gleixner
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Thomas Gleixner @ 2017-04-01 10:50 UTC (permalink / raw)
  To: LKML
  Cc: RT-users, Peter Zijlstra, Steven Rostedt, Sebastian Siewior,
	Julia Cartwright, Wargreen

R/W semaphores in RT do not allow multiple readers because a writer
blocking on the sempahore would have deal with all the readers in terms of
priority or budget inheritance. While multi reader priority boosting would
be possible (it has been attempted before), multi reader budget inheritance
is impossible.

It's obvious that the single reader restriction has severe performance
problems for situations with heavy reader contention.

A typical issue is the contention of mmap_sem. The main issue with mmap_sem
vs. process shared futexes has been cured for some architectures by
switching to fast GUP, but it still persists for those architectures which
do not (yet) implement it.

Non-RT workloads suffer also from mmap_sem contention when they trigger a
massive amount of page faults on multiple threads.

There is another issue with R/W semaphores. 

The single reader restriction is not violating the !RT semantics of R/W
sempahores, because on !RT R/W sempahores are writer fair. That means, that
when a writer blocks on a contended R/W semaphore newly incoming readers
block behind the writer. This prevents writer starvation.

So the following scenario is resulting in a deadlock independent of RT:

T1
down_read(sem);
wait_for_event();
  schedule()

T2
down_write(sem);
  blocks_on(sem);
    schedule();

T3
down_read(sem);		<- T3 cannot take sem for read and blocks behind T2
...			===> DEADLOCK!
wake_waiters();

Though there is a very subtle semantical difference on RT versus the
following scenario:

T1
down_read(sem);
wait_for_event();
  schedule()

T2
if (down_write_trylock(sem))
  do_something()

T3
down_read(sem);
...
wake_waiters();

That works on mainline, but breaks on RT due to the single reader
restriction.

Yes, that's ugly and should be forbidden, but there is code in the mainline
kernel which relies on that (e.g. Radeon driver).

Finding and fixing such constructs is not an easy task and aside of that
the single reader restriction is a performance bottleneck.

After analyzing the writer sides of R/W semaphores I came to the conclusion
that down_writes() happen in expensive code pathes which should not be
invoked in high priority tasks anyway. And if user space is stupid enough
to do so, then it's nothing we should worry about. Doing mmap() in your
high priority task is stupid to begin with.

The following patch series changes the RT implementation of R/W sempahores
to a multi reader model, which is not writer fair. That means writers have
to wait until the last reader left the critical section and readers are
allowed to take the semaphore for read even when a writer is blocked.

This means there is a risk of writer starvation, but the pathological
workloads which trigger it, are not necessarily the typical RT workloads.

It cures the Radeon mess, lowers the contention on mmap_sem for certain
workloads and did not have any negative impact in our initial testing on RT
behaviour.

I think it's worth to expose it to a wider audience of users for testing,
so we can figure out it whether there are dragons lurking.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-04-04 14:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-01 10:50 [patch RT 0/4] rwsem/rt: Lift the single reader restriction Thomas Gleixner
2017-04-01 10:50 ` [patch RT 1/4] rtmutex: Make lock_killable work Thomas Gleixner
2017-04-03 15:21   ` Steven Rostedt
2017-04-04  7:13     ` Peter Zijlstra
2017-04-04 13:20       ` Steven Rostedt
2017-04-01 10:51 ` [patch RT 2/4] rtmutex: Provide rt_mutex_lock_state() Thomas Gleixner
2017-04-01 10:51 ` [patch RT 3/4] rtmutex: Provide locked slowpath Thomas Gleixner
2017-04-01 10:51 ` [patch RT 4/4] rwsem/rt: Lift single reader restriction Thomas Gleixner
2017-04-04 14:01 ` [patch RT 0/4] rwsem/rt: Lift the " Sebastian Siewior

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.