OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.6 KiB

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