Skip to content

Commit

Permalink
fix TLS alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMakeev committed Oct 6, 2023
1 parent 53a0463 commit 3bab5cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion SmMalloc/smmalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void TlsPoolBucket::Init(uint32_t* pCacheStack, uint32_t maxElementsNum, CacheWa
for (uint32_t j = 0; j < num; j++)
{
// allocate from global (pThreadCache is still nullptr)
void* p = alloc->Allocate<false>(elementSize, 16);
void* p = alloc->Allocate<false>(elementSize, Allocator::kMinValidAlignment);
if (p == nullptr)
{
break;
Expand Down Expand Up @@ -260,6 +260,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(bucketSizeInBytes, kMinValidAlignment));
SM_ASSERT(IsAligned(size_t(bucket.pData), alignmentMax) && "Incorrect alignment detected!");
bucket.Create(bucketSizeInBytes);
bucketsDataBegin[i] = bucket.pData;
Expand Down
7 changes: 3 additions & 4 deletions SmMalloc/smmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ struct GenericAllocator
class Allocator
{
public:
static const size_t kMinValidAlignment = 16;
static const size_t kMinValidAlignment = 4;

private:
static const size_t kMaxValidAlignment = 128;
static const size_t kMaxValidAlignment = 4096;

friend struct internal::TlsPoolBucket;

Expand Down Expand Up @@ -539,8 +539,7 @@ class Allocator
bool isValidBucket = false;
#endif

// only allocate from thread-local cache is alignment is compatible
if (bucketIndex < bucketsCount && IsAligned(alignment, 16))
if (bucketIndex < bucketsCount)
{
#ifdef SMMALLOC_STATS_SUPPORT
isValidBucket = true;
Expand Down

0 comments on commit 3bab5cb

Please sign in to comment.