mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
feat(server): Better accounting of DenseSet memory (#2325)
This commit is contained in:
parent
6905389d60
commit
4929e3c777
2 changed files with 11 additions and 21 deletions
|
@ -184,7 +184,7 @@ void DenseSet::ClearInternal() {
|
|||
|
||||
entries_.clear();
|
||||
num_used_buckets_ = 0;
|
||||
num_chain_entries_ = 0;
|
||||
num_links_ = 0;
|
||||
size_ = 0;
|
||||
expiration_used_ = false;
|
||||
}
|
||||
|
@ -426,10 +426,6 @@ void DenseSet::AddUnique(void* obj, bool has_ttl, uint64_t hashcode) {
|
|||
bucket_id -= unlinked.GetDisplacedDirection();
|
||||
}
|
||||
|
||||
if (!entries_[bucket_id].IsEmpty()) {
|
||||
++num_chain_entries_;
|
||||
}
|
||||
|
||||
DCHECK_EQ(BucketId(to_insert.GetObject(), 0), bucket_id);
|
||||
ChainVectorIterator list = entries_.begin() + bucket_id;
|
||||
PushFront(list, to_insert);
|
||||
|
@ -497,7 +493,6 @@ void DenseSet::Delete(DensePtr* prev, DensePtr* ptr) {
|
|||
} else {
|
||||
DCHECK(prev->IsLink());
|
||||
|
||||
--num_chain_entries_;
|
||||
DenseLinkKey* plink = prev->AsLink();
|
||||
DensePtr tmp = DensePtr::From(plink);
|
||||
DCHECK(ObjectAllocSize(tmp.GetObject()));
|
||||
|
@ -512,7 +507,6 @@ void DenseSet::Delete(DensePtr* prev, DensePtr* ptr) {
|
|||
DenseLinkKey* link = ptr->AsLink();
|
||||
obj = link->Raw();
|
||||
*ptr = link->next;
|
||||
--num_chain_entries_;
|
||||
FreeLink(link);
|
||||
}
|
||||
|
||||
|
@ -538,10 +532,7 @@ void* DenseSet::PopInternal() {
|
|||
ExpireIfNeeded(nullptr, &(*bucket_iter));
|
||||
} while (bucket_iter->IsEmpty());
|
||||
|
||||
if (bucket_iter->IsLink()) {
|
||||
--num_chain_entries_;
|
||||
} else {
|
||||
DCHECK(bucket_iter->IsObject());
|
||||
if (bucket_iter->IsObject()) {
|
||||
--num_used_buckets_;
|
||||
}
|
||||
|
||||
|
@ -663,6 +654,8 @@ auto DenseSet::NewLink(void* data, DensePtr next) -> DenseLinkKey* {
|
|||
|
||||
lk->next = next;
|
||||
lk->SetObject(data);
|
||||
++num_links_;
|
||||
|
||||
return lk;
|
||||
}
|
||||
|
||||
|
|
|
@ -227,11 +227,6 @@ class DenseSet {
|
|||
return entries_.size();
|
||||
}
|
||||
|
||||
// those that are chained to the entries stored inline in the bucket array.
|
||||
size_t NumChainEntries() const {
|
||||
return num_chain_entries_;
|
||||
}
|
||||
|
||||
size_t NumUsedBuckets() const {
|
||||
return num_used_buckets_;
|
||||
}
|
||||
|
@ -241,7 +236,7 @@ class DenseSet {
|
|||
}
|
||||
|
||||
size_t SetMallocUsed() const {
|
||||
return (num_chain_entries_ + entries_.capacity()) * sizeof(DensePtr);
|
||||
return entries_.capacity() * sizeof(DensePtr) + num_links_ * sizeof(DenseLinkKey);
|
||||
}
|
||||
|
||||
using ItemCb = std::function<void(const void*)>;
|
||||
|
@ -344,7 +339,8 @@ class DenseSet {
|
|||
|
||||
// return a ChainVectorIterator (a.k.a iterator) or end if there is an empty chain found
|
||||
ChainVectorIterator FindEmptyAround(uint32_t bid);
|
||||
// return if bucket has no item which is not displaced and right/left bucket has no displaced item
|
||||
|
||||
// Return if bucket has no item which is not displaced and right/left bucket has no displaced item
|
||||
// belong to given bid
|
||||
bool NoItemBelongsBucket(uint32_t bid) const;
|
||||
void Grow(size_t prev_size);
|
||||
|
@ -376,6 +372,7 @@ class DenseSet {
|
|||
inline void FreeLink(DenseLinkKey* plink) {
|
||||
// deallocate the link if it is no longer a link as it is now in an empty list
|
||||
mr()->deallocate(plink, sizeof(DenseLinkKey), alignof(DenseLinkKey));
|
||||
--num_links_;
|
||||
}
|
||||
|
||||
// Returns true if *node was deleted.
|
||||
|
@ -395,9 +392,9 @@ class DenseSet {
|
|||
std::vector<DensePtr, DensePtrAllocator> entries_;
|
||||
|
||||
mutable size_t obj_malloc_used_ = 0;
|
||||
mutable uint32_t size_ = 0;
|
||||
mutable uint32_t num_chain_entries_ = 0;
|
||||
mutable uint32_t num_used_buckets_ = 0;
|
||||
mutable uint32_t size_ = 0; // number of elements in the set.
|
||||
mutable uint32_t num_links_ = 0; // number of links in the set.
|
||||
mutable uint32_t num_used_buckets_ = 0; // number of buckets used in entries_ array.
|
||||
unsigned capacity_log_ = 0;
|
||||
|
||||
uint32_t time_now_ = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue