mmap with /dev/zero

后端 未结 2 1257
一个人的身影
一个人的身影 2020-12-06 01:31

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_         


        
相关标签:
2条回答
  • 2020-12-06 01:52

    Yes, even more the pages are only brought into existence if you touch them for the first time.

    BTW, there is the flag MAP_ANONYMOUS that you can use in this situation, no need to open a file descriptor on /dev/null.

    0 讨论(0)
  • 2020-12-06 01:57

    Both mmap /dev/zero and ANONYMOUS don't have file backed, also zeroed content. Look at the following link http://man7.org/linux/man-pages/man2/mmap.2.html

    0 讨论(0)
提交回复
热议问题