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?

Was it helpful?

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
scroll top