Well, in case we would allocate from one thread only and deallocate
from another thread we would need to check if
unsigned long __remove = __bin._M_free[__thread_id];
__remove *= __options._M_freelist_headroom;
if (__remove >= __bin._M_used[__thread_id])
__remove -= __bin._M_used[__thread_id];
else
__remove = 0;
__bin._M_free[__thread_id] * __options._M_freelist_headroom can
ever become bigger than __bin._M_used[__thread_id]. From looking at
the code it seems that __options._M_freelist_headroom is [0, 100],
still if __bin._M_used[__thread_id] would be never shrinking but only
growing we at some point would stop moving freed blocks back to the
global pool.
Of course if we continue to allocate from the local pool always this
doesn't matter. But surely one can construct some artificial testcase
that would produce very unbalanced local free lists and require more
than usual total memory?