Skip to content

Larson sized deallocation test #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ The first set of benchmarks are real world programs and consist of:
objects to be freed by other threads. Larson and Krishnan observe this
behavior (which they call _bleeding_) in actual server applications,
and the benchmark simulates this.
- __larsonN-sized__: same as the __larsonN__ except it uses sized deallocation calls which
have a fast path in some allocators.

The second set of benchmarks are stress tests and consist of:

Expand Down
8 changes: 8 additions & 0 deletions bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ run_sc=0

run_cfrac=0
run_larson=0
run_larson_sized=0
run_ebizzy=0
run_sh6bench=0
run_sh8bench=0
Expand Down Expand Up @@ -169,6 +170,7 @@ while : ; do
run_lean=1
run_xmalloc_test=1
run_larson=1
run_larson_sized=1
run_cscratch=1
run_mstress=1
if [ -z "$darwin" ]; then
Expand Down Expand Up @@ -228,6 +230,8 @@ while : ; do
run_barnes=1;;
larson)
run_larson=1;;
larson-sized)
run_larson_sized=1;;
ebizzy)
run_ebizzy=1;;
sh6bench)
Expand Down Expand Up @@ -306,6 +310,7 @@ while : ; do
echo " redis run redis benchmark"
echo " spec=<num> run selected spec2017 benchmarks (if available)"
echo " larson run larsonN"
echo " larson-sized run larsonN sized deallocation test"
echo " alloc-test run alloc-testN"
echo " xmalloc-test run xmalloc-testN"
echo " sh6bench run sh6benchN"
Expand Down Expand Up @@ -608,6 +613,9 @@ fi
if test "$run_larson" = "1"; then
run_test "larsonN" "./larson 5 8 1000 5000 100 4141 $procs"
fi
if test "$run_larson_sized" = "1"; then
run_test "larsonN-sized" "./larson-sized 5 8 1000 5000 100 4141 $procs"
fi
if test "$run_ebizzy" = "1"; then
run_test "ebizzy" "./ebizzy -t $procs -M -S 2 -s 128"
fi
Expand Down
5 changes: 5 additions & 0 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ target_compile_options(larson PRIVATE -Wno-unused-result)
target_compile_definitions(larson PRIVATE CPP=1)
target_link_libraries(larson pthread)

add_executable(larson-sized larson/larson.cpp)
target_compile_options(larson-sized PRIVATE -Wno-unused-result -fsized-deallocation)
target_compile_definitions(larson-sized PRIVATE CPP=1 SIZED=1)
target_link_libraries(larson-sized pthread)

if(NOT APPLE)
add_executable(alloc-test alloc-test/test_common.cpp alloc-test/allocator_tester.cpp)
target_compile_definitions(alloc-test PRIVATE BENCH=4)
Expand Down
2 changes: 2 additions & 0 deletions bench/larson/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Test driver for memory allocators
Author: Paul Larson, [email protected]

Updated to support C++14 sized deallocation with CPP.
33 changes: 25 additions & 8 deletions bench/larson/larson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <pthread.h>
#endif


typedef void * LPVOID;
typedef long long LONGLONG;
typedef long DWORD;
Expand Down Expand Up @@ -177,7 +176,7 @@ typedef struct thr_data {
int max_size ;

char * *array ;
int *blksize ;
size_t *blksize ;
int asize ;

long cAllocs ;
Expand All @@ -200,7 +199,7 @@ static long lran2(struct lran2_st* d) ;
ULONG CountReservedSpace() ;

char * blkp[MAX_BLOCKS] ;
int blksize[MAX_BLOCKS] ;
size_t blksize[MAX_BLOCKS] ;
long seqlock=0 ;
struct lran2_st rgen ;
int min_size=10, max_size=500 ;
Expand Down Expand Up @@ -280,7 +279,11 @@ int main (int argc, char *argv[])
printf( "\nSingle-threaded test driver \n") ;
#endif
#ifdef CPP
#if defined(SIZED)
printf("C++ version (new and sized delete)\n") ;
#else
printf("C++ version (new and delete)\n") ;
#endif
#else
printf("C version (malloc and free)\n") ;
#endif
Expand Down Expand Up @@ -353,7 +356,7 @@ void runloops(long sleep_cnt, int num_chunks )
{
int cblks ;
int victim ;
int blk_size ;
size_t blk_size ;
#ifdef __WIN32__
_LARGE_INTEGER ticks_per_sec, start_cnt, end_cnt;
#else
Expand Down Expand Up @@ -388,9 +391,11 @@ void runloops(long sleep_cnt, int num_chunks )
for( cblks=0; cblks<num_chunks; cblks++){
victim = lran2(&rgen)%num_chunks ;
#if defined(CPP)
#if defined(SIZED)
operator delete[] (blkp[victim], blksize[victim]);
#else
delete[] blkp[victim] ;
#elif defined(USE_MALLOC)
free(blkp[victim]);
#endif
#else
CUSTOM_FREE(blkp[victim]) ;
#endif
Expand Down Expand Up @@ -578,7 +583,7 @@ static void * exercise_heap( void *pinput)
thread_data *pdea;
int cblks=0 ;
int victim ;
long blk_size ;
size_t blk_size;
int range ;

if( stopflag ) return 0;
Expand All @@ -592,7 +597,11 @@ static void * exercise_heap( void *pinput)
for( cblks=0; cblks<pdea->NumBlocks; cblks++){
victim = lran2(&pdea->rgen)%pdea->asize ;
#ifdef CPP
#if defined(SIZED)
operator delete[] (pdea->array[victim], pdea->blksize[victim]);
#else
delete[] pdea->array[victim] ;
#endif
#else
CUSTOM_FREE(pdea->array[victim]) ;
#endif
Expand Down Expand Up @@ -652,8 +661,9 @@ static void warmup(char **blkp, int num_chunks )
{
int cblks ;
int victim ;
int blk_size ;
size_t blk_size ;
LPVOID tmp ;
size_t tmp_sz;


for( cblks=0; cblks<num_chunks; cblks++){
Expand All @@ -675,14 +685,21 @@ static void warmup(char **blkp, int num_chunks )
for( cblks=num_chunks; cblks > 0 ; cblks--){
victim = lran2(&rgen)%cblks ;
tmp = blkp[victim] ;
tmp_sz = blksize[victim];
blkp[victim] = blkp[cblks-1] ;
blksize[victim] = blksize[cblks-1];
blkp[cblks-1] = (char *) tmp ;
blksize[cblks-1] = tmp_sz;
}

for( cblks=0; cblks<4*num_chunks; cblks++){
victim = lran2(&rgen)%num_chunks ;
#ifdef CPP
#if defined(SIZED)
operator delete[] (blkp[victim], blksize[victim]);
#else
delete[] blkp[victim] ;
#endif
#else
CUSTOM_FREE(blkp[victim]) ;
#endif
Expand Down