riscv-software-src / riscv-pk

RISC-V Proxy Kernel
Other
579 stars 306 forks source link

malloc calls sbrk, __page_alloc, and then memset, polluting cache #238

Closed zinechant closed 3 years ago

zinechant commented 3 years ago

This would pollute caches and produce strange cache numbers in spike-isa-sim. Especially for the case where compute is not intensive, or for the case when a large array is malloced but only a small portion is used. Opening this issue to open the discussion on whether this memset is necessary.

aswaterman commented 3 years ago

It is necessary for the majority of calls to __page_alloc. mmap'ed pages are required to be zeroed, and of course there's no guarantee that main memory is already zeroed. (The fact that Spike zeroes main memory at boot is an implementation detail and is not true of other RISC-V implementations.)

Besides mmap, other uses of __page_alloc within pk rely on the zero initialization, including when new page tables are allocated.

aswaterman commented 3 years ago

Search for the word "zero-fills" on this page for more details on the mmap situation: https://pubs.opengroup.org/onlinepubs/7908799/xsh/mmap.html

zinechant commented 3 years ago

That was fast! Thanks! I am happy with a little hack that commenting out the memset for my purpose. Going to close this issue.

aswaterman commented 3 years ago

Cool, good luck.