Why rss keeps growing when malloc without actual writing?

359 Views Asked by At

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!

0

There are 0 best solutions below