Re: mmap(2) performance netbsd-1-6 vs. -current
Jason Thorpe <[email protected]>
| Newsgroups | gmane.os.netbsd.devel.kernel,gmane.os.netbsd.devel.performance |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]>
>
-- Jason R. Thorpe <[email protected]>