mmap is great, but it often lures developers into thinking that in-memory and on-disk data structures can be reasonably unified. It's still spinning media, and even SSDs are orders of magnitude slower than regular RAM. Optimized data structures should be used accordingly.
It's also not a hard rule that the OS cache is always better. It's probably very good at block-level caching, so don't rewrite that, but that's not very fine grained. The OS can't collect much more than some basic access statistics and madvise()s to figure out what to keep resident. It's kind of dishonest to make it seem like "advanced databases" like PostgreSQL should abandon their own caches entirely. In fact, most PostgreSQL tuners suggest that only a fraction of available RAM should be used as a buffer cache, and that it's prudent to just let the OS manage most of it. The query planner can even be advised as to how much effective cache space is available, including the OS disk cache.
It's also not a hard rule that the OS cache is always better. It's probably very good at block-level caching, so don't rewrite that, but that's not very fine grained. The OS can't collect much more than some basic access statistics and madvise()s to figure out what to keep resident. It's kind of dishonest to make it seem like "advanced databases" like PostgreSQL should abandon their own caches entirely. In fact, most PostgreSQL tuners suggest that only a fraction of available RAM should be used as a buffer cache, and that it's prudent to just let the OS manage most of it. The query planner can even be advised as to how much effective cache space is available, including the OS disk cache.