Skip to content

Commit de7182f

Browse files
sessesnicolet
authored andcommitted
Turn on MADV_RANDOM for Syzygy mmaps (on Unix-like builds)
When running on a cloud VM (n1-highcpu-96) with several NVMe SSDs and some non-SSDs for tablebases, I noticed that the average SSD request size was more than 256 kB. This doesn't make a lot of sense for Syzygy tablebases, which have a block size of 32 bytes and very low locality. Seemingly, the tablebase access patterns during probing make the OS, at least Linux, think that readahead is advantageous; normally, it gives up doing readahead if there are too many misses, but it doesn't, perhaps due to the fairly high overall hit rates. (It seems the kernel cannot distinguish between reading a block that was paged in because the userspace wanted it explicitly, and one that was read as part of readahead.) Setting MADV_RANDOM effectively turns off readahead, which causes the request size to drop to 4 kB. In the aforemented cloud VM test, this roughly tripled the amount of I/O requests that were able to go through, while reducing the total traffic from 2.8 GB/sec to 56 MB/sec (moving the bottleneck to the non-SSDs; it seems the SSDs could have sustained many more requests). Closes #1829 No functional change.
1 parent 6ab92d2 commit de7182f

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/syzygy/tbprobe.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class TBFile : public std::ifstream {
216216
fstat(fd, &statbuf);
217217
*mapping = statbuf.st_size;
218218
*baseAddress = mmap(nullptr, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
219+
madvise(*baseAddress, statbuf.st_size, MADV_RANDOM);
219220
::close(fd);
220221

221222
if (*baseAddress == MAP_FAILED) {

0 commit comments

Comments
 (0)