Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit58b25e9

Browse files
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.com
1 parentbfd12cc commit58b25e9

File tree

6 files changed

+805
-2
lines changed

6 files changed

+805
-2
lines changed

‎src/backend/utils/mmgr/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ subdir = src/backend/utils/mmgr
1212
top_builddir = ../../../..
1313
include$(top_builddir)/src/Makefile.global
1414

15-
OBJS = aset.o dsa.o freepage.o mcxt.o memdebug.o portalmem.o
15+
OBJS = aset.o dsa.o freepage.o mcxt.o memdebug.o portalmem.o slab.o
1616

1717
include$(top_srcdir)/src/backend/common.mk

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp