RFC: replace ptmalloc2
Jörn Engel
joern@purestorage.com
Wed Oct 15 04:52:00 GMT 2014
On Wed, Oct 15, 2014 at 12:00:31AM -0400, Rich Felker wrote:
>
> What benchmark are you using? I'd like to run it on my malloc.
Something pretty primitive that grew out of a simple memhog. Use at
your own risk.
Jörn
--
If every man who wrote a story which was indirectly inspired by Poe
were to pay a tithe toward a monument it would be such as would dwarf
the pyramids.
-- Sir Arthur Conan Doyle
---
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dlmalloc.h"
#define NO_WORKERS 8
#define MAX_ALLOC ((1ull << 31) / NO_WORKERS)
static void *worker(void *arg)
{
unsigned long *p;
int i, e;
uint64_t subtotal = 0;
for (i = 0; ;i++) {
for (e = 0; e < 17; e++) {
size_t size = 5 << e;
subtotal += size;
p = dlmalloc(size);
if (!p)
return NULL;
memset(p, 1, size);
}
if (i % 1000 == 0 || subtotal >= MAX_ALLOC) {
if (subtotal >= MAX_ALLOC) {
printf("%p: done\n", &subtotal);
return NULL;
}
}
}
}
int main(void)
{
int i, err;
pthread_t tid[NO_WORKERS];
for (i = 0; i < NO_WORKERS; i++) {
err = pthread_create(tid + i, NULL, worker, NULL);
if (err)
return 1;
}
for (i = 0; i < NO_WORKERS; i++) {
pthread_join(tid[i], NULL);
}
system("cp /proc/`pgrep memhog`/maps .");
system("cp /proc/`pgrep memhog`/status .");
return 0;
}
More information about the Libc-alpha
mailing list