cvs commit: src/lib/libc/sys mmap.2
Dag-Erling Smørgrav
des at des.no
Sat Mar 25 09:41:38 UTC 2006
Jason Evans <jasone at FreeBSD.org> writes:
> By choosing a malloc size of 1MB in your test program, you just
> happened to pick the worst possible case for malloc chunk
> fragmentation (50% utilization). In reality, the reason that you
> hit a limit of 697 on i386 is that you used pretty much the entire
> mmap()able address space (2*697MB == 1394MB). On i386, jemalloc
> switches from sbrk() to mmap() when heap space runs out.
How about this, then, with malloc(1024):
% ulimit -d
2097152
% ./allocate
2861145 kB
% ulimit -d $((1024*1024))
% ./allocate
1861209 kB
% ulimit -d $((512*1024))
% ./allocate
1361241 kB
In all cases, it should stop when it reaches dsiz.
DES
--
Dag-Erling Smørgrav - des at des.no
-------------- next part --------------
/*
* cc -Wall -pedantic -std=c99 -O2 -pipe -o allocate allocate.c
*/
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
static volatile sig_atomic_t sig_caught;
static void
sig_handler(int sig)
{
sig_caught = sig;
}
int
main(void)
{
int i = 0;
signal(SIGINT, sig_handler);
while (!sig_caught && malloc(1024) != NULL) {
if (++i % 128 == 0)
printf("\r%d MB", i / 1024);
fflush(stdout);
}
printf("\r%d kB\n", i);
if (sig_caught)
printf("interrupted\n");
exit(0);
}
More information about the cvs-src
mailing list