Test Harness for Malloc
By user12610965 on Oct 06, 2011
I recently had the need for a test harness for testing malloc performance for multi-threaded applications. The harness creates a number of allocation threads based on an input parameter. It creates a freeing thread for each allocation thread. It does a number of allocations per loop according to input parameters. It counts loops as the metric of interest. It uses a random number generator (see man rand_r) to select the size of each allocation. The maximum allocation size is an input parameter. We shall use 5000 allocations per loop and let each test run for approximately 1200 seconds. We will use maximum allocation sizes of 256,1024,4096,16384, and 65536 bytes. We will use LD_PRELOAD_64 to instruct the linker to preload the library to be tested. The use of LD_PRELOAD is also a method of implementing each library in production. Another method of using a different memory allocator is to link the library when the application is built (-lmtmalloc, for example).
The input parameters are explained below and the source code is available at.
Get test harness here
The test program, malloc_test, takes the following flags:
-c sample count, how many three second samples to publish
-t thread count
-s memset the allocations, 0=no, 1=yes
-m maximum allocation size in bytes
-r use a random number generator to determine the allocation size
-n number of allocations per loop, 5000 is the maximum
-f do a fixed number of loops and then exit, 0=no, xx=number of loops
Inside the zip file, test_harness/mtmalloc/tests/generic/runtest.ksh is a sample driver for the harness.