Skip to content
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

[not for commit] Change compressed pointer type to 64 bits #324

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 1 addition & 1 deletion cachelib/allocator/CacheAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ class CacheAllocator : public CacheBase {
sizeof(typename RefcountWithFlags::Value) + sizeof(uint32_t) +
sizeof(uint32_t) + sizeof(KAllocation)) == sizeof(Item),
"vtable overhead");
static_assert(32 == sizeof(Item), "item overhead is 32 bytes");
static_assert(44 == sizeof(Item), "item overhead is 44 bytes");

// make sure there is no overhead in ChainedItem on top of a regular Item
static_assert(sizeof(Item) == sizeof(ChainedItem),
Expand Down
19 changes: 9 additions & 10 deletions cachelib/allocator/memory/CompressedPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SlabAllocator;

class CACHELIB_PACKED_ATTR CompressedPtr {
public:
using PtrType = uint32_t;
using PtrType = uint64_t;
// Thrift doesn't support unsigned type
using SerializedPtrType = int64_t;

Expand All @@ -75,8 +75,7 @@ class CACHELIB_PACKED_ATTR CompressedPtr {

// maximum addressable memory for pointer compression to work.
static constexpr size_t getMaxAddressableSize() noexcept {
return static_cast<size_t>(1)
<< (numSlabIdxBits(false) + Slab::kNumSlabBits);
return std::numeric_limits<size_t>::max();
}

// default construct to nullptr.
Expand All @@ -95,7 +94,7 @@ class CACHELIB_PACKED_ATTR CompressedPtr {
private:
// null pointer representation. This is almost never guaranteed to be a
// valid pointer that we can compress to.
static constexpr PtrType kNull = 0xffffffff;
static constexpr PtrType kNull = 0xffffffffffffffffULL;

// default construct to null.
PtrType ptr_{kNull};
Expand All @@ -116,7 +115,7 @@ class CACHELIB_PACKED_ATTR CompressedPtr {
Slab::kNumSlabBits - Slab::kMinAllocPower;

// Use 32nd bit position for TierId
static constexpr unsigned int kNumTierIdxOffset = 31;
static constexpr unsigned int kNumTierIdxOffset = 63;

static constexpr PtrType kAllocIdxMask = ((PtrType)1 << kNumAllocIdxBits) - 1;

Expand All @@ -140,12 +139,12 @@ class CACHELIB_PACKED_ATTR CompressedPtr {
bool isMultiTiered,
TierId tid) noexcept {
XDCHECK_LE(allocIdx, kAllocIdxMask);
XDCHECK_LT(slabIdx, (1u << numSlabIdxBits(isMultiTiered)) - 1);
XDCHECK_LT(slabIdx, (1llu << numSlabIdxBits(isMultiTiered)) - 1);
if (!isMultiTiered) {
return (slabIdx << kNumAllocIdxBits) + allocIdx;
return (static_cast<PtrType>(slabIdx) << kNumAllocIdxBits) + allocIdx;
}
return (static_cast<uint32_t>(tid) << kNumTierIdxOffset) +
(slabIdx << kNumAllocIdxBits) + allocIdx;
return (static_cast<PtrType>(tid) << kNumTierIdxOffset) +
(static_cast<PtrType>(slabIdx) << kNumAllocIdxBits) + allocIdx;
}

// Get the slab index of the compressed ptr
Expand All @@ -169,7 +168,7 @@ class CACHELIB_PACKED_ATTR CompressedPtr {
}

void setTierId(TierId tid) noexcept {
ptr_ += static_cast<uint32_t>(tid) << kNumTierIdxOffset;
ptr_ += static_cast<PtrType>(tid) << kNumTierIdxOffset;
}

friend SlabAllocator;
Expand Down
Loading