@@ -227,27 +227,43 @@ template <typename WrappedAllocator> class MeteredAllocator : public WrappedAllo
227227 void *
228228 alloc_void ()
229229 {
230- inuse_metric->increment (1 );
231- alloc_metric->increment (1 );
230+ increment_for_alloc ();
232231 return WrappedAllocator::alloc_void ();
233232 }
234233
235234 void
236235 free_void (void *ptr)
237236 {
238- inuse_metric->decrement (1 );
239- free_metric->increment (1 );
237+ increment_for_free ();
240238 WrappedAllocator::free_void (ptr);
241239 }
242240
243241 void
244242 free_void_bulk (void *head, void *tail, size_t num_item)
245243 {
246- inuse_metric->decrement (num_item);
247- free_metric->increment (num_item);
244+ // this is only currently called from ProxyAllocator to free
245+ // back to the watermark, so if this is called, it means
246+ // the ProxyAllocator free has been decrementing the free count
247+ // for items on its freelist so this function should not update metrics
248248 WrappedAllocator::free_void_bulk (head, tail, num_item);
249249 }
250250
251+ // NOTE(cmcfarlen): These metric functions are also called
252+ // by ProxyAllocator when items are added/removed from its freelist
253+ void
254+ increment_for_alloc ()
255+ {
256+ inuse_metric->increment (1 );
257+ alloc_metric->increment (1 );
258+ }
259+
260+ void
261+ increment_for_free (int val = 1 )
262+ {
263+ inuse_metric->decrement (val);
264+ free_metric->increment (val);
265+ }
266+
251267 MeteredAllocator () {}
252268
253269 MeteredAllocator (const char *name, unsigned int element_size, unsigned int chunk_size = 128 , unsigned int alignment = 8 ,
0 commit comments