Zero a large memory mapping with `madvise`
问题 I have the following problem: I allocate a large chunk of memory (multiple GiB) via mmap with MAP_ANONYMOUS . That chunk holds a large hash map which needs to be zeroed every now and then. Not the entire mapping may be used in each round (not every page is faulted in), so memset is not a good idea - takes too long. What is the best strategy to do this quickly? Will madvise(ptr, length, MADV_DONTNEED); guarantee me that any subsequent accesses provide new empty pages? From the Linux man