malloc-arena-size.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. diff -ruNp a/malloc/arena.c b/malloc/arena.c
  2. --- a/malloc/arena.c
  3. +++ b/malloc/arena.c
  4. @@ -21,6 +21,27 @@
  5. /* Compile-time constants. */
  6. +#ifndef HEAP_MAX_SIZE
  7. +# ifdef DEFAULT_MMAP_THRESHOLD_MAX
  8. +# define DEFAULT_HEAP_MAX_SIZE (2 * DEFAULT_MMAP_THRESHOLD_MAX)
  9. +# else
  10. +# define DEFAULT_HEAP_MAX_SIZE (1024 * 1024) /* must be a power of two */
  11. +# endif
  12. +# include <sysdep.h>
  13. +static long int heap_max_size = 0;
  14. +# define HEAP_MAX_SIZE \
  15. + ({ \
  16. + if (!heap_max_size) { \
  17. + long int size = glibc_option("heap_size"); \
  18. + if (size > 0) \
  19. + heap_max_size = size; \
  20. + else \
  21. + heap_max_size = DEFAULT_HEAP_MAX_SIZE; \
  22. + } \
  23. + heap_max_size; \
  24. + })
  25. +#endif
  26. +
  27. #define HEAP_MIN_SIZE (32 * 1024)
  28. #ifndef HEAP_MAX_SIZE
  29. # ifdef DEFAULT_MMAP_THRESHOLD_MAX
  30. @@ -556,17 +577,6 @@ new_heap (size_t size, size_t top_pad)
  31. mapping (on Linux, this is the case for all non-writable mappings
  32. anyway). */
  33. p2 = MAP_FAILED;
  34. - if (aligned_heap_area)
  35. - {
  36. - p2 = (char *) MMAP (aligned_heap_area, HEAP_MAX_SIZE, PROT_NONE,
  37. - MAP_NORESERVE);
  38. - aligned_heap_area = NULL;
  39. - if (p2 != MAP_FAILED && ((unsigned long) p2 & (HEAP_MAX_SIZE - 1)))
  40. - {
  41. - __munmap (p2, HEAP_MAX_SIZE);
  42. - p2 = MAP_FAILED;
  43. - }
  44. - }
  45. if (p2 == MAP_FAILED)
  46. {
  47. p1 = (char *) MMAP (0, HEAP_MAX_SIZE << 1, PROT_NONE, MAP_NORESERVE);
  48. @@ -577,8 +587,6 @@ new_heap (size_t size, size_t top_pad)
  49. ul = p2 - p1;
  50. if (ul)
  51. __munmap (p1, ul);
  52. - else
  53. - aligned_heap_area = p2 + HEAP_MAX_SIZE;
  54. __munmap (p2 + HEAP_MAX_SIZE, HEAP_MAX_SIZE - ul);
  55. }
  56. else