Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mmap with its applications in git and libgit2

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Minqi Pan
January 08, 2016

Mmap with its applications in git and libgit2

Minqi Pan

January 08, 2016

Transcript

28 slides
  1. ⽤用法 #include <sys/mman.h> void * // 返回被映射区域的指针 mmap(void *addr, //

    被映射的⻚页从 addr 开始 size_t len, // 被映射的⻚页的最⼤大⻓长度 int prot, // ⻚页的读写跑权限保护 int flags, // 选项 int fd, // 映射源 off_t offset); // 映射源的起点偏移量量
  2. 应⽤用 • 按需分⻚页——仅当缺⻚页(访问虚拟地址但其物理理内存未 加载)时 OS 才进⾏行行磁盘到内存的拷⻉贝 • ⻚页缓存——缓存诸如动态库等磁盘数据,通过虚拟内存 映射共享到使⽤用者的进程空间内 •

    ⾼高效IPC——不同进程将⾃自⾝身⽤用户空间映射到同⼀一个⽂文件 (管道和MQ需要在内核和⽤用户空间进⾏行行四次数据复制) • ⼤大数据处理理——内存空间不⾜足时使⽤用
  3. 在 git 应⽤用场景下 • pack 与 delta window 的概念念 •

    delta window 与系统分⻚页⼤大⼩小的关系,避免缺⻚页 • 这就是为什什么 pack 内的对象顺序⾄至关重要
  4. 在 git 中的应⽤用 diff_populate_filespec While doing rename detection and pickaxe

    operation, we may need to grab the data for the blob (or file) for our own in-core comparison.
  5. 在 git 中的应⽤用 check_packed_git_idx Open and mmap the index file

    at path, perform a couple of consistency checks
  6. 在 libgit2 中的应⽤用 pack_index_check When doing Packed Object lookup query,

    Mmap the index file and do a quick run through the header to guess the index version, and to verify that the size of the index makes sense.

More Decks by Minqi Pan

Other Decks in Programming