BUGFIX: make memstore statistics correct

This commit is contained in:
obdev
2023-02-08 20:07:20 +08:00
committed by ob-robot
parent 838cce3c5d
commit 3dcb0c68b7
2 changed files with 25 additions and 19 deletions

View File

@ -142,7 +142,7 @@ void ObFifoArena::shrink_cached_page(int64_t nway)
if (NULL != ref) {
// There may be concurrent removal, no need to pay attention to the return value
UNUSED(ATOMIC_BCAS(paddr, page, NULL));
IGNORE_RETURN ATOMIC_FAA(&retired_, page->hold());
IGNORE_RETURN ATOMIC_FAA(&retired_, page->get_actual_hold_size());
release_ref(ref);
}
}
@ -169,7 +169,7 @@ void* ObFifoArena::alloc(int64_t adv_idx, Handle& handle, int64_t size)
ret = OB_ALLOCATE_MEMORY_FAILED;
} else {
bool need_switch = false;
handle.add_allocated(page->hold());
handle.add_allocated(page->get_actual_hold_size());
ptr = handle.ref_and_alloc(way_id, need_switch, page, size);
page->frozen();
retire_page(way_id, handle, page);
@ -200,7 +200,7 @@ void* ObFifoArena::alloc(int64_t adv_idx, Handle& handle, int64_t size)
UNUSED(ATOMIC_BCAS(paddr, page, NULL));
ret = OB_ALLOCATE_MEMORY_FAILED;
} else if (ATOMIC_BCAS(paddr, page, new_page)) {
handle.add_allocated(new_page->hold());
handle.add_allocated(new_page->get_actual_hold_size());
} else {
destroy_page(new_page);
}
@ -239,8 +239,8 @@ ObFifoArena::Page* ObFifoArena::alloc_page(int64_t size)
{
Page* page = (Page*)allocator_->alloc(size, attr_);
if (NULL != page) {
ATOMIC_FAA(&allocated_, size);
ATOMIC_FAA(&total_hold_, size);
ATOMIC_FAA(&allocated_, page->get_actual_hold_size());
ATOMIC_FAA(&total_hold_, page->get_actual_hold_size());
ATOMIC_AAF(&hold_, page->get_actual_hold_size());
page->set(size);
}
@ -250,8 +250,8 @@ ObFifoArena::Page* ObFifoArena::alloc_page(int64_t size)
void ObFifoArena::free_page(Page* page)
{
if (NULL != page && NULL != allocator_) {
ATOMIC_FAA(&reclaimed_, page->hold());
ATOMIC_FAA(&total_hold_, -page->hold());
ATOMIC_FAA(&reclaimed_, page->get_actual_hold_size());
ATOMIC_FAA(&total_hold_, -page->get_actual_hold_size());
ATOMIC_FAA(&hold_, -page->get_actual_hold_size());
allocator_->free(page);
}
@ -260,7 +260,7 @@ void ObFifoArena::free_page(Page* page)
void ObFifoArena::retire_page(int64_t idx, Handle& handle, Page* page)
{
if (NULL != page) {
ATOMIC_FAA(&retired_, page->hold());
ATOMIC_FAA(&retired_, page->get_actual_hold_size());
handle.add_ref(idx, &page->self_ref_);
}
}
@ -268,8 +268,9 @@ void ObFifoArena::retire_page(int64_t idx, Handle& handle, Page* page)
void ObFifoArena::destroy_page(Page* page)
{
if (NULL != page && NULL != allocator_) {
ATOMIC_FAA(&allocated_, -page->hold());
ATOMIC_FAA(&total_hold_, -page->hold());
ATOMIC_FAA(&allocated_, -page->get_actual_hold_size());
ATOMIC_FAA(&total_hold_, -page->get_actual_hold_size());
ATOMIC_FAA(&hold_, -page->get_actual_hold_size());
allocator_->free(page);
}
}

View File

@ -44,7 +44,7 @@ public:
}
Ref* next_;
Page* page_;
int64_t allocated_;
int64_t allocated_; // the allocated bytes from page
};
struct Page
@ -81,9 +81,9 @@ public:
return ref;
}
int64_t get_actual_hold_size();
Ref self_ref_;
int64_t limit_;
int64_t pos_;
Ref self_ref_; // record the allocated bytes from page, include self_ref_ itself
int64_t limit_; // the max bytes of a page that can be used
int64_t pos_; // the position after which can be allocated
int64_t ref_;
char buf_[0];
};
@ -141,7 +141,8 @@ public:
TO_STRING_KV(K_(allocated));
int64_t lock_;
Ref* ref_[MAX_NWAY];
int64_t allocated_;
int64_t allocated_; // record all the memory hold by pages, include the size of page structure, AObject and so on.
// only increase while a page is created.
};
public:
@ -233,10 +234,14 @@ private:
lib::ObMemAttr attr_;
lib::ObIAllocator *allocator_;
int64_t nway_;
int64_t allocated_;
int64_t reclaimed_;
int64_t hold_;//for single tenant
int64_t retired_;
int64_t allocated_; // record all the memory hold by pages in history.
// increase while a page created and decrease only if a failed page destroyed.
int64_t reclaimed_; // record all the memory reclaimed by pages in history.
// increase while a page freed.
int64_t hold_; // record all the memory hold by pages current.
// increase while a page created and decrease while a page freed or destroyed.
// (may be: hold_ = allocated_ - reclaimed_)
int64_t retired_; // record all the memory hold by not active pages in history.
int64_t max_seq_;
int64_t clock_;