patch-lib_mm_memlock_c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. --- LVM2.2.02.114.orig/lib/mm/memlock.c 2014-11-29 00:07:42.000000000 +0100
  2. +++ LVM2.2.02.114/lib/mm/memlock.c 2015-02-28 09:44:51.000000000 +0100
  3. @@ -25,7 +25,6 @@
  4. #include <sys/mman.h>
  5. #include <sys/time.h>
  6. #include <sys/resource.h>
  7. -#include <malloc.h>
  8. #ifndef DEVMAPPER_SUPPORT
  9. @@ -134,10 +133,8 @@ static void _touch_memory(void *mem, siz
  10. static void _allocate_memory(void)
  11. {
  12. #ifndef VALGRIND_POOL
  13. - void *stack_mem;
  14. + void *stack_mem, *temp_malloc_mem;
  15. struct rlimit limit;
  16. - int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks;
  17. - char *areas[max_areas];
  18. /* Check if we could preallocate requested stack */
  19. if ((getrlimit (RLIMIT_STACK, &limit) == 0) &&
  20. @@ -146,50 +143,13 @@ static void _allocate_memory(void)
  21. _touch_memory(stack_mem, _size_stack);
  22. /* FIXME else warn user setting got ignored */
  23. - /*
  24. - * When a brk() fails due to fragmented address space (which sometimes
  25. - * happens when we try to grab 8M or so), glibc will make a new
  26. - * arena. In this arena, the rules for using “direct” mmap are relaxed,
  27. - * circumventing the MAX_MMAPs and MMAP_THRESHOLD settings. We can,
  28. - * however, detect when this happens with mallinfo() and try to co-opt
  29. - * malloc into using MMAP as a MORECORE substitute instead of returning
  30. - * MMAP'd memory directly. Since MMAP-as-MORECORE does not munmap the
  31. - * memory on free(), this is good enough for our purposes.
  32. - */
  33. - while (missing > 0) {
  34. - struct mallinfo inf = mallinfo();
  35. - hblks = inf.hblks;
  36. -
  37. - if ((areas[area] = malloc(_size_malloc_tmp)))
  38. - _touch_memory(areas[area], _size_malloc_tmp);
  39. -
  40. - inf = mallinfo();
  41. -
  42. - if (hblks < inf.hblks) {
  43. - /* malloc cheated and used mmap, even though we told it
  44. - not to; we try with twice as many areas, each half
  45. - the size, to circumvent the faulty logic in glibc */
  46. - free(areas[area]);
  47. - _size_malloc_tmp /= 2;
  48. - } else {
  49. - ++ area;
  50. - missing -= _size_malloc_tmp;
  51. - }
  52. -
  53. - if (area == max_areas && missing > 0) {
  54. - /* Too bad. Warn the user and proceed, as things are
  55. - * most likely going to work out anyway. */
  56. - log_warn("WARNING: Failed to reserve memory, %d bytes missing.", missing);
  57. - break;
  58. - }
  59. - }
  60. + if ((temp_malloc_mem = malloc(_size_malloc_tmp)))
  61. + _touch_memory(temp_malloc_mem, _size_malloc_tmp);
  62. if ((_malloc_mem = malloc(_size_malloc)))
  63. _touch_memory(_malloc_mem, _size_malloc);
  64. - /* free up the reserves so subsequent malloc's can use that memory */
  65. - for (i = 0; i < area; ++i)
  66. - free(areas[i]);
  67. + free(temp_malloc_mem);
  68. #endif
  69. }