@@ -196,6 +196,12 @@ class ISLEntry {
196
196
return (uptr () & kTtlBit ) != 0 ;
197
197
}
198
198
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
+
199
205
[[nodiscard]] bool UpdateTtl (uint32_t ttl_sec) {
200
206
if (HasTtl ()) {
201
207
auto * ttl_pos = Raw () + sizeof (char *);
@@ -260,22 +266,25 @@ class IntrusiveStringList {
260
266
return prev_.Next ().ExpiryTime ();
261
267
}
262
268
263
- void SetExpiryTime (uint32_t ttl_sec) {
269
+ void SetExpiryTime (uint32_t ttl_sec, size_t * obj_malloc_used ) {
264
270
auto entry = prev_.Next ();
265
271
266
272
if (!entry.UpdateTtl (ttl_sec)) {
267
273
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 ();
268
276
ISLEntry::Destroy (entry);
269
277
prev_.SetNext (new_entry);
270
278
}
271
279
}
272
280
273
- bool ExpireIfNeeded (uint32_t time_now) {
281
+ bool ExpireIfNeeded (uint32_t time_now, size_t * obj_malloc_used ) {
274
282
auto entry = prev_.Next ();
275
283
276
284
if (auto entry_time = entry.ExpiryTime ();
277
285
entry_time != UINT32_MAX && time_now >= entry_time) {
278
286
prev_.SetNext (prev_.Next ().Next ());
287
+ (*obj_malloc_used) -= sizeof (entry) + entry.Size ();
279
288
ISLEntry::Destroy (entry);
280
289
return true ;
281
290
}
@@ -340,12 +349,14 @@ class IntrusiveStringList {
340
349
ISLEntry& Insert (ISLEntry e) {
341
350
e.SetNext (start_);
342
351
start_ = e;
352
+ obj_malloc_used_ += sizeof (e) + e.Size ();
343
353
return start_;
344
354
}
345
355
346
356
UniqueISLEntry Pop (uint32_t curr_time) {
347
357
for (auto it = start_; it && it.ExpiryTime () < curr_time; it = start_) {
348
358
start_ = it.Next ();
359
+ obj_malloc_used_ -= sizeof (it) + it.Size ();
349
360
ISLEntry::Destroy (it);
350
361
}
351
362
auto res = start_;
@@ -371,7 +382,7 @@ class IntrusiveStringList {
371
382
auto it = begin ();
372
383
373
384
for (; it; ++it) {
374
- if (it.ExpireIfNeeded (time_now)) {
385
+ if (it.ExpireIfNeeded (time_now, &obj_malloc_used_ )) {
375
386
(*expired_fields)++;
376
387
continue ;
377
388
}
@@ -388,7 +399,7 @@ class IntrusiveStringList {
388
399
uint32_t * expired_fields, uint32_t time_now = UINT32_MAX) {
389
400
auto entry = begin ();
390
401
for (; entry; ++entry) {
391
- if (entry.ExpireIfNeeded (time_now)) {
402
+ if (entry.ExpireIfNeeded (time_now, &obj_malloc_used_ )) {
392
403
(*expired_fields)++;
393
404
continue ;
394
405
}
@@ -446,7 +457,12 @@ class IntrusiveStringList {
446
457
return start_;
447
458
}
448
459
460
+ size_t ObjMallocUsed () const {
461
+ return obj_malloc_used_;
462
+ };
463
+
449
464
private:
465
+ size_t obj_malloc_used_;
450
466
ISLEntry start_;
451
467
static ISLEntry end_;
452
468
};
0 commit comments