public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Love <rml@tech9.net>
To: Matthew Wilcox <willy@debian.org>
Cc: Andrew Morton <akpm@digeo.com>,
	John Levon <levon@movementarian.org>,
	linux-kernel@vger.kernel.org
Subject: Re: flock(fd, LOCK_UN) taking 500ms+ ?
Date: 02 Oct 2002 15:21:06 -0400	[thread overview]
Message-ID: <1033586465.24108.77.camel@phantasy> (raw)
In-Reply-To: <20021002193052.B28586@parcelfarce.linux.theplanet.co.uk>

On Wed, 2002-10-02 at 14:30, Matthew Wilcox wrote:

> Heh, you're so focused on perf tuning, Andrew!  It's not a matter of
> locking, it's a matter of semantics.  Here's the comment:
> 
>  *  FL_FLOCK locks never deadlock, an existing lock is always removed before
>  *  upgrading from shared to exclusive (or vice versa). When this happens
>  *  any processes blocked by the current lock are woken up and allowed to
>  *  run before the new lock is applied.
>  *  Andy Walker (andy@lysaker.kvaerner.no), June 09, 1995

Oh, I understand now.  In this case, you actually do need to call
yield() as gross as it is.

You have four options:

- call schedule().  This will result in the highest priority task
running again which may be you.  You will certainly end up running again
in the near future and there may be processes blocked by the current
lock which will not run before you continue.

- call cond_resched().  Same as above but avoid the superfluous
reschedule back to yourself, since if need_resched is unset we won't
call schedule().

- call yield().  You are put at the end of the runqueue and thus all
runnable tasks should run before you get to run again.

- do nothing.  Always my choice :)

So yield() is the only way to guarantee that all lock holders run before
you do (it does not even do that, however: it is possible for you to get
reinserted into the active array and thus it only guarantees that all
lock holders at or above your priority get to run before you). 
cond_resched() will guarantee all higher priority tasks run before you.

If you REALLY want to assure you do not run at all until all the other
lock holders ran, you would need to down() a semaphore and not wake up
until all of them have run again (I have no idea how the flock code
looks, if this is even feasible...). 

> > If there really is a solid need to hand the CPU over to some now-runnable
> > higher-priority process then a cond_resched() will suffice.
> 
> I think that's the right thing to do.  If I understand right, we'll
> check needs_resched at syscall exit, so we don't need to do it for
> unlocks, right?

Right.  On return to user-space need_resched will be checked and
schedule() called if it is set.

However, it is only set if the newly woken up tasks have a higher
priority than you.  Otherwise, schedule() would just select you again.

	Robert Love


  parent reply	other threads:[~2002-10-02 19:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-02  2:39 flock(fd, LOCK_UN) taking 500ms+ ? John Levon
2002-10-02  3:23 ` John Levon
2002-10-02 13:14   ` Matthew Wilcox
2002-10-02 17:04     ` Andrew Morton
2002-10-02 18:30       ` Matthew Wilcox
2002-10-02 18:58         ` John Levon
2002-10-02 19:10           ` Robert Love
2002-10-02 19:21         ` Robert Love [this message]
2002-10-02 19:23         ` Andrew Morton
2002-10-02 20:05           ` Matthew Wilcox
  -- strict thread matches above, loose matches on Subject: below --
2002-10-02 21:36 Manfred Spraul

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=1033586465.24108.77.camel@phantasy \
    --to=rml@tech9.net \
    --cc=akpm@digeo.com \
    --cc=levon@movementarian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=willy@debian.org \
    /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