Re: Wislist for Linux from the mold linker's POV

From: Niklas Hambüchen
Date: Fri Nov 29 2024 - 00:48:33 EST


Hi Rui,

On 2024-11-29 01:44, Rui Ueyama wrote:
> ext4 on a PCIe Gen.5 SSD, but I guess it probably doesn't matter much
> because we observed similar results even on tmpfs

When dealing with ext4, there's another behaviour useful to know, which is the opposite of what you observed:

When files are overwritten, it can suddenly be ~10x slower than if they are deleted and written from scratch.

I thought that shouldn't be, because the files are re-written from scratch using `O_WRONLY|O_CREAT|O_TRUNC` in both cases.

Turns out, `ext4` has built in a feature to work around bad applications forgetting `fsync()`:

`close()`ing new files is fast.
But if you `close()` existing files after writing them from scratch, or atomic-rename something replacing them, ext4 will insert an `fsync()`!

Sources:
* https://superuser.com/questions/865710/write-to-newfile-vs-overwriting-performance-issue/872056
* https://www.kernel.org/doc/html/latest/admin-guide/ext4.html section `auto_da_alloc`
* https://en.wikipedia.org/wiki/Ext4#Delayed_allocation_and_potential_data_loss