- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit29f6a95
committed
Introduce a bump memory allocator
This introduces a bump MemoryContext type. The bump context is bestsuited for short-lived memory contexts which require only allocationsof memory and never a pfree or repalloc, which are unsupported.Memory palloc'd into a bump context has no chunk header. This makesbump a useful context type when lots of small allocations need to bedone without any need to pfree those allocations. Allocation sizes arerounded up to the next MAXALIGN boundary, so with this and no chunkheader, allocations are very compact indeed.Allocations are also very fast as bump does not check any freelists totry and make use of previously free'd chunks. It just checks if thereis enough room on the current block, and if so it bumps the freeptrbeyond this chunk and returns the value that the freeptr was previouslypointing to. Simple and fast. A new block is malloc'd when there's notenough space in the current block.Code using the bump allocator must take care never to call any functionswhich could try to call realloc() (or variants), pfree(),GetMemoryChunkContext() or GetMemoryChunkSpace() on a bump allocatedchunk. Due to lack of chunk headers, these operations are unsupported.To increase the chances of catching such issues, when compiled withMEMORY_CONTEXT_CHECKING, bump allocated chunks are given a header andany attempt to perform an unsupported operation will result in an ERROR.Without MEMORY_CONTEXT_CHECKING, code attempting an unsupportedoperation could result in a segfault.A follow-on commit will implement the first user of bump.Author: David RowleyReviewed-by: Nathan BossartReviewed-by: Matthias van de MeentReviewed-by: Tomas VondraReviewed-by: John NaylorDiscussion:https://postgr.es/m/CAApHDvqGSpCU95TmM=Bp=6xjL_nLys4zdZOpfNyWBk97Xrdj2w@mail.gmail.com1 parent0ba8b75 commit29f6a95
File tree
9 files changed
+856
-4
lines changed- src
- backend
- nodes
- utils/mmgr
- include
- nodes
- utils
- tools/pgindent
9 files changed
+856
-4
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
149 | 149 |
| |
150 | 150 |
| |
151 | 151 |
| |
152 |
| - | |
| 152 | + | |
153 | 153 |
| |
154 | 154 |
| |
155 | 155 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
15 | 15 |
| |
16 | 16 |
| |
17 | 17 |
| |
| 18 | + | |
18 | 19 |
| |
19 | 20 |
| |
20 | 21 |
| |
|
0 commit comments
Comments
(0)