11

借助 ext4 文件系统的 打洞 功能实现消息队列

 3 years ago
source link: https://byronhe.com/post/2019/08/10/message-queue-using-hole-punching/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

借助 ext4 文件系统的 打洞 功能实现消息队列

借助 ext4 文件系统的 打洞 功能,可以实现一个消息队列 https://gist.github.com/CAFxX/571a1558db9a7b393579

fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, offset, length);

Punching holes in files

https://lwn.net/Articles/415889/

怎样对大文件的中间部分进行增删?

首先,如果复制/写文件的后半段的话,肯定是可以实现的,但是这样不“高效”。 所以这里的需求是 “怎样在大文件中间 insert 或者 delete 一段数据而不用读写文件的后半部分”。

由于 unix 的历史,并没有直接提供这种 syscall 。

如果用 3.15 之后的 linux kernel ,在 ext4 (only for extent-based files) 和 XFS 文件系统上, http://man7.org/linux/man-pages/man1/fallocate.1.html http://man7.org/linux/man-pages/man2/fallocate.2.html

fallocate 这个 syscall 新增了 FALLOC_FL_COLLAPSE_RANGE (delete 一段) 和 FALLOC_FL_INSERT_RANGE (insert 一段)这两个选项,可以实现在文件系统 block size 边界对齐的 insert/delete 。

gif 缩放算法及相关资料 Proxygen http2 代码分析


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK