postgresql/src/backend/utils
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
..
activity Use an LWLock instead of a spinlock in waitlsn.c 2024-04-07 00:49:53 +03:00
adt Implement ALTER TABLE ... SPLIT PARTITION ... command 2024-04-07 01:18:44 +03:00
cache Add error codes to some PANIC/FATAL errors reports 2024-04-03 09:19:25 +02:00
error Coordinate emit_log_hook and all log destinations to share the same timeval 2024-04-04 14:15:22 +09:00
fmgr Refactor code checking for file existence 2024-01-12 12:04:51 +09:00
hash Mark hash_corrupted() as pg_attribute_noreturn. 2024-03-17 17:54:45 -04:00
init Increase default vacuum_buffer_usage_limit to 2MB. 2024-04-06 23:12:03 +13:00
mb Make the order of the header file includes consistent 2024-03-13 15:07:00 +01:00
misc Increase default vacuum_buffer_usage_limit to 2MB. 2024-04-06 23:12:03 +13:00
mmgr Introduce a bump memory allocator 2024-04-08 00:02:43 +12:00
resowner Use new overflow-safe integer comparison functions. 2024-02-16 14:05:36 -06:00
sort Clarify comment for LogicalTapeSetBlocks(). 2024-03-25 11:51:44 -07:00
time Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
.gitignore Rearrange makefile rules for running Gen_fmgrtab.pl. 2018-05-03 17:54:18 -04:00
Gen_dummy_probes.pl Update copyright for 2024 2024-01-03 20:49:05 -05:00
Gen_fmgrtab.pl Update copyright for 2024 2024-01-03 20:49:05 -05:00
Makefile Update copyright for 2024 2024-01-03 20:49:05 -05:00
errcodes.txt Introduce transaction_timeout 2024-02-15 23:56:12 +02:00
generate-errcodes.pl Update copyright for 2024 2024-01-03 20:49:05 -05:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
postprocess_dtrace.sed Update copyright for 2024 2024-01-03 20:49:05 -05:00
probes.d Update copyright for 2024 2024-01-03 20:49:05 -05:00