Subject: Re: mmap(2) performance netbsd-1-6 vs. -current
To: Bang Jun-Young <junyoung@netbsd.org>
From: Jason Thorpe <thorpej@wasabisystems.com>
List: tech-kern
Date: 10/19/2003 11:18:18
On Sunday, October 19, 2003, at 09:51 AM, Bang Jun-Young wrote:
> The test program used is as follows (please don't blame me for its
> silliness, I just wanted to see a rough difference in minutes :-):
Ok, I'll ignore the silliness, but I will point out a couple of bugs :-)
> #include <stdio.h>
> #include <sys/mman.h>
>
> main()
> {
> void *ptr[15];
> int i, j;
> size_t size;
>
> for (j = 0; j < 40960; j++) {
> for (i = 0; i < 15; i++) {
> size = 4096 << i;
> ptr[i] = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
> if (ptr == NULL)
> err("NULL returned, i=%d\n", i);
There are two problems with this code:
- mmap() returns MAP_FAILED, not NULL, on faulure.
- "ptr" will never be null anyway! I think you really want to
be testing ptr[i].
> *((int *)ptr) = 0xdeadbeef;
...and, here again, you want to be dereferencing ptr[i].
> }
> for (i = 0; i < 15; i++) {
> size = 4096 << i;
> munmap(ptr[i], size);
> }
> }
> }
>
> Jun-Young
>
> --
> Bang Jun-Young <junyoung@NetBSD.org>
>
-- Jason R. Thorpe <thorpej@wasabisystems.com>