diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-11-21 19:26:58 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-11-21 19:26:58 +0100 |
| commit | 69ddf7df0daac4845e46397967a850277913e358 (patch) | |
| tree | e776b4f2ff03504955967eea1925fb6d10adc9e6 | |
| parent | 9e1d58c70aa03522bb5dac28ad58508c4dfc1fa1 (diff) | |
| download | allocbench-69ddf7df0daac4845e46397967a850277913e358.tar.gz allocbench-69ddf7df0daac4845e46397967a850277913e358.zip | |
don't use fixed sizes to aquire life data
| -rw-r--r-- | src/benchmarks/blowup/blowup.c | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/src/benchmarks/blowup/blowup.c b/src/benchmarks/blowup/blowup.c index defb58c..37ba6d6 100644 --- a/src/benchmarks/blowup/blowup.c +++ b/src/benchmarks/blowup/blowup.c @@ -1,42 +1,67 @@ +#include <malloc.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define NUM_THREADS 10 -#define ALLOCATIONS 1024 * 100 -#define SIZE 1024 +#define LIFE_DATA (1024l * 1024 * 100) // 100 MiB +#define ALLOCATIONS 100000l // 100000 +#define MAX_SIZE (1024l * 16) // 16KiB -static void do_work() -{ - void** ptrs; +typedef struct chunk { + struct chunk* next; + char data[]; +} chunk_t; - ptrs = malloc(sizeof(void*) * ALLOCATIONS); - if (ptrs == NULL) { - perror("malloc"); - return; - } +static inline size_t rand_size() +{ + return (rand() % MAX_SIZE) + sizeof(chunk_t); +} - for(int i = 0; i < ALLOCATIONS; i++) - { - ptrs[i] = malloc(SIZE); - memset(ptrs[i], 0, SIZE); +static void do_work() +{ + chunk_t* head = NULL; + chunk_t* tail = NULL; + size_t to_allocate = LIFE_DATA; + + // allocate life data + while(to_allocate > 0) { + size_t size = rand_size(); + if (size > to_allocate) + size = to_allocate; + + to_allocate -= size; + chunk_t* cur = (chunk_t*) malloc(size); + // touch memory + memset(&cur->data, 0, size - sizeof(struct chunk*)); + + if(!head) { + head = tail = cur; + } + else { + tail->next = cur; + tail = cur; + } } + // Do some random allocations to change the allocators state for(int i = 0; i < ALLOCATIONS; i++) { - free(malloc(SIZE)); + free(malloc(rand_size())); } - for(int i = 0; i < ALLOCATIONS; i++) - { - /* memset(ptrs[i], 0, SIZE); */ - free(ptrs[i]); - } + // free life data + do { + chunk_t* next = head->next; + free(head); + head = next; + } while(head != tail); + // Do some random allocations to change the allocators state for(int i = 0; i < ALLOCATIONS; i++) { - free(malloc(SIZE)); + free(malloc(rand_size())); } return; |
