|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h> |
|
|
|
|
|
|
|
|
#include "pagealign_alloc.h" |
|
|
|
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <unistd.h> |
|
|
|
|
|
#include "resource-ext.h" |
|
|
|
|
|
static size_t pagesize; |
|
|
|
|
|
|
|
|
static int |
|
|
allocate_some_pages (void) |
|
|
{ |
|
|
int i; |
|
|
|
|
|
for (i = 1; i <= 9; i++) |
|
|
if (pagealign_alloc (pagesize) == NULL) |
|
|
return -1; |
|
|
for (i = 1; i <= 2; i++) |
|
|
if (pagealign_alloc (2 * pagesize) == NULL) |
|
|
return -1; |
|
|
for (i = 1; i <= 1; i++) |
|
|
if (pagealign_alloc (3 * pagesize) == NULL) |
|
|
return -1; |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
|
static size_t |
|
|
size_of_some_pages (void) |
|
|
{ |
|
|
return 16 * pagesize; |
|
|
} |
|
|
|
|
|
static void |
|
|
show_stats (intptr_t initial_as, intptr_t initial_data, int count) |
|
|
{ |
|
|
if (count == 0) |
|
|
printf ("Allocation failed.\n"); |
|
|
else |
|
|
{ |
|
|
intptr_t requested = count * size_of_some_pages (); |
|
|
intptr_t as_increase = get_rusage_as () - initial_as; |
|
|
intptr_t data_increase = get_rusage_data () - initial_data; |
|
|
printf ("count = %5d: requested: %6ld pages, " |
|
|
"allocated AS: %6ld pages (%.2f%%), " |
|
|
"allocated DATA: %6ld pages (%.2f%%)\n", |
|
|
count, |
|
|
(long int) (requested / pagesize), |
|
|
(long int) (as_increase / pagesize), |
|
|
100 * (double) as_increase / (double) requested, |
|
|
(long int) (data_increase / pagesize), |
|
|
100 * (double) data_increase / (double) requested); |
|
|
} |
|
|
} |
|
|
|
|
|
static void |
|
|
do_test (void) |
|
|
{ |
|
|
intptr_t initial_as = get_rusage_as (); |
|
|
intptr_t initial_data = get_rusage_data (); |
|
|
int count; |
|
|
for (count = 0; count <= 10000; count++) |
|
|
{ |
|
|
if (count == 10 || count == 30 || count == 90 || count == 270 |
|
|
|| count == 810 || count == 2430 || count == 7290) |
|
|
show_stats (initial_as, initial_data, count); |
|
|
|
|
|
if (allocate_some_pages () < 0) |
|
|
break; |
|
|
} |
|
|
show_stats (initial_as, initial_data, count); |
|
|
} |
|
|
|
|
|
int |
|
|
main (int argc, char *argv[]) |
|
|
{ |
|
|
if (argc != 2) |
|
|
{ |
|
|
fprintf (stderr, "Usage: %s TESTS\n", argv[0]); |
|
|
fprintf (stderr, "Example: %s {a|b|c|d|e|f}\n", argv[0]); |
|
|
exit (1); |
|
|
} |
|
|
|
|
|
const char *tests = argv[1]; |
|
|
|
|
|
pagesize = getpagesize (); |
|
|
|
|
|
|
|
|
size_t i; |
|
|
for (i = 0; i < strlen (tests); i++) |
|
|
{ |
|
|
char test = tests[i]; |
|
|
|
|
|
switch (test) |
|
|
{ |
|
|
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
|
|
pagealign_impl = test - 'a'; |
|
|
do_test (); |
|
|
break; |
|
|
default: |
|
|
|
|
|
; |
|
|
} |
|
|
} |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|