On Thu, 24 Jan 2002, Shlomi Fish wrote:

> The code is attached to this message.

btw, norty norty on not-checking the return value of 'open' and the
value of 'flock'... i didn't create the lock file at first, and saw there
there is no locking performed at all.

> Compile it with gcc. Platform:
>
> Linux Kernel 2.4.13-12mdk ( I think it is based on the old AC tree)
> glibc 2.2.4-6mdk
> Linux Mandrake 8.1
> I'm running it on ReiserFS. Don't know about 64-bit files.

ok, it shows a similar(!) behaviour on redhat 6.2, kernel 2.2.19, glibc
2.1.X, ext2. but there is no starvation. only that the readers are having
priority over the writers - for every ~3-4 times a reader manages to set
and unset the lock, a writer manages to set and unset it once, but i see
the writers having alternate access to the file.

> > > Should I port my FCFS RWLock to the Linux kernel?
> >
> > why? did you read the code of the locks that are currently there? your
> > lock will have hard time competing with them, if you don't re-write it in
> > assembly ;)
>
> I'm talking so it will be available for the flock() system call and
> friends... That code is in /usr/src/linux/fs/locks.c.

if you'd read their code, you'd see there is no place for such a lock to
be used by them. please note the following comment (from a 2.4.4 kernel
source tree, as well as a 2.4.9 kernel source tree):

============================================================
/* Try to create a FLOCK lock on filp. We always insert new FLOCK locks
 * at the head of the list, but that's secret knowledge known only to
 * flock_lock_file and posix_lock_file.
 */
static int flock_lock_file(struct file *filp, unsigned int lock_type,
                           unsigned int wait)
============================================================

this seems to _somehow_ match the demonstrated behaviour. you should note
that most blocking in the kernel, is not done using locks, but rather
using wait queues.

> 1. flock() and friends are not FCFS.
> 2. You have several processes and several threads in the situation that I
> described.

yes. try seeing what 'fcntl' with record locking gives you. note you'll
have to open the lock file for writing, in order to be able to set write
locks. 'man fcntl' and look for 'F_SETLK' and friends.

--
guy

"For world domination - press 1,
 or dial 0, and please hold, for the creator." -- nob o. dy


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to