c - Zero a large memory mapping with `madvise` -
i have following problem: i allocate large chunk of memory (multiple gib) via mmap map_anonymous . chunk holds large hash map needs zeroed every , then. not entire mapping may used in each round (not every page faulted in), memset not idea - takes long. what best strategy quickly? will madvise(ptr, length, madv_dontneed); guarantee me subsequent accesses provide new empty pages? from linux man madvise page: this call not influence semantics of application (except in case of madv_dontneed ), may influence performance. kernel free ignore advice. ... madv_dontneed subsequent accesses of pages in range succeed, result either in reloading of memory contents underlying mapped file (see mmap(2)) or zero-fill-on-demand pages mappings without underlying file. ... the current linux implementation (2.4.0) views system call more command advice ... or have munmap , remap region anew? it has work on linux , ideally have same behaviour on os...