Tookmund / Swapspace

A fork of Jeroen T. Vermeulen's excellent dynamic swap space manager
GNU General Public License v2.0
128 stars 12 forks source link

Clarify our use of `fallocate` vs just writing bytes #38

Open gerion0 opened 1 year ago

gerion0 commented 1 year ago

Currently, the swap files seem to be allocated by opening a file and writing zeros in it (with fill_swapfile/write_data). This takes a lot of time and normally has no real benefit, since the data is overwritten anyway.

For these cases, Linux and glibc provide the fallocate-call, which instantly can allocate a large block of data (and is supported on all major file systems and usable for swap files). I think, this syscall would be much better suited for this program, since the time to allocate swap would basically disappear completely.

Tookmund commented 1 year ago

We do use it when available. https://github.com/Tookmund/Swapspace/blob/9342d856ccc4c382c0c624e985d9c2b7b9fd9f57/src/swaps.c#L418

The comment above write_data does not make that clear however, and the name itself is now misleading.

Definitely some comment and naming improvements that could be made to clarify it.

gerion0 commented 1 year ago

Ah nice! I have completely overlooked that block.

Could be, that some more comments are helpful or renaming of write_data. Anyway, I have searched explicitely for how the file is allocated and scanned for a loop thus missing the codeblock above it. From my side, the bug can be closed.