public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chris Friesen <chris.friesen@genband.com>
To: Rob Donovan <rob@proivrc.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: FCNTL Performance problem
Date: Wed, 11 Aug 2010 11:00:46 -0600	[thread overview]
Message-ID: <4C62D73E.6090302@genband.com> (raw)
In-Reply-To: <001d01cb3971$0677e700$1367b500$@com>

On 08/11/2010 10:19 AM, Rob Donovan wrote:
> Hi,
> 
> Not sure it's about read or write 'priority' so much is it?
> 
> I wouldn't want to particularly favour writes over reads either, or it will
> just make the problem happen for reads wouldn't it?

No, because readers can always share the lock with other readers if
there is no writer waiting.

If you have one or more readers already holding the lock, with a writer
waiting, you have two choices:  1) let the new reader in under the
assumption that they'll be quick and won't extend the current "read"
usage by much, or 2) block the new reader until after any waiting
writers get a chance to get in.  The first is called reader priority,
the second is writer priority.

> And to do this, and make it favour writes, I presume it would have to be
> coded into the kernel to do this, there isn't any 'switch' for me to try?

The locks are written by glibc and the kernel.  I haven't looked at
fcntl locking so I'm not sure where the bulk of the code is.  I'd
suspect in the kernel.

> Could we not have it 'fairly' process locks? So that if a read lock comes
> along, and there is a write lock waiting for another read lock to unlock,
> then the 2nd read has to wait for the write lock. Not particularly because
> the write lock has priority, but because it was requested after the write
> lock was.

The behaviour you describe is called "writer priority".

> To me, it seems like there needs to be something in the fcntl() routines so
> that when a lock is called with F_SETLKW, if it gets blocked then it needs
> to put its 'request' in some kind of queue, so that if any more reads come
> along, they know there is already a lock waiting to get the lock before it,
> so they queue up behind it. 

Again, this would be implementing writer priority.

POSIX doesn't guarantee either form, so if you need a writer-priority
lock then fcntl() isn't a good choice.  In fact in most cases I suspect
you'll find that read/write locks are implemented as reader priority
since the expectation is that writes are infrequent.

Chris

-- 
Chris Friesen
Software Developer
GENBAND
chris.friesen@genband.com
www.genband.com

      reply	other threads:[~2010-08-11 17:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-08 19:26 FCNTL Performance problem Rob Donovan
2010-08-09 21:41 ` Chris Friesen
2010-08-11 16:19   ` Rob Donovan
2010-08-11 17:00     ` Chris Friesen [this message]

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=4C62D73E.6090302@genband.com \
    --to=chris.friesen@genband.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob@proivrc.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