Skip to content

Commit af8f0a6

Browse files
authored
Merge pull request #25 from jq-rs/larson_sized_test
Larson sized deallocation test
2 parents 0941b33 + e570436 commit af8f0a6

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ The first set of benchmarks are real world programs and consist of:
126126
objects to be freed by other threads. Larson and Krishnan observe this
127127
behavior (which they call _bleeding_) in actual server applications,
128128
and the benchmark simulates this.
129+
- __larsonN-sized__: same as the __larsonN__ except it uses sized deallocation calls which
130+
have a fast path in some allocators.
129131

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

bench.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ run_sc=0
3232

3333
run_cfrac=0
3434
run_larson=0
35+
run_larson_sized=0
3536
run_ebizzy=0
3637
run_sh6bench=0
3738
run_sh8bench=0
@@ -177,6 +178,7 @@ while : ; do
177178
run_lean=1
178179
run_xmalloc_test=1
179180
run_larson=1
181+
run_larson_sized=1
180182
run_cscratch=1
181183
run_mstress=1
182184
if [ -z "$darwin" ]; then
@@ -242,6 +244,8 @@ while : ; do
242244
run_barnes=1;;
243245
larson)
244246
run_larson=1;;
247+
larson-sized)
248+
run_larson_sized=1;;
245249
ebizzy)
246250
run_ebizzy=1;;
247251
sh6bench)
@@ -323,6 +327,7 @@ while : ; do
323327
echo " redis run redis benchmark"
324328
echo " spec=<num> run selected spec2017 benchmarks (if available)"
325329
echo " larson run larsonN"
330+
echo " larson-sized run larsonN sized deallocation test"
326331
echo " alloc-test run alloc-testN"
327332
echo " xmalloc-test run xmalloc-testN"
328333
echo " sh6bench run sh6benchN"
@@ -648,6 +653,9 @@ fi
648653
if test "$run_larson" = "1"; then
649654
run_test "larsonN" "./larson 5 8 1000 5000 100 4141 $procs"
650655
fi
656+
if test "$run_larson_sized" = "1"; then
657+
run_test "larsonN-sized" "./larson-sized 5 8 1000 5000 100 4141 $procs"
658+
fi
651659
if test "$run_ebizzy" = "1"; then
652660
run_test "ebizzy" "./ebizzy -t $procs -M -S 2 -s 128"
653661
fi

bench/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ target_compile_options(larson PRIVATE -Wno-unused-result)
6060
target_compile_definitions(larson PRIVATE CPP=1)
6161
target_link_libraries(larson pthread)
6262

63+
add_executable(larson-sized larson/larson.cpp)
64+
target_compile_options(larson-sized PRIVATE -Wno-unused-result -fsized-deallocation)
65+
target_compile_definitions(larson-sized PRIVATE CPP=1 SIZED=1)
66+
target_link_libraries(larson-sized pthread)
67+
6368
if(NOT APPLE)
6469
add_executable(alloc-test alloc-test/test_common.cpp alloc-test/allocator_tester.cpp)
6570
target_compile_definitions(alloc-test PRIVATE BENCH=4)

bench/larson/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Test driver for memory allocators
22
Author: Paul Larson, [email protected]
3+
4+
Updated to support C++14 sized deallocation with CPP.

bench/larson/larson.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <pthread.h>
3030
#endif
3131

32-
3332
typedef void * LPVOID;
3433
typedef long long LONGLONG;
3534
typedef long DWORD;
@@ -177,7 +176,7 @@ typedef struct thr_data {
177176
int max_size ;
178177

179178
char * *array ;
180-
int *blksize ;
179+
size_t *blksize ;
181180
int asize ;
182181

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

202201
char * blkp[MAX_BLOCKS] ;
203-
int blksize[MAX_BLOCKS] ;
202+
size_t blksize[MAX_BLOCKS] ;
204203
long seqlock=0 ;
205204
struct lran2_st rgen ;
206205
int min_size=10, max_size=500 ;
@@ -280,7 +279,11 @@ int main (int argc, char *argv[])
280279
printf( "\nSingle-threaded test driver \n") ;
281280
#endif
282281
#ifdef CPP
282+
#if defined(SIZED)
283+
printf("C++ version (new and sized delete)\n") ;
284+
#else
283285
printf("C++ version (new and delete)\n") ;
286+
#endif
284287
#else
285288
printf("C version (malloc and free)\n") ;
286289
#endif
@@ -353,7 +356,7 @@ void runloops(long sleep_cnt, int num_chunks )
353356
{
354357
int cblks ;
355358
int victim ;
356-
int blk_size ;
359+
size_t blk_size ;
357360
#ifdef __WIN32__
358361
_LARGE_INTEGER ticks_per_sec, start_cnt, end_cnt;
359362
#else
@@ -388,9 +391,11 @@ void runloops(long sleep_cnt, int num_chunks )
388391
for( cblks=0; cblks<num_chunks; cblks++){
389392
victim = lran2(&rgen)%num_chunks ;
390393
#if defined(CPP)
394+
#if defined(SIZED)
395+
operator delete[] (blkp[victim], blksize[victim]);
396+
#else
391397
delete[] blkp[victim] ;
392-
#elif defined(USE_MALLOC)
393-
free(blkp[victim]);
398+
#endif
394399
#else
395400
CUSTOM_FREE(blkp[victim]) ;
396401
#endif
@@ -578,7 +583,7 @@ static void * exercise_heap( void *pinput)
578583
thread_data *pdea;
579584
int cblks=0 ;
580585
int victim ;
581-
long blk_size ;
586+
size_t blk_size;
582587
int range ;
583588

584589
if( stopflag ) return 0;
@@ -592,7 +597,11 @@ static void * exercise_heap( void *pinput)
592597
for( cblks=0; cblks<pdea->NumBlocks; cblks++){
593598
victim = lran2(&pdea->rgen)%pdea->asize ;
594599
#ifdef CPP
600+
#if defined(SIZED)
601+
operator delete[] (pdea->array[victim], pdea->blksize[victim]);
602+
#else
595603
delete[] pdea->array[victim] ;
604+
#endif
596605
#else
597606
CUSTOM_FREE(pdea->array[victim]) ;
598607
#endif
@@ -652,8 +661,9 @@ static void warmup(char **blkp, int num_chunks )
652661
{
653662
int cblks ;
654663
int victim ;
655-
int blk_size ;
664+
size_t blk_size ;
656665
LPVOID tmp ;
666+
size_t tmp_sz;
657667

658668

659669
for( cblks=0; cblks<num_chunks; cblks++){
@@ -675,14 +685,21 @@ static void warmup(char **blkp, int num_chunks )
675685
for( cblks=num_chunks; cblks > 0 ; cblks--){
676686
victim = lran2(&rgen)%cblks ;
677687
tmp = blkp[victim] ;
688+
tmp_sz = blksize[victim];
678689
blkp[victim] = blkp[cblks-1] ;
690+
blksize[victim] = blksize[cblks-1];
679691
blkp[cblks-1] = (char *) tmp ;
692+
blksize[cblks-1] = tmp_sz;
680693
}
681694

682695
for( cblks=0; cblks<4*num_chunks; cblks++){
683696
victim = lran2(&rgen)%num_chunks ;
684697
#ifdef CPP
698+
#if defined(SIZED)
699+
operator delete[] (blkp[victim], blksize[victim]);
700+
#else
685701
delete[] blkp[victim] ;
702+
#endif
686703
#else
687704
CUSTOM_FREE(blkp[victim]) ;
688705
#endif

0 commit comments

Comments
 (0)