Michał Górny Michał Górny - 9 months ago 61
C Question

What posix_fadvise() args for sequential file write?

I am working on an application which does sequentially write a large file (and does not read at all), and I would like to use

to optimize the filesystem behavior.

The function description in the manpage suggests that the most appropriate strategy would be
. However, the Linux implementation description doubts that:

Under Linux,
sets the readahead window to the default size for the backing device;
doubles this size, and
disables file readahead entirely.

As I'm only writing data (overwriting files possibly too), I don't expect any readahead. Should I then stick with my
or rather use
to disable it?

How about other options, such as
? Or maybe do not use
for writing at all?

Answer Source

It all depends on the temporal locality of your data. If your application won't need the data soon after it was written, then you can go with POSIX_FADV_NOREUSE to avoid writing to the buffer cache (in a similar way as the O_DIRECT flag from open()).