I’ve been working in another branch on speeding up IBD/reindexing, and have been looking at how to improve page cache hits on Linux. This is a minor (but safe) improvement I’ve discovered during that work.
The change here uses posix_fadvise()
on systems that support it (Linux, BSD, macOS) such that:
- When opening a block file for processing, it advises the kernel that the block will be read immediately, and that the read will be sequential.
- When closing a block file, it advises the kernel that it can discard entries in the page cache associated with that block file, which potentially leaves a bit more page cache room for things like chainstate files when chainstate reindexing happens.
There’s also a minor/pedantic fix to related to an existing posix_fallocate()
call to make sure it doesn’t redefine _POSIX_C_SOURCE
(which could potentially affect the behavior of header files included after the redefinition).
I don’t expect this to be a huge performance win, but it’s safe and well contained. The new util functions are potentially useful elsewhere. The speedup here is potentially bigger by using these methods selectively on CAutoFile, as that’s how block files are loaded during the chainstate reindexing phase. I’m working on that as well, but that’s more delicate since CAutoFile is used all over the place (compared to CBufferedFile which is just used when reindexing block files).