linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michel Lespinasse <walken@google.com>
To: David Howells <dhowells@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mike Waychison <mikew@google.com>,
	Suleiman Souhlal <suleiman@google.com>,
	Ying Han <yinghan@google.com>
Subject: Re: [PATCH 07/10] generic rwsem: implement down_read_critical() /  up_read_critical()
Date: Wed, 19 May 2010 16:47:17 -0700	[thread overview]
Message-ID: <AANLkTil9ev-q_uAK9vvA-GJ4LiPoDuKdeZJjAe4bh87K@mail.gmail.com> (raw)
In-Reply-To: <32068.1274275283@redhat.com>

On Wed, May 19, 2010 at 6:21 AM, David Howells <dhowells@redhat.com> wrote:
> Michel Lespinasse <walken@google.com> wrote:
>
>> +void __sched down_read_critical(struct rw_semaphore *sem)
>> +{
>> +     might_sleep();
>> +     rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
>> +
>> +     LOCK_CONTENDED(sem, __down_read_trylock, __down_read_unfair);
>> +
>> +     preempt_disable();
>
> Shouldn't preemption really be disabled before __down_read_unfair() is called?
> Otherwise you can get an unfair read on a sem and immediately get taken off
> the CPU.  Of course, this means __down_read_unfair() would have to deal with
> that in the slow path:-/

I've asked myself the same question; it is true that we don't fully
prevent ourselves getting preempted while holding the rwsem here.

My understanding is that Linus wants the preempt_disable() mainly to
prevent threads doing voluntary preemption (anything that might_sleep)
while holding the unfairly acquired rwsem;  and also to have people
think twice before adding more down_read_critical() calls.

It wouldn't be difficult to move the preempt_disable() ahead of the
lock acquire fast path. However I don't think I can do it for the
blocking path, where thread A tries to acquire the lock on behalf of
thread B and then wakes B if it succeeded - I don't think we have an
API for A to say 'I want to disable preemption in thread B', is there
?

> Oh, and something else that occurs to me:  Do unfair readers have to go at the
> front of the wakeup queue?  Can they be slightly less unfair and go either
> before the first reader in the queue or at the back of the queue instead?

Going before the first reader would be fine for our use, as we're
really only using this for mmap_sem and the write holders there don't
keep it very long. I'm not sure what this buys us though.

Going at the back of the queue would mean the critical readers would
still get occasionally blocked behind other readers doing disk
accesses - we'd like to avoid that.

-- 
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.

  reply	other threads:[~2010-05-19 23:47 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-17 22:25 [PATCH 00/10] V3: rwsem changes + down_read_critical() proposal Michel Lespinasse
2010-05-17 22:25 ` [PATCH 01/10] x86 rwsem: minor cleanups Michel Lespinasse
2010-05-17 22:25 ` [PATCH 02/10] rwsem: fully separate code pathes to wake writers vs readers Michel Lespinasse
2010-05-17 22:25 ` [PATCH 03/10] rwsem: lighter active count checks when waking up readers Michel Lespinasse
2010-05-17 22:25 ` [PATCH 04/10] rwsem: let RWSEM_WAITING_BIAS represent any number of waiting threads Michel Lespinasse
2010-05-17 22:25 ` [PATCH 05/10] rwsem: wake queued readers when writer blocks on active read lock Michel Lespinasse
2010-05-17 22:25 ` [PATCH 06/10] rwsem: smaller wrappers around rwsem_down_failed_common Michel Lespinasse
2010-05-17 22:25 ` [PATCH 07/10] generic rwsem: implement down_read_critical() / up_read_critical() Michel Lespinasse
2010-05-17 22:44   ` Linus Torvalds
2010-05-17 23:13     ` Michel Lespinasse
2010-05-17 23:20       ` Michel Lespinasse
2010-05-19 13:21       ` David Howells
2010-05-19 23:47         ` Michel Lespinasse [this message]
2010-05-21  3:35         ` Michel Lespinasse
2010-05-17 22:25 ` [PATCH 08/10] rwsem: down_read_critical infrastructure support Michel Lespinasse
2010-05-17 22:25 ` [PATCH 09/10] x86 rwsem: down_read_critical implementation Michel Lespinasse
2010-05-17 22:25 ` [PATCH 10/10] Use down_read_critical() for /sys/<pid>/exe and /sys/<pid>/maps files Michel Lespinasse
2010-05-19 11:47 ` [PATCH 01/10] x86 rwsem: minor cleanups David Howells
2010-05-20 21:37   ` Michel Lespinasse
2010-05-19 12:04 ` [PATCH 02/10] rwsem: fully separate code pathes to wake writers vs readers David Howells
2010-05-20 21:48   ` Michel Lespinasse
2010-05-19 12:25 ` [PATCH 03/10] rwsem: lighter active count checks when waking up readers David Howells
2010-05-20 22:33   ` Michel Lespinasse
2010-05-21  8:06   ` David Howells
2010-05-19 12:33 ` [PATCH 04/10] rwsem: let RWSEM_WAITING_BIAS represent any number of waiting threads David Howells
2010-05-19 12:44 ` [PATCH 05/10] rwsem: wake queued readers when writer blocks on active read lock David Howells
2010-05-19 12:51 ` [PATCH 06/10] rwsem: smaller wrappers around rwsem_down_failed_common David Howells
2010-05-19 13:34 ` [PATCH 08/10] rwsem: down_read_critical infrastructure support David Howells
2010-05-20 23:30   ` Michel Lespinasse
2010-05-21  8:03   ` David Howells
2010-05-19 14:36 ` [PATCH 09/10] x86 rwsem: down_read_critical implementation David Howells
2010-05-19 15:21 ` [PATCH 10/10] Use down_read_critical() for /sys/<pid>/exe and /sys/<pid>/maps files David Howells
2010-05-21  2:44   ` Michel Lespinasse
2010-05-22  1:49   ` Michel Lespinasse
2010-05-25  9:42   ` David Howells

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=AANLkTil9ev-q_uAK9vvA-GJ4LiPoDuKdeZJjAe4bh87K@mail.gmail.com \
    --to=walken@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikew@google.com \
    --cc=mingo@elte.hu \
    --cc=suleiman@google.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=yinghan@google.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).