Re: Lockless file reading

From: Nagendra Singh Tomar
Date: Thu Aug 28 2003 - 05:26:46 EST



On Thu, 28 Aug 2003, Timo Sirainen wrote:

> On Thu, 2003-08-28 at 00:15, Nagendra Singh Tomar wrote:
> > > > I beleive ur original post was to address the case of a reader
> > > reading
> > > > a file getting *incorrect* data due to the file being written
> > > > simultaneously by another writer process.
> > >
> > > Well, "old" data, which mixed with new data would become incorrect
> as a
> > > whole.
> >
> > What is this mixing we are talking of ??
>
> I can easily see that the data might be divided into two separate pages
> and between updating those pages, another process would have read the
> first page, but not the second page. That would result in a mixed old
> and new data. Probably just <old><new> or <new><old> instead of
> <new><old><new> what I was worrying about, but still it would be nicer
> to rely only on byte atomicity and read/write ordering. :)

Timo, I am at loss. OK, let me put across my understanding of the problem.
Thw writer is *updating* the file and not writing it for the first time,
which means that the file can be 1000 bytes long and the writer might be
updating bytes 100 onwards. You are worried abt the reader reading
partially old and partially new data. A question.
If the writer does not want the reader to read old data why does'nt it
truncate the file and start writing from the begining every time.
Please correct me if I am missing something significant. All this while I
was thinking that the writer is writing to the file for the first time.
i.e as he keeps writing the file size increases, so the reader is sure not
to read anything else but what the writer writes.

>
> > > That was my original plan, to just rely on such kernel behaviour. I
> just
> > > don't know if it's such a good idea to rely on that, especially if I
> > > want to keep my program portable. I'll probably fallback to that
> anyway
> > > if my checksumming ideas won't work.
> >
> > But I don't see any problem with a single writer and >=1 reader. There
> is
> > no question of portability.
>
> There are of multiple writers, but it's fine for them to do locking
> between each others.
>
>

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/