This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: RFC: replace ptmalloc2
- From: Jörn Engel <joern at purestorage dot com>
- To: Rich Felker <dalias at libc dot org>
- Cc: Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 14 Oct 2014 21:52:38 -0700
- Subject: Re: RFC: replace ptmalloc2
- Authentication-results: sourceware.org; auth=none
- References: <20141009215447 dot GD8583 at Sligo dot logfs dot org> <CAAHN_R0JDNQkx7oV0HS9Knv7nsPZiARLeFb4zpPa+rj7cNfECg at mail dot gmail dot com> <20141010010743 dot GA15146 at Sligo dot logfs dot org> <20141010012530 dot GX23797 at brightrain dot aerifal dot cx> <20141010013302 dot GC15146 at Sligo dot logfs dot org> <20141010020229 dot GY23797 at brightrain dot aerifal dot cx> <20141014233254 dot GA1860 at Sligo dot logfs dot org> <20141015040031 dot GR32028 at brightrain dot aerifal dot cx>
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;
}