fix fifoallocator with different memattr

This commit is contained in:
tushicheng
2023-06-06 03:42:17 +00:00
committed by ob-robot
parent e4279e8bee
commit 502448cead
4 changed files with 19 additions and 30 deletions

View File

@ -276,20 +276,16 @@ bool ObFIFOAllocator::check_magic(void *p, int64_t &size)
void *ObFIFOAllocator::alloc(const int64_t size) void *ObFIFOAllocator::alloc(const int64_t size)
{ {
return alloc_align(size, 16, attr_); return alloc_align(size, 16);
} }
void *ObFIFOAllocator::alloc(const int64_t size, const ObMemAttr &attr) void *ObFIFOAllocator::alloc(const int64_t size, const ObMemAttr &attr)
{ {
return alloc_align(size, 16, attr); UNUSED(attr);
return alloc_align(size, 16);
} }
void *ObFIFOAllocator::alloc_align(const int64_t size, const int64_t align) void *ObFIFOAllocator::alloc_align(const int64_t size, const int64_t align)
{
return alloc_align(size, align, attr_);
}
void *ObFIFOAllocator::alloc_align(const int64_t size, const int64_t align, const ObMemAttr &attr)
{ {
ObLockGuard<ObSpinLock> guard(lock_); ObLockGuard<ObSpinLock> guard(lock_);
void *ptr = nullptr; void *ptr = nullptr;
@ -298,16 +294,16 @@ void *ObFIFOAllocator::alloc_align(const int64_t size, const int64_t align, cons
} else if (!check_param(size, align)) { } else if (!check_param(size, align)) {
LOG_WARN_RET(OB_INVALID_ARGUMENT, "ObFIFOAllocator alloc(size, align) parameter Error.", K(size), K(align)); LOG_WARN_RET(OB_INVALID_ARGUMENT, "ObFIFOAllocator alloc(size, align) parameter Error.", K(size), K(align));
} else if (is_normal_page_enough(size, align)) { } else if (is_normal_page_enough(size, align)) {
ptr = alloc_normal(size, align, attr); ptr = alloc_normal(size, align);
} else { } else {
ptr = alloc_special(size, align, attr); ptr = alloc_special(size, align);
} }
return ptr; return ptr;
} }
// get a new page, set current_using_ pointing to it. // get a new page, set current_using_ pointing to it.
void ObFIFOAllocator::alloc_new_normal_page(const ObMemAttr &attr) void ObFIFOAllocator::alloc_new_normal_page()
{ {
if (IS_NOT_INIT || OB_ISNULL(allocator_)) { if (IS_NOT_INIT || OB_ISNULL(allocator_)) {
LOG_ERROR_RET(OB_NOT_INIT, "ObFIFOAllocator not init"); LOG_ERROR_RET(OB_NOT_INIT, "ObFIFOAllocator not init");
@ -318,7 +314,7 @@ void ObFIFOAllocator::alloc_new_normal_page(const ObMemAttr &attr)
} }
if (nullptr == new_page) { if (nullptr == new_page) {
if (total() + page_size_ <= max_size_) { if (total() + page_size_ <= max_size_) {
void *ptr = allocator_->alloc(page_size_, attr); void *ptr = allocator_->alloc(page_size_, attr_);
if (OB_NOT_NULL(ptr)) { if (OB_NOT_NULL(ptr)) {
new_page = new (ptr) NormalPageHeader(); new_page = new (ptr) NormalPageHeader();
} else { } else {
@ -401,7 +397,7 @@ void ObFIFOAllocator::free(void *p)
} }
} }
void *ObFIFOAllocator::alloc_normal(int64_t size, int64_t align, const ObMemAttr &attr) void *ObFIFOAllocator::alloc_normal(int64_t size, int64_t align)
{ {
void *ptr = nullptr; void *ptr = nullptr;
void *new_space = nullptr; void *new_space = nullptr;
@ -410,7 +406,7 @@ void *ObFIFOAllocator::alloc_normal(int64_t size, int64_t align, const ObMemAttr
} else { } else {
if (nullptr == current_using_) { if (nullptr == current_using_) {
if (total() + page_size_ <= max_size_) { if (total() + page_size_ <= max_size_) {
new_space = allocator_->alloc(page_size_, attr); new_space = allocator_->alloc(page_size_, attr_);
} }
if (nullptr == new_space) { if (nullptr == new_space) {
LOG_WARN_RET(OB_ALLOCATE_MEMORY_FAILED, "can not allocate new page", K(page_size_)); LOG_WARN_RET(OB_ALLOCATE_MEMORY_FAILED, "can not allocate new page", K(page_size_));
@ -427,7 +423,7 @@ void *ObFIFOAllocator::alloc_normal(int64_t size, int64_t align, const ObMemAttr
ptr = try_alloc(size, align); ptr = try_alloc(size, align);
// current_page_do not have enough space. // current_page_do not have enough space.
if (nullptr == ptr) { if (nullptr == ptr) {
alloc_new_normal_page(attr); alloc_new_normal_page();
ptr = try_alloc(size, align); ptr = try_alloc(size, align);
} }
if (ptr != nullptr) { if (ptr != nullptr) {
@ -469,7 +465,7 @@ void ObFIFOAllocator::free_normal(NormalPageHeader *page, int64_t size)
| hole | | hole |
|--------------------| |--------------------|
*/ */
void *ObFIFOAllocator::alloc_special(int64_t size, int64_t align, const ObMemAttr &attr) void *ObFIFOAllocator::alloc_special(int64_t size, int64_t align)
{ {
void *ptr = NULL; void *ptr = NULL;
@ -482,7 +478,7 @@ void *ObFIFOAllocator::alloc_special(int64_t size, int64_t align, const ObMemAtt
// these bytes may be before (align 1) AND after user data (align 2). // these bytes may be before (align 1) AND after user data (align 2).
// one of them can be zero. // one of them can be zero.
int64_t real_size = size + sizeof(SpecialPageHeader) + sizeof(AllocHeader) + align - 1; int64_t real_size = size + sizeof(SpecialPageHeader) + sizeof(AllocHeader) + align - 1;
void *new_space = allocator_->alloc(real_size, attr); void *new_space = allocator_->alloc(real_size, attr_);
if (NULL == new_space) { if (NULL == new_space) {
LOG_WARN_RET(OB_ALLOCATE_MEMORY_FAILED, "can not alloc a page from underlying allocator", K(real_size)); LOG_WARN_RET(OB_ALLOCATE_MEMORY_FAILED, "can not alloc a page from underlying allocator", K(real_size));
} else { } else {

View File

@ -97,7 +97,7 @@ public:
void reset(); void reset();
void *alloc(const int64_t size); void *alloc(const int64_t size);
void *alloc(const int64_t size, const ObMemAttr &attr); void *alloc(const int64_t size, const ObMemAttr &attr);
void *alloc_align(const int64_t size, const int64_t align); virtual void *alloc_align(const int64_t size, const int64_t align);
void free(void *p); void free(void *p);
void set_label(const lib::ObLabel &label) { attr_.label_ = label; } void set_label(const lib::ObLabel &label) { attr_.label_ = label; }
void set_attr(const ObMemAttr &attr) { attr_ = attr; } void set_attr(const ObMemAttr &attr) { attr_ = attr; }
@ -127,9 +127,6 @@ public:
return normal_total() + special_total_; return normal_total() + special_total_;
} }
protected:
virtual void *alloc_align(const int64_t size, const int64_t align, const ObMemAttr &attr);
private: private:
BasePageHeader *get_page_header(void *p); BasePageHeader *get_page_header(void *p);
bool check_param(const int64_t size, const int64_t align); bool check_param(const int64_t size, const int64_t align);
@ -141,10 +138,10 @@ private:
return (max_free_size >= size); return (max_free_size >= size);
} }
void *try_alloc(const int64_t size, const int64_t align); void *try_alloc(const int64_t size, const int64_t align);
void alloc_new_normal_page(const ObMemAttr &attr); void alloc_new_normal_page();
void *alloc_normal(const int64_t size, const int64_t align, const ObMemAttr &attr); void *alloc_normal(const int64_t size, const int64_t align);
void free_normal(NormalPageHeader *page, int64_t size); void free_normal(NormalPageHeader *page, int64_t size);
void *alloc_special(const int64_t size, const int64_t align, const ObMemAttr &attr); void *alloc_special(const int64_t size, const int64_t align);
void free_special(SpecialPageHeader *page); void free_special(SpecialPageHeader *page);
int sync_idle(const int64_t idle_size, const int64_t max_size) ; int sync_idle(const int64_t idle_size, const int64_t max_size) ;
private: private:

View File

@ -1625,13 +1625,12 @@ int ObTenantMetaMemMgr::GetWashTabletCandidate::operator()(
void *ObTenantMetaMemMgr::TenantMetaAllocator::alloc_align( void *ObTenantMetaMemMgr::TenantMetaAllocator::alloc_align(
const int64_t size, const int64_t size,
const int64_t align, const int64_t align)
const ObMemAttr &attr)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
void *ptr = nullptr; void *ptr = nullptr;
const int64_t max_wait_ts = ObTimeUtility::fast_current_time() + 1000L * 1000L * 3L; // 3s const int64_t max_wait_ts = ObTimeUtility::fast_current_time() + 1000L * 1000L * 3L; // 3s
while (OB_ISNULL(ptr = ObFIFOAllocator::alloc_align(size, align, attr)) while (OB_ISNULL(ptr = ObFIFOAllocator::alloc_align(size, align))
&& OB_SUCC(ret) && OB_SUCC(ret)
&& max_wait_ts - ObTimeUtility::fast_current_time() >= 0) { && max_wait_ts - ObTimeUtility::fast_current_time() >= 0) {
ob_usleep(1); ob_usleep(1);

View File

@ -383,10 +383,7 @@ private:
virtual ~TenantMetaAllocator() = default; virtual ~TenantMetaAllocator() = default;
TO_STRING_KV("used", used(), "total", total()); TO_STRING_KV("used", used(), "total", total());
protected: protected:
virtual void *alloc_align( virtual void *alloc_align(const int64_t size, const int64_t align) override;
const int64_t size,
const int64_t align,
const ObMemAttr &attr) override;
private: private:
TryWashTabletFunc &wash_func_; TryWashTabletFunc &wash_func_;
}; };