diff options
author | Tomas Vondra <tomas.vondra@postgresql.org> | 2019-10-01 03:13:39 +0200 |
---|---|---|
committer | Tomas Vondra <tomas.vondra@postgresql.org> | 2019-10-01 03:13:39 +0200 |
commit | 5dd7fc1519461548eebf26c33eac6878ea3e8788 (patch) | |
tree | b2905a092eeee47d09a7d5c17dbaeb290b633d0b /src/include/utils/memutils.h | |
parent | 36d22dd95bc87ca68e742da91f47f8826f8758c9 (diff) | |
download | postgresql-5dd7fc1519461548eebf26c33eac6878ea3e8788.tar.gz postgresql-5dd7fc1519461548eebf26c33eac6878ea3e8788.zip |
Add transparent block-level memory accounting
Adds accounting of memory allocated in a memory context. Compared to
various ad hoc solutions, the main advantage is that the accounting is
transparent and does not require direct control over allocations (this
matters for use cases where the allocations happen in user code, like
for example aggregate states allocated in a transition functions).
To reduce overhead, the accounting happens at the block level (not for
individual chunks) and only the context immediately owning the block is
updated. When inquiring about amount of memory allocated in a context,
we have to recursively walk all children contexts.
This "lazy" accounting works well for cases with relatively small number
of contexts in the relevant subtree and/or with infrequent inquiries.
Author: Jeff Davis
Reivewed-by: Tomas Vondra, Melanie Plageman, Soumyadeep Chakraborty
Discussion: https://www.postgresql.org/message-id/flat/027a129b8525601c6a680d27ce3a7172dab61aab.camel@j-davis.com
Diffstat (limited to 'src/include/utils/memutils.h')
-rw-r--r-- | src/include/utils/memutils.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h index ffe6de536e2..6a837bc9902 100644 --- a/src/include/utils/memutils.h +++ b/src/include/utils/memutils.h @@ -82,6 +82,7 @@ extern void MemoryContextSetParent(MemoryContext context, extern Size GetMemoryChunkSpace(void *pointer); extern MemoryContext MemoryContextGetParent(MemoryContext context); extern bool MemoryContextIsEmpty(MemoryContext context); +extern int64 MemoryContextMemAllocated(MemoryContext context, bool recurse); extern void MemoryContextStats(MemoryContext context); extern void MemoryContextStatsDetail(MemoryContext context, int max_children); extern void MemoryContextAllowInCriticalSection(MemoryContext context, |