Skip to content

Commit

Permalink
update copyright year + improve debug statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMakeev committed Oct 6, 2023
1 parent 4fbcb32 commit ef2fadc
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 27 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Sergey Makeev
Copyright (c) 2017-2023 Sergey Makeev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions SmMalloc/smmalloc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2017-2021 Sergey Makeev
// Copyright (c) 2017-2023 Sergey Makeev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -259,7 +259,7 @@ void Allocator::Init(uint32_t _bucketsCount, size_t _bucketSizeInBytes)
bucket.pData = pBuffer.get() + i * bucketSizeInBytes;
bucket.pBufferEnd = bucket.pData + bucketSizeInBytes;
size_t bucketSizeInBytes = getBucketSizeInBytesByIndex(i);
SM_ASSERT(IsAligned(size_t(bucket.pData), GetNextPow2(uint32_t(bucketSizeInBytes))) && "Alignment failed");
SM_ASSERT(IsAligned(size_t(bucket.pData), alignmentMax) && "Incorrect alignment detected!");
bucket.Create(bucketSizeInBytes);
bucketsDataBegin[i] = bucket.pData;
}
Expand Down
2 changes: 1 addition & 1 deletion SmMalloc/smmalloc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2017-2021 Sergey Makeev
// Copyright (c) 2017-2023 Sergey Makeev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion SmMalloc/smmalloc_generic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2017-2021 Sergey Makeev
// Copyright (c) 2017-2023 Sergey Makeev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion SmMalloc/smmalloc_tls.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2017-2021 Sergey Makeev
// Copyright (c) 2017-2023 Sergey Makeev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
15 changes: 10 additions & 5 deletions smmalloc_perf01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ struct PerfTestGlobals
void printDebug(sm_allocator heap)
{
const sm::GlobalStats& gstats = heap->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 numAllocationAttempts = gstats.totalNumAllocationAttempts.load();
size_t numAllocationsServed = gstats.totalAllocationsServed.load();
size_t numAllocationsRouted = gstats.totalAllocationsRoutedToDefaultAllocator.load();
double servedPercentage = (numAllocationAttempts == 0) ? 0.0 : (double(numAllocationsServed) / double(numAllocationAttempts) * 100.0);
double routedPercentage = (numAllocationAttempts == 0) ? 0.0 : (double(numAllocationsRouted) / double(numAllocationAttempts) * 100.0);
printf("Allocation attempts: %zu\n", numAllocationAttempts);
printf("Allocations served: %zu (%3.2f%%)\n", numAllocationsServed, servedPercentage);
printf("Allocated using default malloc: %zu (%3.2f%%)\n", numAllocationsRouted, routedPercentage);
printf(" - Because of size: %zu\n", gstats.routingReasonBySize.load());
printf(" - Because of saturation: %zu\n", gstats.routingReasonSaturation.load());

size_t bucketsCount = heap->GetBucketsCount();
for (size_t bucketIndex = 0; bucketIndex < bucketsCount; bucketIndex++)
Expand Down
15 changes: 10 additions & 5 deletions smmalloc_perf02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ 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 numAllocationAttempts = gstats.totalNumAllocationAttempts.load();
size_t numAllocationsServed = gstats.totalAllocationsServed.load();
size_t numAllocationsRouted = gstats.totalAllocationsRoutedToDefaultAllocator.load();
double servedPercentage = (numAllocationAttempts == 0) ? 0.0 : (double(numAllocationsServed) / double(numAllocationAttempts) * 100.0);
double routedPercentage = (numAllocationAttempts == 0) ? 0.0 : (double(numAllocationsRouted) / double(numAllocationAttempts) * 100.0);
printf("Allocation attempts: %zu\n", numAllocationAttempts);
printf("Allocations served: %zu (%3.2f%%)\n", numAllocationsServed, servedPercentage);
printf("Allocated using default malloc: %zu (%3.2f%%)\n", numAllocationsRouted, routedPercentage);
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++)
{
Expand Down
15 changes: 10 additions & 5 deletions smmalloc_test01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ TEST(SimpleTests, MegaAlloc)

#ifdef SMMALLOC_STATS_SUPPORT
const sm::GlobalStats& gstats = heap->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 numAllocationAttempts = gstats.totalNumAllocationAttempts.load();
size_t numAllocationsServed = gstats.totalAllocationsServed.load();
size_t numAllocationsRouted = gstats.totalAllocationsRoutedToDefaultAllocator.load();
double servedPercentage = (numAllocationAttempts == 0) ? 0.0 : (double(numAllocationsServed) / double(numAllocationAttempts) * 100.0);
double routedPercentage = (numAllocationAttempts == 0) ? 0.0 : (double(numAllocationsRouted) / double(numAllocationAttempts) * 100.0);
printf("Allocation attempts: %zu\n", numAllocationAttempts);
printf("Allocations served: %zu (%3.2f%%)\n", numAllocationsServed, servedPercentage);
printf("Allocated using default malloc: %zu (%3.2f%%)\n", numAllocationsRouted, routedPercentage);
printf(" - Because of size: %zu\n", gstats.routingReasonBySize.load());
printf(" - Because of saturation: %zu\n", gstats.routingReasonSaturation.load());
size_t bucketsCount = heap->GetBucketsCount();
for (size_t bucketIndex = 0; bucketIndex < bucketsCount; bucketIndex++)
{
Expand Down
17 changes: 11 additions & 6 deletions smmalloc_test02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void ThreadFunc2(sm_allocator heap)

TEST(MultithreadingTests, MtPerformance)
{
sm_allocator heap = _sm_allocator_create(5, (48 * 1024 * 1024));
sm_allocator heap = _sm_allocator_create(8, (48 * 1024 * 1024));

operationsCount.store(0);
int threadsCount = std::thread::hardware_concurrency();
Expand Down Expand Up @@ -188,11 +188,16 @@ TEST(MultithreadingTests, MtPerformance)

#ifdef SMMALLOC_STATS_SUPPORT
const sm::GlobalStats& gstats = heap->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 numAllocationAttempts = gstats.totalNumAllocationAttempts.load();
size_t numAllocationsServed = gstats.totalAllocationsServed.load();
size_t numAllocationsRouted = gstats.totalAllocationsRoutedToDefaultAllocator.load();
double servedPercentage = (numAllocationAttempts == 0) ? 0.0 : (double(numAllocationsServed) / double(numAllocationAttempts) * 100.0);
double routedPercentage = (numAllocationAttempts == 0) ? 0.0 : (double(numAllocationsRouted) / double(numAllocationAttempts) * 100.0);
printf("Allocation attempts: %zu\n", numAllocationAttempts);
printf("Allocations served: %zu (%3.2f%%)\n", numAllocationsServed, servedPercentage);
printf("Allocated using default malloc: %zu (%3.2f%%)\n", numAllocationsRouted, routedPercentage);
printf(" - Because of size: %zu\n", gstats.routingReasonBySize.load());
printf(" - Because of saturation: %zu\n", gstats.routingReasonSaturation.load());
size_t bucketsCount = heap->GetBucketsCount();
for (size_t bucketIndex = 0; bucketIndex < bucketsCount; bucketIndex++)
{
Expand Down

0 comments on commit ef2fadc

Please sign in to comment.