postgresql/src/backend
David Rowley 29f6a959cf Introduce a bump memory allocator
This introduces a bump MemoryContext type.  The bump context is best
suited for short-lived memory contexts which require only allocations
of memory and never a pfree or repalloc, which are unsupported.

Memory palloc'd into a bump context has no chunk header.  This makes
bump a useful context type when lots of small allocations need to be
done without any need to pfree those allocations.  Allocation sizes are
rounded up to the next MAXALIGN boundary, so with this and no chunk
header, allocations are very compact indeed.

Allocations are also very fast as bump does not check any freelists to
try and make use of previously free'd chunks.  It just checks if there
is enough room on the current block, and if so it bumps the freeptr
beyond this chunk and returns the value that the freeptr was previously
pointing to.  Simple and fast.  A new block is malloc'd when there's not
enough space in the current block.

Code using the bump allocator must take care never to call any functions
which could try to call realloc() (or variants), pfree(),
GetMemoryChunkContext() or GetMemoryChunkSpace() on a bump allocated
chunk.  Due to lack of chunk headers, these operations are unsupported.
To increase the chances of catching such issues, when compiled with
MEMORY_CONTEXT_CHECKING, bump allocated chunks are given a header and
any attempt to perform an unsupported operation will result in an ERROR.
Without MEMORY_CONTEXT_CHECKING, code attempting an unsupported
operation could result in a segfault.

A follow-on commit will implement the first user of bump.

Author: David Rowley
Reviewed-by: Nathan Bossart
Reviewed-by: Matthias van de Meent
Reviewed-by: Tomas Vondra
Reviewed-by: John Naylor
Discussion: https://postgr.es/m/CAApHDvqGSpCU95TmM=Bp=6xjL_nLys4zdZOpfNyWBk97Xrdj2w@mail.gmail.com
2024-04-08 00:02:43 +12:00
..
access Reduce branches in heapgetpage()'s per-tuple loop 2024-04-06 23:52:26 -07:00
archive Add built-in ERROR handling for archive callbacks. 2024-04-02 22:28:11 -05:00
backup Align blocks in incremental backups to BLCKSZ 2024-04-05 16:30:01 +02:00
bootstrap Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
catalog CREATE INDEX: do not update stats during binary upgrade. 2024-04-03 16:12:45 -07:00
commands Implement ALTER TABLE ... SPLIT PARTITION ... command 2024-04-07 01:18:44 +03:00
executor Change BitmapAdjustPrefetchIterator to accept BlockNumber 2024-04-07 01:25:15 +02:00
foreign Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
jit Add SQL/JSON query functions 2024-03-21 17:07:03 +09:00
lib Use the pairing heap instead of a flat array for LSN replay waiters 2024-04-03 18:15:41 +03:00
libpq Avoid needless large memcpys in libpq socket writing 2024-04-07 21:20:18 +12:00
main Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
nodes Introduce a bump memory allocator 2024-04-08 00:02:43 +12:00
optimizer Enhance nbtree ScalarArrayOp execution. 2024-04-06 11:47:10 -04:00
parser Implement ALTER TABLE ... SPLIT PARTITION ... command 2024-04-07 01:18:44 +03:00
partitioning Implement ALTER TABLE ... SPLIT PARTITION ... command 2024-04-07 01:18:44 +03:00
po Update copyright for 2024 2024-01-03 20:49:05 -05:00
port Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
postmaster Add built-in ERROR handling for archive callbacks. 2024-04-02 22:28:11 -05:00
regex Support C.UTF-8 locale in the new builtin collation provider. 2024-03-19 15:24:41 -07:00
replication Support retrieval of results in chunks with libpq. 2024-04-06 20:45:11 -04:00
rewrite Add RETURNING support to MERGE. 2024-03-17 13:58:59 +00:00
snowball Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
statistics Make stxstattarget nullable 2024-03-17 12:26:26 +01:00
storage Fix if/while thinko in read_stream.c edge case. 2024-04-07 14:51:33 +12:00
tcop Invent SERIALIZE option for EXPLAIN. 2024-04-03 17:41:57 -04:00
tsearch Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
utils Introduce a bump memory allocator 2024-04-08 00:02:43 +12:00
.gitignore
Makefile Rework lwlocknames.txt to become lwlocklist.h 2024-03-20 11:55:20 +01:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build Remove AIX support 2024-02-28 15:17:23 +04:00
nls.mk Remove distprep 2023-11-06 15:18:04 +01:00