[lkml]   [2003]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: fcntl and flock wakeups not FIFO?
Matthew Wilcox wrote:
>>I've been doing some experimenting with locking on 2.4.18 and have
>>noticed that if I have a number of writers waiting on a lock, they are
>>not woken up in the order in which they requested the lock.
>>Is this expected? If so, what was the reasoning for this and are there
>>any patches to give FIFO wakeups?
> That certainly isn't what's supposed to happen. They should get woken
> up in-order. The code in 2.4.18 seems to be doing that. Are you
> doing anything clever with scheduling?

I have a potential cause here, but I'm not sure if it makes sense. The
following code (slightly reformatted) is taken from locks.c in the
Mandrake 2.4.19-16mdk kernel.

static void locks_wake_up_blocks(struct file_lock *blocker,
unsigned int wait)
while (!list_empty(&blocker->fl_block)) {
struct file_lock *waiter = list_entry(blocker->,
struct file_lock, fl_block);
if (wait) {

/* Let the blocked process remove waiter from the
* block list when it gets scheduled.
current->policy |= SCHED_YIELD;
} else {
/* Remove waiter from the block list, because by the
* time it wakes up blocker won't exist any more.

It appears that if this function is called with a wait value of zero,
all of the waiting processes will be woken up before the scheduler gets
called. This means that the scheduler ends up picking which process
runs rather than the locking code.

Looking through the file, there is no call chain on an unlock or on
closing the last locked fd which can give a nonzero wait value, meaning
that we will always end up with the scheduler making the decision in
these cases.

Am I missing something?


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:33    [W:0.046 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site