用于顺序文件写入的posix_fadvise()参数是什么? [英] What posix_fadvise() args for sequential file write?
问题描述
我正在开发一个按顺序写一个大文件(根本不读)的应用程序,并且我想使用posix_fadvise()
优化文件系统的行为.
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 posix_fadvise()
to optimize the filesystem behavior.
联机帮助页中的功能描述建议最合适的策略是POSIX_FADV_SEQUENTIAL
.但是,Linux实现描述怀疑:
The function description in the manpage suggests that the most appropriate strategy would be POSIX_FADV_SEQUENTIAL
. However, the Linux implementation description doubts that:
在Linux中,
POSIX_FADV_NORMAL
将预读窗口设置为备用设备的默认大小;POSIX_FADV_SEQUENTIAL
将该大小加倍,并且POSIX_FADV_RANDOM
完全禁用文件预读.
Under Linux,
POSIX_FADV_NORMAL
sets the readahead window to the default size for the backing device;POSIX_FADV_SEQUENTIAL
doubles this size, andPOSIX_FADV_RANDOM
disables file readahead entirely.
由于我只写数据(也可能覆盖文件),所以我不希望有任何预读.然后我应该坚持使用POSIX_FADV_SEQUENTIAL
还是使用POSIX_FADV_RANDOM
禁用它?
As I'm only writing data (overwriting files possibly too), I don't expect any readahead. Should I then stick with my POSIX_FADV_SEQUENTIAL
or rather use POSIX_FADV_RANDOM
to disable it?
其他选项(例如POSIX_FADV_NOREUSE
)如何?还是根本不使用posix_fadvise()
进行书写?
How about other options, such as POSIX_FADV_NOREUSE
? Or maybe do not use posix_fadvise()
for writing at all?
推荐答案
这全都取决于数据的时间局部性.如果应用程序在写入后不久就不需要数据,则可以使用POSIX_FADV_NOREUSE
避免写入缓冲区缓存(与open()
中的O_DIRECT
标志类似).
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()
).
这篇关于用于顺序文件写入的posix_fadvise()参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!