使用内存映射或解锁流操作?
我正在研究 Linux 下 FAT32 的 FUSE 实现(我知道 Linux 内核中已经提供了该功能,但这是一项学校作业)。 FAT32 文件系统是使用 mkfs.msdos 命令创建的,稍后我将使用 posix_madvise 将该命令映射到内存,或者通过 posix_fadvise 使用未锁定的流代码>.
我不确定我的选择应该基于什么,我的意思是,每种方法的优缺点是什么(在性能、内存使用等方面)。我见过一些将 madvise
与 mmap
结合使用的示例,但没有提供关于是否应使用 fadvise
的信息也有 mmap
,或者,首先,fadvise
/madvise
和 POSIX 实现之间的区别posix_fadvise
/posix_madvise
。
任何正确方向的观点都将受到高度赞赏。
I am working on a FUSE implementation for FAT32 under Linux (I know this is already available in the Linux Kernel, but this is a school assignment).
The FAT32 filesystem is created with the mkfs.msdos
command, which I will later map into memory with posix_madvise
, or use an unlocked stream by means of posix_fadvise
.
I am not sure what should I base my choice on, I mean, what the pros and cons of each method are (in terms of performance, memory usage, etc). I have seen a few examples out there which combine the use of madvise
with mmap
, but no information was provided as to whether fadvise
should be used with mmap
too, or, to start with, the difference between the fadvise
/madvise
and POSIX implementations posix_fadvise
/posix_madvise
.
Any point in the right direction will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您想将自己限制为 ~2.5 GB 文件系统或需要 64 位计算机,否则您的选择是使用
mmap
并动态管理要映射的文件系统的哪些部分,或使用正常的读/写运营。我可能会选择后者。mmap
作为一种性能优化被高估了,并且具有填充虚拟地址空间等缺点,因此我倾向于仅在您确实需要将文件视为内存 - 例如,存储进程共享的同步对象、可执行代码或要提供给仅接受内存中数据的 API 的大数据(例如,qsort
)。Unless you want to limit yourself to ~2.5 GB filesystems or requiring a 64-bit machine, your choices are to use
mmap
and dynamically manage what part of the filesystem you keep mapped, or use normal read/write operations. I would probably go for the latter.mmap
is overrated as a performance optimization, and has drawbacks like filling up your virtual address space, so I would tend to only usemmap
when you really need to treat a file as memory - for instance, storing process-shared synchronization objects, executable code, or large data you want to feed to an API that only accepts in-memory data (for example,qsort
).