On Mon, 2020-03-16 at 11:45 -0700, Jeff Davis wrote: > Attached is a patch that makes mem_allocated a method (rather than a > field) of MemoryContext, and allows each memory context type to track > the memory its own way. They all do the same thing as before > (increment/decrement a field), but AllocSet also subtracts out the > free > space in the current block. For Slab and Generation, we could do > something similar, but it's not as much of a problem because there's > no > doubling of the allocation size.
Committed. In an off-list discussion, Andres suggested that MemoryContextStats could be refactored to achieve this purpose, perhaps with flags to avoid walking through the blocks and freelists when those are not needed. We discussed a few other names, such as "space", "active memory", and "touched". We didn't settle on any great name, but "touched" seemed to be the most descriptive. This refactoring/renaming can be done later; right now I committed this to unblock disk-based Hash Aggregation, which is ready. Regards, Jeff Davis