nocfbot.v11-0001-Add-const-qualification-in-SLRU-subsyst.patch
application/octet-stream
Filename: nocfbot.v11-0001-Add-const-qualification-in-SLRU-subsyst.patch
Type: application/octet-stream
Part: 1
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v11-0001
Subject: Add const qualification in SLRU subsystem
| File | + | − |
|---|---|---|
| src/backend/access/transam/slru.c | 41 | 37 |
| src/include/access/slru.h | 20 | 18 |
| src/test/modules/test_slru/test_slru.c | 2 | 1 |
From 53f491e2565f42fc1fcb3612fe821b1c3b796d4b Mon Sep 17 00:00:00 2001
From: Matthias van de Meent <boekewurm+postgres@gmail.com>
Date: Sun, 5 Apr 2026 21:46:31 +0200
Subject: [PATCH vnocfbot.v11 1/2] Add const qualification in SLRU subsystem
With SlruCtl being replaced with SlruDesc*, we can const-qualify the
input arguments of various SLRU functions without significant effort.
In passing, some other arguments are also const-qualified.
---
src/backend/access/transam/slru.c | 78 ++++++++++++++------------
src/include/access/slru.h | 38 +++++++------
src/test/modules/test_slru/test_slru.c | 3 +-
3 files changed, 63 insertions(+), 56 deletions(-)
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 47dd52d6749..a1e688dd702 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -91,7 +91,7 @@
* dir/123456 for [2^20, 2^24-1]
*/
static inline int
-SlruFileName(SlruDesc *ctl, char *path, int64 segno)
+SlruFileName(const SlruDesc *ctl, char *path, int64 segno)
{
if (ctl->options.long_segment_names)
{
@@ -178,19 +178,22 @@ static SlruErrorCause slru_errcause;
static int slru_errno;
-static void SimpleLruZeroLSNs(SlruDesc *ctl, int slotno);
-static void SimpleLruWaitIO(SlruDesc *ctl, int slotno);
-static void SlruInternalWritePage(SlruDesc *ctl, int slotno, SlruWriteAll fdata);
-static bool SlruPhysicalReadPage(SlruDesc *ctl, int64 pageno, int slotno);
-static bool SlruPhysicalWritePage(SlruDesc *ctl, int64 pageno, int slotno,
+static void SimpleLruZeroLSNs(const SlruDesc *ctl, int slotno);
+static void SimpleLruWaitIO(const SlruDesc *ctl, int slotno);
+static void SlruInternalWritePage(const SlruDesc *ctl, int slotno,
SlruWriteAll fdata);
-static void SlruReportIOError(SlruDesc *ctl, int64 pageno,
+static bool SlruPhysicalReadPage(const SlruDesc *ctl, int64 pageno,
+ int slotno);
+static bool SlruPhysicalWritePage(const SlruDesc *ctl, int64 pageno,
+ int slotno, SlruWriteAll fdata);
+static void SlruReportIOError(const SlruDesc *ctl, int64 pageno,
const void *opaque_data);
-static int SlruSelectLRUPage(SlruDesc *ctl, int64 pageno);
+static int SlruSelectLRUPage(const SlruDesc *ctl, int64 pageno);
-static bool SlruScanDirCbDeleteCutoff(SlruDesc *ctl, char *filename,
+static bool SlruScanDirCbDeleteCutoff(const SlruDesc *ctl,
+ const char *filename,
int64 segpage, void *data);
-static void SlruInternalDeleteSegment(SlruDesc *ctl, int64 segno);
+static void SlruInternalDeleteSegment(const SlruDesc *ctl, int64 segno);
static inline void SlruRecentlyUsed(SlruShared shared, int slotno);
@@ -394,7 +397,7 @@ check_slru_buffers(const char *name, int *newval)
* Bank lock must be held at entry, and will be held at exit.
*/
int
-SimpleLruZeroPage(SlruDesc *ctl, int64 pageno)
+SimpleLruZeroPage(const SlruDesc *ctl, int64 pageno)
{
SlruShared shared = ctl->shared;
int slotno;
@@ -447,7 +450,7 @@ SimpleLruZeroPage(SlruDesc *ctl, int64 pageno)
* This assumes that InvalidXLogRecPtr is bitwise-all-0.
*/
static void
-SimpleLruZeroLSNs(SlruDesc *ctl, int slotno)
+SimpleLruZeroLSNs(const SlruDesc *ctl, int slotno)
{
SlruShared shared = ctl->shared;
@@ -463,7 +466,7 @@ SimpleLruZeroLSNs(SlruDesc *ctl, int slotno)
* SLRU bank lock is acquired and released here.
*/
void
-SimpleLruZeroAndWritePage(SlruDesc *ctl, int64 pageno)
+SimpleLruZeroAndWritePage(const SlruDesc *ctl, int64 pageno)
{
int slotno;
LWLock *lock;
@@ -489,7 +492,7 @@ SimpleLruZeroAndWritePage(SlruDesc *ctl, int64 pageno)
* Bank lock must be held at entry, and will be held at exit.
*/
static void
-SimpleLruWaitIO(SlruDesc *ctl, int slotno)
+SimpleLruWaitIO(const SlruDesc *ctl, int slotno)
{
SlruShared shared = ctl->shared;
int bankno = SlotGetBankNumber(slotno);
@@ -547,7 +550,7 @@ SimpleLruWaitIO(SlruDesc *ctl, int slotno)
* The correct bank lock must be held at entry, and will be held at exit.
*/
int
-SimpleLruReadPage(SlruDesc *ctl, int64 pageno, bool write_ok,
+SimpleLruReadPage(const SlruDesc *ctl, int64 pageno, bool write_ok,
const void *opaque_data)
{
SlruShared shared = ctl->shared;
@@ -651,7 +654,7 @@ SimpleLruReadPage(SlruDesc *ctl, int64 pageno, bool write_ok,
* It is unspecified whether the lock will be shared or exclusive.
*/
int
-SimpleLruReadPage_ReadOnly(SlruDesc *ctl, int64 pageno, const void *opaque_data)
+SimpleLruReadPage_ReadOnly(const SlruDesc *ctl, int64 pageno, const void *opaque_data)
{
SlruShared shared = ctl->shared;
LWLock *banklock = SimpleLruGetBankLock(ctl, pageno);
@@ -698,7 +701,7 @@ SimpleLruReadPage_ReadOnly(SlruDesc *ctl, int64 pageno, const void *opaque_data)
* Bank lock must be held at entry, and will be held at exit.
*/
static void
-SlruInternalWritePage(SlruDesc *ctl, int slotno, SlruWriteAll fdata)
+SlruInternalWritePage(const SlruDesc *ctl, int slotno, SlruWriteAll fdata)
{
SlruShared shared = ctl->shared;
int64 pageno = shared->page_number[slotno];
@@ -778,7 +781,7 @@ SlruInternalWritePage(SlruDesc *ctl, int slotno, SlruWriteAll fdata)
* fdata is always passed a NULL here.
*/
void
-SimpleLruWritePage(SlruDesc *ctl, int slotno)
+SimpleLruWritePage(const SlruDesc *ctl, int slotno)
{
Assert(ctl->shared->page_status[slotno] != SLRU_PAGE_EMPTY);
@@ -792,7 +795,7 @@ SimpleLruWritePage(SlruDesc *ctl, int slotno)
* large enough to contain the given page.
*/
bool
-SimpleLruDoesPhysicalPageExist(SlruDesc *ctl, int64 pageno)
+SimpleLruDoesPhysicalPageExist(const SlruDesc *ctl, int64 pageno)
{
int64 segno = pageno / SLRU_PAGES_PER_SEGMENT;
int rpageno = pageno % SLRU_PAGES_PER_SEGMENT;
@@ -850,7 +853,7 @@ SimpleLruDoesPhysicalPageExist(SlruDesc *ctl, int64 pageno)
* read/write operations. We could cache one virtual file pointer ...
*/
static bool
-SlruPhysicalReadPage(SlruDesc *ctl, int64 pageno, int slotno)
+SlruPhysicalReadPage(const SlruDesc *ctl, int64 pageno, int slotno)
{
SlruShared shared = ctl->shared;
int64 segno = pageno / SLRU_PAGES_PER_SEGMENT;
@@ -922,7 +925,7 @@ SlruPhysicalReadPage(SlruDesc *ctl, int64 pageno, int slotno)
* SimpleLruWriteAll.
*/
static bool
-SlruPhysicalWritePage(SlruDesc *ctl, int64 pageno, int slotno, SlruWriteAll fdata)
+SlruPhysicalWritePage(const SlruDesc *ctl, int64 pageno, int slotno, SlruWriteAll fdata)
{
SlruShared shared = ctl->shared;
int64 segno = pageno / SLRU_PAGES_PER_SEGMENT;
@@ -1094,7 +1097,7 @@ SlruPhysicalWritePage(SlruDesc *ctl, int64 pageno, int slotno, SlruWriteAll fdat
* SlruPhysicalWritePage. Call this after cleaning up shared-memory state.
*/
static void
-SlruReportIOError(SlruDesc *ctl, int64 pageno, const void *opaque_data)
+SlruReportIOError(const SlruDesc *ctl, int64 pageno, const void *opaque_data)
{
int64 segno = pageno / SLRU_PAGES_PER_SEGMENT;
int rpageno = pageno % SLRU_PAGES_PER_SEGMENT;
@@ -1216,7 +1219,7 @@ SlruRecentlyUsed(SlruShared shared, int slotno)
* The correct bank lock must be held at entry, and will be held at exit.
*/
static int
-SlruSelectLRUPage(SlruDesc *ctl, int64 pageno)
+SlruSelectLRUPage(const SlruDesc *ctl, int64 pageno)
{
SlruShared shared = ctl->shared;
@@ -1369,7 +1372,7 @@ SlruSelectLRUPage(SlruDesc *ctl, int64 pageno)
* entries are on disk.
*/
void
-SimpleLruWriteAll(SlruDesc *ctl, bool allow_redirtied)
+SimpleLruWriteAll(const SlruDesc *ctl, bool allow_redirtied)
{
SlruShared shared = ctl->shared;
SlruWriteAllData fdata;
@@ -1455,7 +1458,7 @@ SimpleLruWriteAll(SlruDesc *ctl, bool allow_redirtied)
* after it has accrued freshly-written data.
*/
void
-SimpleLruTruncate(SlruDesc *ctl, int64 cutoffPage)
+SimpleLruTruncate(const SlruDesc *ctl, int64 cutoffPage)
{
SlruShared shared = ctl->shared;
int prevbank;
@@ -1550,7 +1553,7 @@ restart:
* they either can't yet contain anything, or have already been cleaned out.
*/
static void
-SlruInternalDeleteSegment(SlruDesc *ctl, int64 segno)
+SlruInternalDeleteSegment(const SlruDesc *ctl, int64 segno)
{
char path[MAXPGPATH];
@@ -1573,7 +1576,7 @@ SlruInternalDeleteSegment(SlruDesc *ctl, int64 segno)
* Delete an individual SLRU segment, identified by the segment number.
*/
void
-SlruDeleteSegment(SlruDesc *ctl, int64 segno)
+SlruDeleteSegment(const SlruDesc *ctl, int64 segno)
{
SlruShared shared = ctl->shared;
int prevbank = SlotGetBankNumber(0);
@@ -1650,7 +1653,7 @@ restart:
* first>=cutoff && last>=cutoff: no; every page of this segment is too young
*/
static bool
-SlruMayDeleteSegment(SlruDesc *ctl, int64 segpage, int64 cutoffPage)
+SlruMayDeleteSegment(const SlruDesc *ctl, int64 segpage, int64 cutoffPage)
{
int64 seg_last_page = segpage + SLRU_PAGES_PER_SEGMENT - 1;
@@ -1662,7 +1665,7 @@ SlruMayDeleteSegment(SlruDesc *ctl, int64 segpage, int64 cutoffPage)
#ifdef USE_ASSERT_CHECKING
static void
-SlruPagePrecedesTestOffset(SlruDesc *ctl, int per_page, uint32 offset)
+SlruPagePrecedesTestOffset(const SlruDesc *ctl, int per_page, uint32 offset)
{
TransactionId lhs,
rhs;
@@ -1747,7 +1750,7 @@ SlruPagePrecedesTestOffset(SlruDesc *ctl, int per_page, uint32 offset)
* do not apply to them.)
*/
void
-SlruPagePrecedesUnitTests(SlruDesc *ctl, int per_page)
+SlruPagePrecedesUnitTests(const SlruDesc *ctl, int per_page)
{
/* Test first, middle and last entries of a page. */
SlruPagePrecedesTestOffset(ctl, per_page, 0);
@@ -1762,8 +1765,8 @@ SlruPagePrecedesUnitTests(SlruDesc *ctl, int per_page)
* one containing the page passed as "data".
*/
bool
-SlruScanDirCbReportPresence(SlruDesc *ctl, char *filename, int64 segpage,
- void *data)
+SlruScanDirCbReportPresence(const SlruDesc *ctl, const char *filename,
+ int64 segpage, void *data)
{
int64 cutoffPage = *(int64 *) data;
@@ -1778,7 +1781,7 @@ SlruScanDirCbReportPresence(SlruDesc *ctl, char *filename, int64 segpage,
* This callback deletes segments prior to the one passed in as "data".
*/
static bool
-SlruScanDirCbDeleteCutoff(SlruDesc *ctl, char *filename, int64 segpage,
+SlruScanDirCbDeleteCutoff(const SlruDesc *ctl, const char *filename, int64 segpage,
void *data)
{
int64 cutoffPage = *(int64 *) data;
@@ -1794,7 +1797,8 @@ SlruScanDirCbDeleteCutoff(SlruDesc *ctl, char *filename, int64 segpage,
* This callback deletes all segments.
*/
bool
-SlruScanDirCbDeleteAll(SlruDesc *ctl, char *filename, int64 segpage, void *data)
+SlruScanDirCbDeleteAll(const SlruDesc *ctl, const char *filename,
+ int64 segpage, void *data)
{
SlruInternalDeleteSegment(ctl, segpage / SLRU_PAGES_PER_SEGMENT);
@@ -1808,7 +1812,7 @@ SlruScanDirCbDeleteAll(SlruDesc *ctl, char *filename, int64 segpage, void *data)
* SLRU segment.
*/
static inline bool
-SlruCorrectSegmentFilenameLength(SlruDesc *ctl, size_t len)
+SlruCorrectSegmentFilenameLength(const SlruDesc *ctl, size_t len)
{
if (ctl->options.long_segment_names)
return (len == 15); /* see SlruFileName() */
@@ -1841,7 +1845,7 @@ SlruCorrectSegmentFilenameLength(SlruDesc *ctl, size_t len)
* Note that no locking is applied.
*/
bool
-SlruScanDirectory(SlruDesc *ctl, SlruScanCallback callback, void *data)
+SlruScanDirectory(const SlruDesc *ctl, SlruScanCallback callback, void *data)
{
bool retval = false;
DIR *cldir;
@@ -1881,7 +1885,7 @@ SlruScanDirectory(SlruDesc *ctl, SlruScanCallback callback, void *data)
* performs the fsync.
*/
int
-SlruSyncFileTag(SlruDesc *ctl, const FileTag *ftag, char *path)
+SlruSyncFileTag(const SlruDesc *ctl, const FileTag *ftag, char *path)
{
int fd;
int save_errno;
diff --git a/src/include/access/slru.h b/src/include/access/slru.h
index 36a7514d7a0..74ea84deec5 100644
--- a/src/include/access/slru.h
+++ b/src/include/access/slru.h
@@ -200,7 +200,7 @@ typedef struct SlruDesc
* respective bank.
*/
static inline LWLock *
-SimpleLruGetBankLock(SlruDesc *ctl, int64 pageno)
+SimpleLruGetBankLock(const SlruDesc *ctl, int64 pageno)
{
int bankno;
@@ -215,34 +215,36 @@ extern void SimpleLruRequestWithOpts(const SlruOpts *options);
SimpleLruRequestWithOpts(&(SlruOpts){__VA_ARGS__})
extern int SimpleLruAutotuneBuffers(int divisor, int max);
-extern int SimpleLruZeroPage(SlruDesc *ctl, int64 pageno);
-extern void SimpleLruZeroAndWritePage(SlruDesc *ctl, int64 pageno);
-extern int SimpleLruReadPage(SlruDesc *ctl, int64 pageno, bool write_ok,
+extern int SimpleLruZeroPage(const SlruDesc *ctl, int64 pageno);
+extern void SimpleLruZeroAndWritePage(const SlruDesc *ctl, int64 pageno);
+extern int SimpleLruReadPage(const SlruDesc *ctl, int64 pageno, bool write_ok,
const void *opaque_data);
-extern int SimpleLruReadPage_ReadOnly(SlruDesc *ctl, int64 pageno,
+extern int SimpleLruReadPage_ReadOnly(const SlruDesc *ctl, int64 pageno,
const void *opaque_data);
-extern void SimpleLruWritePage(SlruDesc *ctl, int slotno);
-extern void SimpleLruWriteAll(SlruDesc *ctl, bool allow_redirtied);
+extern void SimpleLruWritePage(const SlruDesc *ctl, int slotno);
+extern void SimpleLruWriteAll(const SlruDesc *ctl, bool allow_redirtied);
#ifdef USE_ASSERT_CHECKING
-extern void SlruPagePrecedesUnitTests(SlruDesc *ctl, int per_page);
+extern void SlruPagePrecedesUnitTests(const SlruDesc *ctl, int per_page);
#else
#define SlruPagePrecedesUnitTests(ctl, per_page) do {} while (0)
#endif
-extern void SimpleLruTruncate(SlruDesc *ctl, int64 cutoffPage);
-extern bool SimpleLruDoesPhysicalPageExist(SlruDesc *ctl, int64 pageno);
+extern void SimpleLruTruncate(const SlruDesc *ctl, int64 cutoffPage);
+extern bool SimpleLruDoesPhysicalPageExist(const SlruDesc *ctl, int64 pageno);
-typedef bool (*SlruScanCallback) (SlruDesc *ctl, char *filename, int64 segpage,
- void *data);
-extern bool SlruScanDirectory(SlruDesc *ctl, SlruScanCallback callback, void *data);
-extern void SlruDeleteSegment(SlruDesc *ctl, int64 segno);
+typedef bool (*SlruScanCallback) (const SlruDesc *ctl, const char *filename,
+ int64 segpage, void *data);
+extern bool SlruScanDirectory(const SlruDesc *ctl, SlruScanCallback callback,
+ void *data);
+extern void SlruDeleteSegment(const SlruDesc *ctl, int64 segno);
-extern int SlruSyncFileTag(SlruDesc *ctl, const FileTag *ftag, char *path);
+extern int SlruSyncFileTag(const SlruDesc *ctl, const FileTag *ftag,
+ char *path);
/* SlruScanDirectory public callbacks */
-extern bool SlruScanDirCbReportPresence(SlruDesc *ctl, char *filename,
+extern bool SlruScanDirCbReportPresence(const SlruDesc *ctl, const char *filename,
int64 segpage, void *data);
-extern bool SlruScanDirCbDeleteAll(SlruDesc *ctl, char *filename, int64 segpage,
- void *data);
+extern bool SlruScanDirCbDeleteAll(const SlruDesc *ctl, const char *filename,
+ int64 segpage, void *data);
extern bool check_slru_buffers(const char *name, int *newval);
extern void shmem_slru_init(void *location, ShmemStructOpts *options);
diff --git a/src/test/modules/test_slru/test_slru.c b/src/test/modules/test_slru/test_slru.c
index 40efffdbf62..5dfa082ed25 100644
--- a/src/test/modules/test_slru/test_slru.c
+++ b/src/test/modules/test_slru/test_slru.c
@@ -55,7 +55,8 @@ static const ShmemCallbacks test_slru_shmem_callbacks = {
#define TestSlruCtl (&TestSlruDesc)
static bool
-test_slru_scan_cb(SlruDesc *ctl, char *filename, int64 segpage, void *data)
+test_slru_scan_cb(const SlruDesc *ctl, const char *filename, int64 segpage,
+ void *data)
{
elog(NOTICE, "Calling test_slru_scan_cb()");
return SlruScanDirCbDeleteAll(ctl, filename, segpage, data);
--
2.50.1 (Apple Git-155)