@@ -196,6 +196,12 @@ class ISLEntry {
196196 return (uptr () & kTtlBit ) != 0 ;
197197 }
198198
199+ size_t Size () {
200+ size_t key_field_size = HasSso () ? 1 : 4 ;
201+ size_t ttl_field_size = HasTtl () ? 4 : 0 ;
202+ return (sizeof (char *) + ttl_field_size + key_field_size + GetKeySize ());
203+ }
204+
199205 [[nodiscard]] bool UpdateTtl (uint32_t ttl_sec) {
200206 if (HasTtl ()) {
201207 auto * ttl_pos = Raw () + sizeof (char *);
@@ -260,22 +266,25 @@ class IntrusiveStringList {
260266 return prev_.Next ().ExpiryTime ();
261267 }
262268
263- void SetExpiryTime (uint32_t ttl_sec) {
269+ void SetExpiryTime (uint32_t ttl_sec, size_t * obj_malloc_used ) {
264270 auto entry = prev_.Next ();
265271
266272 if (!entry.UpdateTtl (ttl_sec)) {
267273 ISLEntry new_entry = ISLEntry::Create (entry.Key (), entry.Next ().data_ , ttl_sec);
274+ (*obj_malloc_used) += sizeof (new_entry) + new_entry.Size ();
275+ (*obj_malloc_used) -= sizeof (entry) + entry.Size ();
268276 ISLEntry::Destroy (entry);
269277 prev_.SetNext (new_entry);
270278 }
271279 }
272280
273- bool ExpireIfNeeded (uint32_t time_now) {
281+ bool ExpireIfNeeded (uint32_t time_now, size_t * obj_malloc_used ) {
274282 auto entry = prev_.Next ();
275283
276284 if (auto entry_time = entry.ExpiryTime ();
277285 entry_time != UINT32_MAX && time_now >= entry_time) {
278286 prev_.SetNext (prev_.Next ().Next ());
287+ (*obj_malloc_used) -= sizeof (entry) + entry.Size ();
279288 ISLEntry::Destroy (entry);
280289 return true ;
281290 }
@@ -340,12 +349,14 @@ class IntrusiveStringList {
340349 ISLEntry& Insert (ISLEntry e) {
341350 e.SetNext (start_);
342351 start_ = e;
352+ obj_malloc_used_ += sizeof (e) + e.Size ();
343353 return start_;
344354 }
345355
346356 UniqueISLEntry Pop (uint32_t curr_time) {
347357 for (auto it = start_; it && it.ExpiryTime () < curr_time; it = start_) {
348358 start_ = it.Next ();
359+ obj_malloc_used_ -= sizeof (it) + it.Size ();
349360 ISLEntry::Destroy (it);
350361 }
351362 auto res = start_;
@@ -371,7 +382,7 @@ class IntrusiveStringList {
371382 auto it = begin ();
372383
373384 for (; it; ++it) {
374- if (it.ExpireIfNeeded (time_now)) {
385+ if (it.ExpireIfNeeded (time_now, &obj_malloc_used_ )) {
375386 (*expired_fields)++;
376387 continue ;
377388 }
@@ -388,7 +399,7 @@ class IntrusiveStringList {
388399 uint32_t * expired_fields, uint32_t time_now = UINT32_MAX) {
389400 auto entry = begin ();
390401 for (; entry; ++entry) {
391- if (entry.ExpireIfNeeded (time_now)) {
402+ if (entry.ExpireIfNeeded (time_now, &obj_malloc_used_ )) {
392403 (*expired_fields)++;
393404 continue ;
394405 }
@@ -446,7 +457,12 @@ class IntrusiveStringList {
446457 return start_;
447458 }
448459
460+ size_t ObjMallocUsed () const {
461+ return obj_malloc_used_;
462+ };
463+
449464 private:
465+ size_t obj_malloc_used_;
450466 ISLEntry start_;
451467 static ISLEntry end_;
452468};
0 commit comments