Subject: Re: Swap overcommit (was Re: Replacement for grep(1) (part 2))
To: None <dillon@apollo.backplane.com, soda@sra.co.jp>
From: D. Rock <rock@dead-end.net>
List: tech-userlevel
Date: 07/15/1999 23:23:13
>     It would be really easy to test this.
>
>     Write a program that malloc's 32MB of space and touches it,
>     then sleeps 10 seconds and forks, with both child and parent
>     sleeping afterwords.  ( the parent and the forked child should
>     not touch the memory after the fork occurs ).
>
>     Do a pstat -s before, after the initial touch, and after
>     the fork.  If you do not see the reserved swap space jump
>     by 32MB after the fork, it isn't what you thought it was.
Is this OK:

main()
{
  char *bla;
  int i, pid;

  bla = malloc(32 * 1048576);

  printf("Waiting 10 seconds\n");
  sleep(10);
  for(i = 0; i < 32 * 1048576 - 4096; i += 4096)
    bla[i] = ' ';
  printf("Waiting 10 seconds\n");
  sleep(10);
  if(fork() > 0)
    printf("Waiting 10 seconds\n");
  sleep(10);
}

Before program start:
total: 20000k bytes allocated + 4792k reserved = 24792k used, 191048k available

After malloc, before touch:
total: 18756k bytes allocated + 37500k reserved = 56256k used, 159580k available

After malloc + touch:
total: 52804k bytes allocated + 4852k reserved = 57656k used, 158184k available

After fork:
total: 52928k bytes allocated + 37644k reserved = 90572k used, 125264k available

[there has been a little background activity, but the numbers speak for themselves]


Daniel