AFAIK, malloc have no reasons to use physical memory unless the actual write operation is taken, because of Demand paging, but when I actually test:
// gcc test.c
#include <stdio.h>
#include <stdlib.h>
int main (void) {
int n = 0;
while (1) {
if (malloc(1<<20) == NULL) {
printf("malloc failure after %d MiB\n", n);
return 0;
}
printf ("got %d MiB\n", ++n);
}
}
then gcc test.c -o test && ./test
and top -d $(pgrep test)
in another shell, you will note rss is increasing crazily!