From owner-freebsd-current Sat Jan 18 23:09:56 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id XAA21224 for current-outgoing; Sat, 18 Jan 1997 23:09:56 -0800 (PST) Received: from scrooge.ee.swin.oz.au (scrooge.ee.swin.oz.au [136.186.4.20]) by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id XAA21219 for ; Sat, 18 Jan 1997 23:09:54 -0800 (PST) Received: (from dtc@localhost) by scrooge.ee.swin.oz.au (8.6.9/8.6.9) id SAA09054 for current@freebsd.org; Sun, 19 Jan 1997 18:11:57 +1100 From: Douglas Thomas Crosher Message-Id: <199701190711.SAA09054@scrooge.ee.swin.oz.au> Subject: madvise MADV_FREE behavior broken? To: current@freebsd.org Date: Sun, 19 Jan 1997 18:11:57 +1100 (EST) X-Mailer: ELM [version 2.4 PL24] Content-Type: text Sender: owner-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk I've noticed that madvise MADV_FREE doesn't seem to be working as documented. On the next access it seems to usually zero pages if they are in memory, and page them in if paged out. Seems almost the total opposite of the ideal behaviour of avoiding a zero fill if the page is in memory and zero filling if a page-in were required. The example below illustrates this. It writes to a lot of pages, so many are paged out (on a 64M machine), then it MADV_FREEs each page and reads from it. This causes as many page-ins as not using MADV_FREE, where I would have expect no page-ins. If the pages are unmapped and re-mapped, the page-ins are minimal, although there is still a lot of paging out? If the amount of pages used is decreased so that few are paged out then most are zero filled. Regards Douglas Crosher -=-=- #include #include #include #define NUM_PAGES 16384 main() { int n,i, page; int num_not_zero=0; if (mmap(0x9000000,NUM_PAGES*4096, PROT_READ|PROT_WRITE|PROT_EXEC,MAP_PRIVATE|MAP_ANON,-1,0) == -1) printf("mmap erorr\n"); printf("Writing\n"); /* write to all the pages */ for (page=0;page