• Michel Lespinasse's avatar
    rwsem: wake queued readers when writer blocks on active read lock · 424acaae
    Michel Lespinasse authored
    This change addresses the following situation:
    
    - Thread A acquires the rwsem for read
    - Thread B tries to acquire the rwsem for write, notices there is already
      an active owner for the rwsem.
    - Thread C tries to acquire the rwsem for read, notices that thread B already
      tried to acquire it.
    - Thread C grabs the spinlock and queues itself on the wait queue.
    - Thread B grabs the spinlock and queues itself behind C. At this point A is
      the only remaining active owner on the rwsem.
    
    In this situation thread B could notice that it was the last active writer
    on the rwsem, and decide to wake C to let it proceed in parallel with A
    since they both only want the rwsem for read.
    Signed-off-by: default avatarMichel Lespinasse <walken@google.com>
    Acked-by: default avatarDavid Howells <dhowells@redhat.com>
    Cc: Mike Waychison <mikew@google.com>
    Cc: Suleiman Souhlal <suleiman@google.com>
    Cc: Ying Han <yinghan@google.com>
    Cc: Ingo Molnar <mingo@elte.hu>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: "H. Peter Anvin" <hpa@zytor.com>
    Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    424acaae
rwsem.c 8.16 KB