说我使用的/ dev / zero的如下分配与MMAP大的内存(40MB)。
Say I allocate a big memory (40MB) with mmap using /dev/zero as follows.
fd = open("/dev/zero", O_RDWR); a = mmap (0, 4096e4, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE, fd, 0);我不解的是,内核将初始化回忆到零页面被带入物理内存(我假设现代Linux内核使用的按需分页的)。因此,例如,当第一页被触摸,因此带入物理内存,内核将其所有的4096字节初始化为零,然后,当第二页被触摸时,它同样的等等。
What I understand is that the kernel will initialize memories to zero as the pages are brought into the physical memory (I suppose the modern Linux kernels use Demand paging). So for example, when the first page is touched and therefore brought into the physical memory, kernel will initialize all of its 4096 bytes to zero, then when the second page is touched, it does the same and so on.
我的理解是否正确?
推荐答案是的,甚至更多的页面只有当你触摸它们首次带入存在。
Yes, even more the pages are only brought into existence if you touch them for the first time.
BTW,有标志 MAP_ANONYMOUS ,你可以在这种情况下使用,无需打开文件描述符的/ dev / null的。
BTW, there is the flag MAP_ANONYMOUS that you can use in this situation, no need to open a file descriptor on /dev/null.
更多推荐
MMAP为/ dev /零
发布评论