All in a context!
summary
PostgreSQL routes every malloc into hierarchical memory contexts so code never calls free directly, using allocation sets of 8 KB that double on growth and a free list reuse to avoid repeated creation. Contexts expose APIs like memory_context_create/reset/delete, memory_context_switch and alloc/alloc_zero/alloc_extended, callbacks that run on reset in reverse child→parent order, and PG backend memory_context view plus enable C_ASSERT and memory_context_stats for debugging. Setting a context parent extends its lifetime.
AI-written summary · about
chapters (20)
- 0:00Introduction and setup
- 1:49Why memory context exists
- 3:36Memory context structure
- 6:03Memory context methods
- 7:27Free list mechanism
- 8:54Memory context callbacks
- 9:56Basic operations in context
- 10:39Context organization in Postgres
- 11:44Key memory contexts
- 13:31Other specialized contexts
- 14:55Current context and allocation
- 16:00Creating a memory context
- 17:03Deleting and resetting contexts
- 18:29Switching and allocating in context
- 19:11Inquiry and debugging functions
- 20:18Viewing memory context stats
- 21:24Detecting memory leaks
- 24:35Advantages of memory context
- 26:45Summary and conclusion
- 27:08Q&A session
related talks
32mDesigning and implementing a monitoring feature in PostgreSQL
25mDesigning a monitoring feature in PostgreSQL
45mEnhancing PostgreSQL Plasticity: New Frontiers in Memory Management
50mInside PostgreSQL Shared Memory
50mHacking on Postgres: An Overview
52mMulti-threaded PostgreSQL?
26mLinux and PostgreSQL in the Multiverse of Connections
30mPostgreSQL and Linux Kernel interactions
