pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Introduce a bump memory allocator
4+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2024-04-09 5a15bdea3b Remove unused BumpBlockIsValid macro
* pgsql: Introduce a bump memory allocator
@ 2024-04-07 12:03 David Rowley <drowley@postgresql.org>
0 siblings, 1 reply; 4+ messages in thread
From: David Rowley @ 2024-04-07 12:03 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
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
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/29f6a959cfd8ffa7d6db2c0629439c5329e2853e
Modified Files
--------------
src/backend/nodes/gen_node_support.pl | 2 +-
src/backend/utils/mmgr/Makefile | 1 +
src/backend/utils/mmgr/bump.c | 811 ++++++++++++++++++++++++++++++++++
src/backend/utils/mmgr/mcxt.c | 15 +-
src/backend/utils/mmgr/meson.build | 1 +
src/include/nodes/memnodes.h | 3 +-
src/include/utils/memutils.h | 7 +
src/include/utils/memutils_internal.h | 18 +-
src/tools/pgindent/typedefs.list | 2 +
9 files changed, 856 insertions(+), 4 deletions(-)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pgsql: Introduce a bump memory allocator
@ 2024-04-09 12:05 Peter Eisentraut <peter@eisentraut.org>
parent: David Rowley <drowley@postgresql.org>
0 siblings, 1 reply; 4+ messages in thread
From: Peter Eisentraut @ 2024-04-09 12:05 UTC (permalink / raw)
To: David Rowley <drowley@postgresql.org>; pgsql-committers@lists.postgresql.org
On 07.04.24 14:03, David Rowley wrote:
> Introduce a bump memory allocator
This patch introduces in bump.c the macro BumpBlockIsValid(), but it's
not used anywhere. Can we remove it?
(If we don't remove it, I suggest to make it an inline function, so it's
easier to tell what it's supposed to be called with. Especially with
the BumpIsValid() nearby, it can be a bit confusing.)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pgsql: Introduce a bump memory allocator
@ 2024-04-09 23:11 David Rowley <dgrowleyml@gmail.com>
parent: Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 4+ messages in thread
From: David Rowley @ 2024-04-09 23:11 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: David Rowley <drowley@postgresql.org>; pgsql-committers@lists.postgresql.org
On Wed, 10 Apr 2024 at 00:05, Peter Eisentraut <peter@eisentraut.org> wrote:
> This patch introduces in bump.c the macro BumpBlockIsValid(), but it's
> not used anywhere. Can we remove it?
I've just pushed a patch to remove it.
Was that spotted by eagle eyes or tooling?
David
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pgsql: Introduce a bump memory allocator
@ 2024-04-10 07:35 Peter Eisentraut <peter@eisentraut.org>
parent: David Rowley <dgrowleyml@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Peter Eisentraut @ 2024-04-10 07:35 UTC (permalink / raw)
To: David Rowley <dgrowleyml@gmail.com>; +Cc: pgsql-committers@lists.postgresql.org
On 10.04.24 01:11, David Rowley wrote:
> On Wed, 10 Apr 2024 at 00:05, Peter Eisentraut <peter@eisentraut.org> wrote:
>> This patch introduces in bump.c the macro BumpBlockIsValid(), but it's
>> not used anywhere. Can we remove it?
>
> I've just pushed a patch to remove it.
>
> Was that spotted by eagle eyes or tooling?
I used gcc -Wunused-macros. This is somewhat noisy, but occasionally
useful to find leftover stuff.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2024-04-10 07:35 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-04-07 12:03 pgsql: Introduce a bump memory allocator David Rowley <drowley@postgresql.org>
2024-04-09 12:05 ` Peter Eisentraut <peter@eisentraut.org>
2024-04-09 23:11 ` David Rowley <dgrowleyml@gmail.com>
2024-04-10 07:35 ` Peter Eisentraut <peter@eisentraut.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox