how to indicate to ext4 the size of a file before doing the write?
-
19-06-2021 - |
Question
I'm curious if there is a way to do this? my understanding of ext4 is limited, but I do believe it has the capability to allocate contiguous ranges of disk space
I'm writing a file, from RAM, and know its size before the open(). Is there a way I can indicate this to the filesystem? are there performance benefits?
Solution
It seems that you're looking for posix_fallocate.
Using this allows the filesystem to allocate blocks up-front, which can reduce the fragmentation of the file. In particular, this matters for applications that randomly write chunks of the file (think bittorrent clients). For an application that writes a file sequentially, it's probably not worth it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow