On Thu, 24 Jan 2002, guy keren wrote:
>
> 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.
>
This was a test script which I happened to write in C. It does not aim to
be a fool-proof program.
> > 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.
>
Readers having priority over the writers may mean that the writers may be
starved by the readers.
> > > > 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.
>
I don't understand that comment too well. Would making flock() FCFS break
its expected behaviour?
> > 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.
>
I'll try, and report the results
Regards,
Shlomi Fish
> --
> guy
>
> "For world domination - press 1,
> or dial 0, and please hold, for the creator." -- nob o. dy
>
----------------------------------------------------------------------
Shlomi Fish [EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/
Home E-mail: [EMAIL PROTECTED]
"Let's suppose you have a table with 2^n cups..."
"Wait a second - is n a natural number?"
=================================================================
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]