1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

refactor: Move BackendWritebackContext initialization

BackendWritebackContext is a purely per-process thing, so it feels
wrong to initialize it in the shmem init/attach functions.  Move the
initialization to InitBufferManagerAccess() instead.

Backpatch to version 19, where the new shared memory callbacks system
was introduced.  While this isn't new with that, it made the ShmemInit
functions more closely related to shared memory initialization than
before.

Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/fb1bd612-4a58-4235-976f-2b2ef036bfff@iki.fi
Backpatch-through: 19
This commit is contained in:
Heikki Linnakangas
2026-10-10 01:01:02 +03:00
parent 270caee04f
commit 1feb619383
3 changed files with 6 additions and 16 deletions

View File

@@ -24,17 +24,14 @@
BufferDescPadded *BufferDescriptors;
char *BufferBlocks;
ConditionVariableMinimallyPadded *BufferIOCVArray;
WritebackContext BackendWritebackContext;
CkptSortItem *CkptBufferIds;
static void BufferManagerShmemRequest(void *arg);
static void BufferManagerShmemInit(void *arg);
static void BufferManagerShmemAttach(void *arg);
const ShmemCallbacks BufferManagerShmemCallbacks = {
.request_fn = BufferManagerShmemRequest,
.init_fn = BufferManagerShmemInit,
.attach_fn = BufferManagerShmemAttach,
};
/*
@@ -138,16 +135,4 @@ BufferManagerShmemInit(void *arg)
proclist_init(&buf->lock_waiters);
ConditionVariableInit(BufferDescriptorGetIOCV(buf));
}
/* Initialize per-backend file flush context */
WritebackContextInit(&BackendWritebackContext,
&backend_flush_after);
}
static void
BufferManagerShmemAttach(void *arg)
{
/* Initialize per-backend file flush context */
WritebackContextInit(&BackendWritebackContext,
&backend_flush_after);
}

View File

@@ -270,6 +270,8 @@ static int PrivateRefCountEntryLast = -1;
static uint32 MaxProportionalPins;
static WritebackContext BackendWritebackContext;
static void ReservePrivateRefCountEntry(void);
static PrivateRefCountEntry *NewPrivateRefCountEntry(Buffer buffer);
static PrivateRefCountEntry *GetPrivateRefCountEntry(Buffer buffer, bool do_move);
@@ -4252,6 +4254,10 @@ InitBufferManagerAccess(void)
PrivateRefCountHash = refcount_create(CurrentMemoryContext, 100, NULL);
/* Initialize per-backend file flush context */
WritebackContextInit(&BackendWritebackContext,
&backend_flush_after);
/*
* AtProcExit_Buffers needs LWLock access, and thereby has to be called at
* the corresponding phase of backend shutdown.

View File

@@ -412,7 +412,6 @@ typedef struct WritebackContext
/* in buf_init.c */
extern PGDLLIMPORT BufferDescPadded *BufferDescriptors;
extern PGDLLIMPORT ConditionVariableMinimallyPadded *BufferIOCVArray;
extern PGDLLIMPORT WritebackContext BackendWritebackContext;
/* in localbuf.c */
extern PGDLLIMPORT BufferDesc *LocalBufferDescriptors;