11 comments

[ 5.2 ms ] story [ 46.5 ms ] thread
Does this assume the file fits in address space? That's not always the case.
While the default behavior of this library is to map the entire file into address space (and also the default assumption that people have regarding mmap), you can map specific portions of a file into memory to avoid virtual address exhaustion. It's just far less convenient to do so, though typically still faster than the alternatives.
From the first paragraph:

> One of the main problems a database storage engine has to solve is how to deal with data in disk that is bigger than the available memory.

I misread the comment. The file fits in address space? As sibling comment suggests, address space is v. big and it's very much a corner case (or very specific use case) for most people.
According to the developers of Mongo at least, it's not worth considering. You can't store more than 2GB of data on a 32-bit machine because they map the entire datastore into memory.
This kind of articles, sounds like a reminder that system programming is a fundamental knowledge for software engineers.
Fundamentals are key. And it is very fun for those who really enjoy their craft
Be aware that using mmap instead of read/write might mess up Go’s scheduling. The runtime has special handling of other blocking system calls which tried to minimize the impact of those on other running goroutines. With directly accessing memory locations mapped via mmap you won’t get this benefit.