mmap一个10 GB文件,并将其加载到内存中 [英] mmap a 10 GB file and load it into memory

查看:690
本文介绍了mmap一个10 GB文件,并将其加载到内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想要 mmap 一个10 GB的文件,并立即将整个文件加载到物理内存,我该如何做?

我不想使用 mlock 这样的函数,因为它需要root权限。

是否有可以满足我需求的系统调用?

if I want to mmap a 10 GB file and load the whole file into physical memory immediately, how can I do so?
I don't want to use function like mlock because it needs root privileges.
Is there a system call which can satisfy my demand?

(我有足够的内存。)

推荐答案

http://man7.org/linux/man-pages/man2/mmap.2.html =nofollow> 手册页> mmap

Read the man-page for mmap:


MAP_POPULATE(自Linux 2.5.46开始)



)页表用于映射。对于文件
映射,这将导致文件的预读。后来访问
到映射不会被页面错误阻塞。
只有自
Linux 2.6.23

MAP_POPULATE (since Linux 2.5.46)

Populate (prefault) page tables for a mapping. For a file mapping, this causes read-ahead on the file. Later accesses to the mapping will not be blocked by page faults. MAP_POPULATE is supported for private mappings only since Linux 2.6.23


$支持私人映射b $ b

发出您的请求,并准备好等待一小段时间(除非您超过进程限制)(取决于磁盘带宽和缓存)。

Issue your request, and be prepared for a short wait (unless you exceed the processes limits) (depending on disk-bandwidth and cache).

这篇关于mmap一个10 GB文件,并将其加载到内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆