PostgreSQL makes heavy use of memory pools and, when Valgrind is turned on, provides information about them to Valgrind with VALGRIND_CREATE_MEMPOOL, etc.
Combined with incremental leak checking using client requests such as VALGRIND_DO_LEAK_CHECKand VALGRIND_DO_ADDED_LEAK_CHECK, this is really useful for tracking memory usage in a large, complex, and long-lived program.
But: PostgreSQL has many caches whose lifetimes tend to span typical boundaries, such as transactions. As a rule, a memory leak usually occurs in such caches (for various reasons), but it is not always easy to determine whether such memory is allocated in the cache context using only the stack.
So, I'm looking for a way to show the names of memory pools in leak reports and filter them during suppressions. Ideally something like
{
my_suppression_name
Memcheck:Leak
match-leak-kinds: reachable
pool:CacheMemoryContext # <---- something like this
fun:malloc
fun:AllocSetAlloc
fun:palloc
fun:initStringInfo
fun:apply_work
...
}
or in leak reports, for example:
... 6 (+6) bytes in 1 (+1) blocks are possibly lost in loss record 180 of 942
... in mempool "CacheMemoryContext" <---- Like this
... at 0x815FFC: MemoryContextAlloc (mcxt.c:771)
... by 0x817680: MemoryContextStrdup (mcxt.c:1157)
I suspect the answer is no, as the interface for registering memgrs Valgrind does not seem to refer to names. PostgreSQL stores have names built into their header blocks, so you just need to train Valgrind what byte range the pool name was.
Am I missing something or is it simply impossible now?
Software callbacks can be a viable alternative to filter leak check reports or add annotation information to them. But again, I see nothing in Valgrind, which suggests that this is possible.
It seems that others would like something, so maybe I just donβt see a way to do this.
: , - , PostgreSQL TopMemoryContext. , , .