[lkml]   [2003]   [Aug]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Lockless file reading

On Thu, 28 Aug 2003, Jamie Lokier wrote:

> Nagendra Singh Tomar wrote:
> > > Or what about: write("12"), fsync(), write("12")? Is it still
> possible
> > > for read() to return "1x1x"?
> >
> > Th read will still read both "12"s from the cache (in very high
> possibility).
> That is a terrible assumption.
> On all the Linux architures, even single CPUs, with no fancy memory
> ordering, even 386, Pentiums etc., it is possible for read() to return
> "1x1x".
> Like this: the write() is preempted (see CONFIG_PREEMPT) after writing
> one "1" byte, the read() runs, reads "1x" and is then preempted back
> to the writer, which writes "2", calls fsync(), writes "1" and is then
> preempted back to the reader, which continues and reads its second
> "1x".

kernel mode premption in Linux has still not sunk within me. All this
while I was assuming that the kernel cannot be preempted. But I have one
While the write had "12" in its buffers and it would have grabbed the
page lock to write it into the page cache, won't it set some flag saying
that I don't want to be prempted now. I think there is a small primitive
for it in from 2.5 onwards. I don't think it will be a good idea to prempt
while it is holding the page lock. How is it possible that it just wrote
"1" and did not write "2" though it had grabbed the page lock for that
I am yet to read the 2.5 kernel premption code.
Thanx for ur nice explaination though.

> Interrupts caused by network packets arriving at just the wrong moment
> can trigger that sort of thing.
> > Even if the page caches are stolen (due to mem shortage) the kernel
> > file cachecing will ensure that you get consistent data.
> The kernel does not provide synchronisation between read() and write()
> data transfers, and it does not always use atomic 32-bit reads and
> writes either.

> -- Jamie

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:48    [W:0.101 / U:3.232 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site