Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How zero-fill-on demand is implemented in Linux kernel, and where I can disable it?

When we malloc memory, only virtual memory is available, and it actually pointed to zero-page. The real physical memory will be allocated when we try to write to the malloced memory, at this moment, there will be copy-on-wright that copy zeros from zero-page to physical memory which mapped by page-fault. My problem is, how/where zero-fill-on demand is implemented in linux source code, I want to disable this functionality to do some test. I guess it may happened in page-fault procedure, rather than brk() or mmap().

Similar topics related to zero-fill-on-demand. ZFOD and COW.

like image 587
Qinchen Avatar asked Nov 07 '22 19:11

Qinchen


1 Answers

You want to use the MAP_UNINITIALIZED parameter to mmap and enable CONFIG_MMAP_ALLOW_UNINITIALIZED in your kernel compilation.

MAP_UNINITIALIZED (since Linux 2.6.33) Don't clear anonymous pages. This flag is intended to improve performance on embedded devices. This flag is honored only if the kernel was configured with the CONFIG_MMAP_ALLOW_UNINITIAL‐ IZED option. Because of the security implications, that option is normally enabled only on embedded devices (i.e., devices where one has complete control of the contents of user memory).

like image 59
John Meacham Avatar answered Nov 15 '22 11:11

John Meacham