Sourceware Bugzilla – Attachment 8667 Details for
Bug 19048
malloc: arena free list can become cyclic, increasing contention
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
arena_test.c
arena_test.c (text/plain), 2.55 KB, created by
Paulo Andrade
on 2015-10-01 21:14:48 UTC
(
hide
)
Description:
arena_test.c
Filename:
MIME Type:
Creator:
Paulo Andrade
Created:
2015-10-01 21:14:48 UTC
Size:
2.55 KB
patch
obsolete
>/* > >gcc -o arena_test arena_test.c -pthread -static > > */ > >#include <stdio.h> >#include <stdlib.h> >#include <unistd.h> >#include <pthread.h> >#include <sys/syscall.h> > >#define NUM_THREADS 126 > >static void >spawn_threads(void); > >typedef struct arena_info arena_info_t; >struct arena_info { > void *arena; > long count; >}; > >pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; >arena_info_t *arenas; >int num_arenas; >pthread_t pthreads[NUM_THREADS]; >volatile int got_info = 0; > >/* This is really ugly, but should be good enough for a (not so) quick > * way to get the, per thread __libc_tsd_MALLOC value */ >static void >get__libc_tsd_MALLOC(void) >{ > int i; > FILE *pp; > void *ptr; > char buf[4096]; > if (got_info) > return; > got_info = 1; > sprintf(buf, "./arena_test.pl %d %d", getpid(), syscall(SYS_gettid)); > pp = popen(buf, "r"); > while (fscanf(pp, "%x", &ptr) == 1) { > for (i = 0; i < num_arenas; ++i) { > if (arenas[i].arena == ptr) { > ++arenas[i].count; > break; > } > } > if (i == num_arenas) { > if (num_arenas % 16 == 0) > arenas = realloc(arenas, sizeof(arena_info_t) * (num_arenas + 16)); > arenas[num_arenas].arena = ptr; > arenas[num_arenas].count = 1; > ++num_arenas; > } > } > pclose(pp); >} > >static void * >run(void *arg) >{ > int i; > long delay = (long)arg; > void **alloc; > alloc = malloc(sizeof(void*) * 1024); > for (i = 0; i < 1024; ++i) > alloc[i] = malloc(1024); > usleep(delay * 100000); > for (i = 0; i < 1024; ++i) > free(alloc[i]); > free(alloc); > pthread_mutex_lock(&g_lock); > get__libc_tsd_MALLOC(); > pthread_mutex_unlock(&g_lock); > return NULL; >} > >static void >spawn_threads(void) >{ > int i; > for (i = 0; i < 2; ++i) > pthread_create(pthreads + i, NULL, run, (void*)32); > for (i = 2; i < 2 + 4; ++i) > pthread_create(pthreads + i, NULL, run, (void*)16); > for (i = 6; i < 2 + 4 + 8; ++i) > pthread_create(pthreads + i, NULL, run, (void*)8); > for (i = 14; i < 2 + 4 + 8 + 16; ++i) > pthread_create(pthreads + i, NULL, run, (void*)4); > for (i = 30; i < 2 + 4 + 8 + 16 + 32; ++i) > pthread_create(pthreads + i, NULL, run, (void*)2); > for (i = 62; i < 2 + 4 + 8 + 16 + 32 + 64; ++i) > pthread_create(pthreads + i, NULL, run, (void*)1); > for (i = 0; i < NUM_THREADS; ++i) > pthread_join(pthreads[i], NULL); >} > >int >main(int argc, char *argv[]) >{ > int i; > while (1) { > got_info = 0; > spawn_threads(); > printf("Arena Count\n"); > printf("------------------------\n"); > for (i = 0; i < num_arenas; ++i) > printf("%-16p %-8d\n", arenas[i].arena, arenas[i].count); > } > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 19048
:
8666
| 8667 |
8668
|
8669
|
8672
|
8674
|
8700
|
8718
|
8719