memset() is eating cpu
Issue
- The kernel needs to allocate physical memory for the executable, needing to release memory from the cache. Kernel CPU spikes here.
- Through a small program it has been observed that I/O has nothing to do with this problem. When the kernel is in the bad state memset() spikes the kernel CPU. time. The two important lines from the program are:
void * pc = malloc(1024*1024*1024); // Allocate 1 GiB of virtual memory
memset(pc, 1, 1024*1024*1024); // Write the memory, which allocates physical memory
- Linux does not allocate physical pages to the process until memset() is called. That is where the kernel CPU time spikes.
Cache loaded:
real 0m10.151s
user 0m0.193s
sys 0m9.936s
Cache empty:
real 0m0.391s
user 0m0.137s
sys 0m0.193s
Environment
- Red Hat Enterprise Linux 6
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
