Skip to content

Commit

Permalink
switch back to linear partitioning by default
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMakeev committed Oct 5, 2023
1 parent 5801413 commit 4fbcb32
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
6 changes: 3 additions & 3 deletions SmMalloc/smmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#endif

#if !defined(SMM_LINEAR_PARTITIONING) && !defined(SMM_FLOAT_PARTITIONING)
//#define SMM_LINEAR_PARTITIONING
#define SMM_LINEAR_PARTITIONING
/*
Simple linear partitioning: every bucket size grow by 16 bytes
Expand All @@ -81,10 +81,10 @@
49->800, 50->816, 51->832, 52->848, 53->864, 54->880, 55->896, 56->912, 57->928, 58->944, 59->960, 60->976, 61->992
*/

#define SMM_FLOAT_PARTITIONING
//#define SMM_FLOAT_PARTITIONING
/*
Use Sebastian Aaltonen floating point partitioning idea (https://github.com/sebbbi/OffsetAllocator)
This is slightly slower than SMM_LINEAR_PARTITIONING but might be less wastefull in case if you need to handle big-enough allocations
This is SLOWER! than SMM_LINEAR_PARTITIONING but might be less wastefull in case if you need to handle big-enough allocations
Note: smmalloc floating point is different (2 bit mantissa + 6 bit exponent) and biased to better serve common C++ allocation sizes
Expand Down
4 changes: 2 additions & 2 deletions smmalloc_perf01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void printDebug(sm_allocator) {}
// ============ smmalloc with thread cache enabled ============
#define ALLOCATOR_TEST_NAME sm
#define HEAP sm_allocator
#define CREATE_HEAP _sm_allocator_create(5, (48 * 1024 * 1024))
#define CREATE_HEAP _sm_allocator_create(10, (48 * 1024 * 1024))
#define DESTROY_HEAP \
printDebug(heap); \
_sm_allocator_destroy(heap)
Expand All @@ -116,7 +116,7 @@ void printDebug(sm_allocator) {}
// ============ smmalloc with thread cache disabled ============
#define ALLOCATOR_TEST_NAME sm_tcd
#define HEAP sm_allocator
#define CREATE_HEAP _sm_allocator_create(5, (48 * 1024 * 1024))
#define CREATE_HEAP _sm_allocator_create(10, (48 * 1024 * 1024))
#define DESTROY_HEAP \
printDebug(heap); \
_sm_allocator_destroy(heap)
Expand Down
28 changes: 27 additions & 1 deletion smmalloc_perf02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ UBENCH_EX(PerfTest, smmalloc_10m)
UBenchGlobals& g = UBenchGlobals::get();
size_t wsSize = g.workingSet.size();

sm_allocator space = _sm_allocator_create(5, (48 * 1024 * 1024));
sm_allocator space = _sm_allocator_create(12, (32 * 1024 * 1024));

UBENCH_DO_BENCHMARK()
{
Expand Down Expand Up @@ -78,6 +78,32 @@ UBENCH_EX(PerfTest, smmalloc_10m)
}
}

#ifdef SMMALLOC_STATS_SUPPORT
const sm::GlobalStats& gstats = space->GetGlobalStats();
printf("Allocations attempts: %zu\n", gstats.totalNumAllocationAttempts.load());
printf("Allocations served: %zu\n", gstats.totalAllocationsServed.load());
printf("Allocated using default malloc: %zu\n", gstats.totalAllocationsRoutedToDefaultAllocator.load());
printf(" - Because of size %zu\n", gstats.routingReasonBySize.load());
printf(" - Because of saturation %zu\n", gstats.routingReasonSaturation.load());
size_t bucketsCount = space->GetBucketsCount();
for (size_t bucketIndex = 0; bucketIndex < bucketsCount; bucketIndex++)
{
uint32_t elementsCount = space->GetBucketElementsCount(bucketIndex);
size_t elementsSize = sm::getBucketSizeInBytesByIndex(bucketIndex);
printf("Bucket[%zu], Elements[%d], SizeOf[%zu] -----\n", bucketIndex, elementsCount, elementsSize);
const sm::BucketStats* stats = space->GetBucketStats(bucketIndex);
if (!stats)
{
continue;
}

printf(" Cache Hit : %zu\n", stats->cacheHitCount.load());
printf(" Hits : %zu\n", stats->hitCount.load());
printf(" Misses : %zu\n", stats->missCount.load());
printf(" Operations : %zu\n", stats->cacheHitCount.load() + stats->hitCount.load() + stats->missCount.load());
}
#endif

_sm_allocator_destroy(space);
}

Expand Down

0 comments on commit 4fbcb32

Please sign in to comment.