Make MemoryContextMemAllocated() more precise
От | Jeff Davis |
---|---|
Тема | Make MemoryContextMemAllocated() more precise |
Дата | |
Msg-id | ec63d70b668818255486a83ffadc3aec492c1f57.camel@j-davis.com обсуждение исходный текст |
Ответы |
Re: Make MemoryContextMemAllocated() more precise
Re: Make MemoryContextMemAllocated() more precise Re: Make MemoryContextMemAllocated() more precise Re: Make MemoryContextMemAllocated() more precise |
Список | pgsql-hackers |
AllocSet allocates memory for itself in blocks, which double in size up to maxBlockSize. So, the current block (the last one malloc'd) may represent half of the total memory allocated for the context itself. The free space at the end of that block hasn't been touched at all, and doesn't represent fragmentation or overhead. That means that the "allocated" memory can be 2X the memory ever touched in the worst case. Although that's technically correct, the purpose of MemoryContextMemAllocated() is to give a "real" usage number so we know when we're out of work_mem and need to spill (in particular, the disk- based HashAgg work, but ideally other operators as well). This "real" number should include fragmentation, freed-and-not-reused chunks, and other overhead. But it should not include significant amounts of allocated-but-never-touched memory, which says more about economizing calls to malloc than it does about the algorithm's memory usage. 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. Although I think this still matches the word "allocation" in spirit, it's not technically correct, so feel free to suggest a new name for MemoryContextMemAllocated(). Regards, Jeff Davis
Вложения
В списке pgsql-hackers по дате отправления: