DBMS 需要管理数据在磁盘和内存之间的流动

使用 OS 的 memory mapping 机制(mmap)存在的问题:

  • Transaction Safety(事务安全)
  • I/O Stalls(DBMS 不知道哪些页在内存中,会导致更多的 page fault)
  • Error Handling(需要更多的错误处理,SIGBUS)
  • TLB Shootdowns

memory mapping 一些其他函数:

  • mdavise:Tell the OS how you expect to read certain pages
  • mlock:Tell the OS that memory ranges cannot be paged out
  • msync:Tell the OS to flush memory ranges out to disk

DBMS 控制内存换入换出会比 OS 更好:

  • 写脏页时可以以正确的顺序写入
  • 预读
  • Buffer replacement policy
  • Thread scheduling