forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit58b25e9
committed
Add "Slab" MemoryContext implementation for efficient equal-sized allocations.
The default general purpose aset.c style memory context is not a greatchoice for allocations that are all going to be evenly sized,especially when those objects aren't small, and have varyinglifetimes. There tends to be a lot of fragmentation, largerallocations always directly go to libc rather than have their costamortized over several pallocs.These problems lead to the introduction of ad-hoc slab allocators inreorderbuffer.c. But it turns out that the simplistic implementationleads to problems when a lot of objects are allocated and freed, asaset.c is still the underlying implementation. Especially freeing caneasily run into O(n^2) behavior in aset.c.While the O(n^2) behavior in aset.c can, and probably will, beaddressed, custom allocators for this behavior are more efficientboth in space and time.This allocator is for evenly sized allocations, and supports bothcheap allocations and freeing, without fragmenting significantly. Itdoes so by allocating evenly sized blocks via malloc(), and carvesthem into chunks that can be used for allocations. In order torelease blocks to the OS as early as possible, chunks are allocatedfrom the fullest block that still has free objects, increasing thelikelihood of a block being entirely unused.A subsequent commit uses this in reorderbuffer.c, but a furtherallocator is needed to resolve the performance problems triggeringthis work.There likely are further potentialy uses of this allocator besidesreorderbuffer.c.There's potential further optimizations of the new slab.c, inparticular the array of freelists could be replaced by a moreintelligent structure - but for now this looks more than good enough.Author: Tomas Vondra, editorialized by Andres FreundReviewed-By: Andres Freund, Petr Jelinek, Robert Haas, Jim NasbyDiscussion:https://postgr.es/m/d15dff83-0b37-28ed-0809-95a5cc7292ad@2ndquadrant.com1 parentbfd12cc commit58b25e9
File tree
6 files changed
+805
-2
lines changed- src
- backend/utils/mmgr
- include
- nodes
- utils
- tools/pgindent
6 files changed
+805
-2
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
12 | 12 |
| |
13 | 13 |
| |
14 | 14 |
| |
15 |
| - | |
| 15 | + | |
16 | 16 |
| |
17 | 17 |
|
0 commit comments
Comments
(0)