On Wed, Jan 22, 2025 at 01:14:22AM +0000, Andy Fan wrote: > Andres Freund <and...@anarazel.de> writes: >> FWIW, I've seen the fsyncs around recycling being a rather substantial >> bottleneck. To the point of the main benefit of larger segments being the >> reduction in number of fsyncs at the end of a checkpoint. I think we should >> be able to make the fsyncs a lot more efficient by batching them, first >> rename >> a bunch of files, then fsync them and the directory. The current pattern >> bascially requires a separate filesystem jouranl flush for each WAL segment. > > For education purpose, how to fsync files in batch? 'man fsync' tells me > user can only fsync one file each time. > > int fsync(int fd); > > The fsync manual seems not saying fsync on a directory would fsync all > the files under that directory.
I think Andres means that we should wait until the end of recycling to fsync() the directory so that we aren't flushing it for every single recycled segment. This sort of batching approach could also work well with pre_sync_fname(), so that by the time we actually call fsync() on the files, it has very little to do. -- nathan