[CP] Optimize cpu consumption of slice allocator

This commit is contained in:
obdev
2023-10-25 06:39:29 +00:00
committed by ob-robot
parent f7f7642085
commit 5586d55073

View File

@ -301,11 +301,14 @@ public:
class Arena
{
public:
Arena(): blk_(NULL) {}
Arena(): lock_(ObLatchIds::OB_DLIST_LOCK), blk_(NULL) {}
void lock() { lock_.lock(); }
void unlock() { lock_.unlock(); }
Block* blk() { return ATOMIC_LOAD(&blk_); }
bool cas(Block* ov, Block* nv) { return ATOMIC_BCAS(&blk_, ov, nv); }
Block* clear() { return ATOMIC_TAS(&blk_, NULL); }
private:
mutable common::ObSpinLock lock_;
Block* blk_;
} CACHE_ALIGNED;
ObSliceAlloc(): nway_(0), bsize_(0), isize_(0),
@ -359,6 +362,9 @@ public:
Arena& arena = arena_[get_itid() % nway_];
Block* blk = arena.blk();
if (NULL == blk) {
arena.lock();
DEFER(arena.unlock());
if (NULL == arena.blk()) {
Block* new_blk = prepare_block();
if (NULL == new_blk) {
// alloc block fail, end
@ -368,6 +374,7 @@ public:
release_block(new_blk);
}
}
}
} else {
Block* blk2release = NULL;
int64_t slot_idx = ObBlockSlicer::hash((uint64_t)blk) % MAX_REF_NUM;