Live data from Hacker News

Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

db.cs.cmu.edu

11–20 of 182 posts

Re: Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

#11
Many general-purpose OS abstractions start leaking when you're working on systems-like software.

You notice it when web servers are doing kernel bypass to for zero-copy, low-latency networking, or database engines throw away the kernel's page cache to implement their own file buffer.

Re: Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

#12
A well written bespoke function can beat a generalized function at a specific task.

If you have the resources to write and maintain the bespoke method great. The large database developers probably have this. For others please don't take this link and go around claiming mmap is bad though. That gets tiresome and is misguided. Mmap is a shortcut to access large files in a non linear fashion. It's good at that too. Just not as good as a bespoke function.

Re: Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

#13

Old timers will recall when using mmap was a prominently promoted selling point for the “no sql” dbms.

For documents it made access fast since there’s no joins, etc. that require paging from all over. The problem ended up being updates and compaction issues.

Re: Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

#14

A well written bespoke function can beat a generalized function at a specific task. If you have the resources to write and maintain the bespoke method great. The large database developers probably have this. For others please don't take this link and go around claiming mmap is bad though. That gets tiresome and is misguided. Mmap is a shortcut to access large files in a non linear fashion. It's good at that too. Just…

mmap can be handy but usually is not a good idea when you care about ACID properties. So it tends to be most useful outside databases.

Re: Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

#15

I've become convinced that there are very few, if any, reasons to MMAP a file on disk. It seems to simplify things in the common case, but in the end it adds a massive amount of unnecessary complexity.

Complexity? You mmap it in and then read the multi terrabyte file as if it was an array.

The opposite with actual file io sucks in terms of complexity. I get that you can write bespoke code that performs better but mmap is a one liner to turn a file into an array.

Re: Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

#16

A well written bespoke function can beat a generalized function at a specific task. If you have the resources to write and maintain the bespoke method great. The large database developers probably have this. For others please don't take this link and go around claiming mmap is bad though. That gets tiresome and is misguided. Mmap is a shortcut to access large files in a non linear fashion. It's good at that too. Just…

This paper isn't aimed at random developers, and it's not a criticism of mmap in general.

This is an appeal to core database engineers to stop using the wrong tool for the job.

Re: Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

#17
post #2

Memory-Mapped Files = access violations when a disk read fails. If you're not prepared to handle those, don't use memory-mapped files. (Access violation exceptions are the same thing that happens when you attempt to read a null pointer) Then there's the part with writes being delayed. Be prepared to deal with blocks not necessarily updating to disk in the order they were written to, and 10 seconds after the fact. Thi…

does that get delivered as SIGSEGV to the process or something else?

On Linux, it's a SIGBUS.

Re: Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

#19

I've become convinced that there are very few, if any, reasons to MMAP a file on disk. It seems to simplify things in the common case, but in the end it adds a massive amount of unnecessary complexity.

It's incredibly useful in read-only, memory constrained scenarios. I.E. we used to mmap all of our animation data on many rendering engines I worked on where having ~20-50mb of animation data and only "paying" a couple 10s of kb based on usage patterns was very handy. It becomes even more powerful when you have multiple processes sharing that data and the kernel is able to re-use clean pages across processes.

From reading the paper most of the concerns are around the write side. LMDB is the primary implementation that I know which leans heavily into mmap but it also comes with a number of constraints there(single writer, read locks can lead to unbounded appending to the WAL, etc). As with any tech choice it's about knowing constraints/trade-offs and making appropriate choices for your domain.

Re: Are You Sure You Want to Use MMAP in Your Database Management System? (2022)

#20

A well written bespoke function can beat a generalized function at a specific task. If you have the resources to write and maintain the bespoke method great. The large database developers probably have this. For others please don't take this link and go around claiming mmap is bad though. That gets tiresome and is misguided. Mmap is a shortcut to access large files in a non linear fashion. It's good at that too. Just…

mmap can be handy but usually is not a good idea when you care about ACID properties. So it tends to be most useful outside databases.

Can you give some examples where mmap is useful?
Post reply on HN