pastebin - collaborative debugging tool
rovema.kpaste.net RSS


glibc_malloc_tuneables1.ksh - Simple automated test for malloc tuneables
Posted by Anonymous on Mon 24th Jul 2023 11:19
raw | new post
view followups (newest first): glibc_malloc_tuneables1.ksh - Simple automated test for malloc tuneables by Anonymous

  1. #!/bin/ksh
  2.  
  3. #
  4. # glibc_malloc_tuneables1.ksh - Simple automated test for malloc tuneables
  5. #
  6.  
  7. printf $"# Generating test source...\n"
  8.  
  9. rm -f 'glibc_malloc_tuneables1.c'
  10. cat >'glibc_malloc_tuneables1.c' <<EOF
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <unistd.h>
  14.  
  15. int main(int ac, char *av[])
  16. {
  17. #define NUM_ARRAY_ELEMENTS (16)
  18.         void *p[NUM_ARRAY_ELEMENTS];
  19.         int i;
  20.        
  21.         /* Allocate */
  22.         for (i=0 ; i < NUM_ARRAY_ELEMENTS ; i++)
  23.                 p[i] = malloc(16*1024*1024);
  24.        
  25.         (void)sleep(1);
  26.        
  27.         for (i=0 ; i < NUM_ARRAY_ELEMENTS ; i++)
  28.                 free(p[i]);
  29.  
  30.         return EXIT_SUCCESS;
  31. }
  32. EOF
  33.  
  34.  
  35. printf $"\n# Building test executable...\n"
  36. rm -f 'glibc_malloc_tuneables1'
  37. gcc -Wall -m32 -g glibc_malloc_tun#!/bin/ksh
  38.  
  39. #
  40. # glibc_malloc_tuneables1.ksh - Simple automated test for malloc tuneables
  41. #
  42.  
  43. printf $"# Generating test source...\n"
  44.  
  45. rm -f 'glibc_malloc_tuneables1.c'
  46. cat >'glibc_malloc_tuneables1.c' <<EOF
  47. #include <stdlib.h>
  48. #include <stdio.h>
  49. #include <unistd.h>
  50.  
  51. int main(int ac, char *av[])
  52. {
  53. #define NUM_ARRAY_ELEMENTS (16)
  54.         void *p[NUM_ARRAY_ELEMENTS];
  55.         int i;
  56.        
  57.         /* Allocate */
  58.         for (i=0 ; i < NUM_ARRAY_ELEMENTS ; i++)
  59.                 p[i] = malloc(16*1024*1024);
  60.        
  61.         (void)sleep(1);
  62.        
  63.         for (i=0 ; i < NUM_ARRAY_ELEMENTS ; i++)
  64.                 free(p[i]);
  65.  
  66.         return EXIT_SUCCESS;
  67. }
  68. EOF
  69.  
  70.  
  71. printf $"\n# Building test executable...\n"
  72. rm -f 'glibc_malloc_tuneables1'
  73. gcc -Wall -m32 -g glibc_malloc_tuneables1.c -o glibc_malloc_tuneables1
  74.  
  75.  
  76. printf $"\n# Test run with default allocator settings\n"
  77. env - strace ./glibc_malloc_tuneables1 2>&1 | egrep 'mmap.*\(NULL,.+MAP_ANON.+\)'
  78. printf $"\n# Test run with MALLOC_MMAP_MAX_=0 allocator settings\n"
  79. env - MALLOC_MMAP_MAX_=0 strace ./glibc_malloc_tuneables1 2>&1 | egrep 'mmap.*\(NULL,.+MAP_ANON.+\)'
  80. # EOF.
  81. eables1.c -o glibc_malloc_tuneables1
  82.  
  83.  
  84. printf $"\n# Test run with default allocator settings\n"
  85. env - strace ./glibc_malloc_tuneables1 2>&1 | egrep 'mmap.*\(NULL,.+MAP_ANON.+\)'
  86. printf $"\n# Test run with MALLOC_MMAP_MAX_=0 allocator settings\n"
  87. env - MALLOC_MMAP_MAX_=0 strace ./glibc_malloc_tuneables1 2>&1 | egrep 'mmap.*\(NULL,.+MAP_ANON.+\)'
  88. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at