From: | Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Redefine backend ID to be an index into the proc array |
Date: | 2024-03-03 17:39:48 |
Message-ID: | E1rgpoS-001uTN-2k@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Redefine backend ID to be an index into the proc array
Previously, backend ID was an index into the ProcState array, in the
shared cache invalidation manager (sinvaladt.c). The entry in the
ProcState array was reserved at backend startup by scanning the array
for a free entry, and that was also when the backend got its backend
ID. Things become slightly simpler if we redefine backend ID to be the
index into the PGPROC array, and directly use it also as an index to
the ProcState array. This uses a little more memory, as we reserve a
few extra slots in the ProcState array for aux processes that don't
need them, but the simplicity is worth it.
Aux processes now also have a backend ID. This simplifies the
reservation of BackendStatusArray and ProcSignal slots.
You can now convert a backend ID into an index into the PGPROC array
simply by subtracting 1. We still use 0-based "pgprocnos" in various
places, for indexes into the PGPROC array, but the only difference now
is that backend IDs start at 1 while pgprocnos start at 0. (The next
commmit will get rid of the term "backend ID" altogether and make
everything 0-based.)
There is still a 'backendId' field in PGPROC, now part of 'vxid' which
encapsulates the backend ID and local transaction ID together. It's
needed for prepared xacts. For regular backends, the backendId is
always equal to pgprocno + 1, but for prepared xact PGPROC entries,
it's the ID of the original backend that processed the transaction.
Reviewed-by: Andres Freund, Reid Thompson
Discussion: https://www.postgresql.org/message-id/8171f1aa-496f-46a6-afc3-c46fe7a9b407@iki.fi
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ab355e3a88de745607f6dd4c21f0119b5c68f2ad
Modified Files
--------------
src/backend/access/transam/twophase.c | 37 ++---
src/backend/access/transam/xact.c | 12 +-
src/backend/catalog/namespace.c | 2 +-
src/backend/commands/sequence.c | 2 +-
src/backend/executor/functions.c | 4 +-
src/backend/postmaster/auxprocess.c | 12 +-
src/backend/storage/ipc/procarray.c | 73 +++++++++-
src/backend/storage/ipc/procsignal.c | 27 ++--
src/backend/storage/ipc/sinvaladt.c | 200 +++++++++-------------------
src/backend/storage/ipc/standby.c | 1 +
src/backend/storage/lmgr/lock.c | 28 ++--
src/backend/storage/lmgr/proc.c | 32 +++--
src/backend/utils/activity/backend_status.c | 52 +++-----
src/backend/utils/adt/lockfuncs.c | 2 +-
src/backend/utils/adt/mcxtfuncs.c | 14 +-
src/backend/utils/error/csvlog.c | 4 +-
src/backend/utils/error/elog.c | 6 +-
src/backend/utils/error/jsonlog.c | 6 +-
src/backend/utils/init/postinit.c | 10 +-
src/backend/utils/time/snapmgr.c | 5 +-
src/include/miscadmin.h | 2 -
src/include/storage/backendid.h | 12 +-
src/include/storage/lock.h | 9 +-
src/include/storage/proc.h | 32 ++++-
src/include/storage/procarray.h | 4 +
src/include/storage/procsignal.h | 2 +-
src/include/storage/sinvaladt.h | 4 -
src/pl/plpgsql/src/pl_exec.c | 10 +-
28 files changed, 282 insertions(+), 322 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2024-03-03 21:14:49 | Re: pgsql: Improve performance of subsystems on top of SLRU |
Previous Message | Alvaro Herrera | 2024-03-03 14:29:22 | Re: pgsql: Improve performance of subsystems on top of SLRU |