> idea is that, unless actually written, the zero-filled memory doesn't have
> to exist at all! This is called "demand-zero" paging and has been used
> in VAXen forever.
> When an actual write occurs, the page that was filled in from "demand-zero"
> is replaced with a page that can be dirtied. In fact, on the VAX, the
> write is allowed to occur and then that page is removed from the demand-zero
> list and becomes part of the processes' working set.
Doesnt linux already do this, or at least something very close? Consider
the program:
int main(void)
{
char *buff;
char y;
long i;
long max = 1024*1024*64;
system("free");
buff = malloc(max);
if(!buff) {printf("malloc failed"); return 1;}
for(i=0; i<max; i+=4096) y=buff[i];
system("free");
return 0;
}
It mallocs 64M of ram, reads from each page, but never dirties any of them.
You can see from the output that it uses almost no real memory at all:
jlnance-pc> a.out
total used free shared buffers cached
Mem: 18808 18144 664 6464 1012 11572
-/+ buffers: 5560 13248
Swap: 65388 1444 63944
total used free shared buffers cached
Mem: 18808 18212 596 6476 1012 11572
-/+ buffers: 5628 13180
Swap: 65388 1444 63944
Am I missing something?
Jim