2
0

ALLOCM_ARENA.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #define JEMALLOC_MANGLE
  2. #include "jemalloc_test.h"
  3. #define NTHREADS 10
  4. void *
  5. je_thread_start(void *arg)
  6. {
  7. unsigned thread_ind = (unsigned)(uintptr_t)arg;
  8. unsigned arena_ind;
  9. int r;
  10. void *p;
  11. size_t rsz, sz;
  12. sz = sizeof(arena_ind);
  13. if (mallctl("arenas.extend", &arena_ind, &sz, NULL, 0)
  14. != 0) {
  15. malloc_printf("Error in arenas.extend\n");
  16. abort();
  17. }
  18. if (thread_ind % 4 != 3) {
  19. size_t mib[3];
  20. size_t miblen = sizeof(mib) / sizeof(size_t);
  21. const char *dss_precs[] = {"disabled", "primary", "secondary"};
  22. const char *dss = dss_precs[thread_ind % 4];
  23. if (mallctlnametomib("arena.0.dss", mib, &miblen) != 0) {
  24. malloc_printf("Error in mallctlnametomib()\n");
  25. abort();
  26. }
  27. mib[1] = arena_ind;
  28. if (mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss,
  29. sizeof(const char *))) {
  30. malloc_printf("Error in mallctlbymib()\n");
  31. abort();
  32. }
  33. }
  34. r = allocm(&p, &rsz, 1, ALLOCM_ARENA(arena_ind));
  35. if (r != ALLOCM_SUCCESS) {
  36. malloc_printf("Unexpected allocm() error\n");
  37. abort();
  38. }
  39. return (NULL);
  40. }
  41. int
  42. main(void)
  43. {
  44. je_thread_t threads[NTHREADS];
  45. unsigned i;
  46. malloc_printf("Test begin\n");
  47. for (i = 0; i < NTHREADS; i++) {
  48. je_thread_create(&threads[i], je_thread_start,
  49. (void *)(uintptr_t)i);
  50. }
  51. for (i = 0; i < NTHREADS; i++)
  52. je_thread_join(threads[i], NULL);
  53. malloc_printf("Test end\n");
  54. return (0);
  55. }