From 5047e64dee7c80d90a1a6edeb77882e5cb8071a6 Mon Sep 17 00:00:00 2001 From: John Sully Date: Mon, 12 Sep 2022 15:05:09 +0000 Subject: [PATCH] Fix O(n) algorithm in INFO command --- src/object.cpp | 5 ++--- src/semiorderedset.h | 12 +++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/object.cpp b/src/object.cpp index 44dcbd6e9..4f6a56338 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -1140,10 +1140,9 @@ struct redisMemOverhead *getMemoryOverheadData(void) { db->size() * sizeof(robj); mh->db[mh->num_dbs].overhead_ht_main = mem; mem_total+=mem; - + std::unique_lock ul(g_expireLock); - mem = db->setexpire()->bytes_used(); - + mem = db->setexpire()->estimated_bytes_used(); mh->db[mh->num_dbs].overhead_ht_expires = mem; mem_total+=mem; diff --git a/src/semiorderedset.h b/src/semiorderedset.h index fe463fe31..c9ff10bac 100644 --- a/src/semiorderedset.h +++ b/src/semiorderedset.h @@ -240,14 +240,12 @@ public: bool empty() const noexcept { return celem == 0; } size_t size() const noexcept { return celem; } - size_t bytes_used() const + size_t estimated_bytes_used() const { - size_t cb = sizeof(this) + (m_data.capacity()-m_data.size())*sizeof(T); - for (auto &vec : m_data) - { - if (vec != nullptr) - cb += vec->bytes_used(); - } + // This estimate does't include all the overhead of the internal vectors + size_t cb = sizeof(this) + + (m_data.capacity() * sizeof(m_data[0])) + + sizeof(T) * size(); return cb; }