Skip to content

Commit 9a32150

Browse files
Make min_wal_size/max_wal_size use MB internally
Previously they were defined using multiples of XLogSegSize. Remove GUC_UNIT_XSEGS. Introduce GUC_UNIT_MB Extracted from patch series on XLogSegSize infrastructure. Beena Emerson
1 parent cd740c0 commit 9a32150

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

src/backend/access/transam/xlog.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ extern uint32 bootstrap_data_checksum_version;
8686

8787

8888
/* User-settable parameters */
89-
int max_wal_size = 64; /* 1 GB */
90-
int min_wal_size = 5; /* 80 MB */
89+
int max_wal_size_mb = 1024; /* 1 GB */
90+
int min_wal_size_mb = 80; /* 80 MB */
9191
int wal_keep_segments = 0;
9292
int XLOGbuffers = -1;
9393
int XLogArchiveTimeout = 0;
@@ -738,6 +738,10 @@ static ControlFileData *ControlFile = NULL;
738738
#define UsableBytesInPage (XLOG_BLCKSZ - SizeOfXLogShortPHD)
739739
#define UsableBytesInSegment ((XLOG_SEG_SIZE / XLOG_BLCKSZ) * UsableBytesInPage - (SizeOfXLogLongPHD - SizeOfXLogShortPHD))
740740

741+
/* Convert min_wal_size_mb and max wal_size_mb to equivalent segment count */
742+
#define ConvertToXSegs(x) \
743+
(x / (XLOG_SEG_SIZE / (1024 * 1024)))
744+
741745
/*
742746
* Private, possibly out-of-date copy of shared LogwrtResult.
743747
* See discussion above.
@@ -2200,7 +2204,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, bool opportunistic)
22002204
}
22012205

22022206
/*
2203-
* Calculate CheckPointSegments based on max_wal_size and
2207+
* Calculate CheckPointSegments based on max_wal_size_mb and
22042208
* checkpoint_completion_target.
22052209
*/
22062210
static void
@@ -2210,14 +2214,14 @@ CalculateCheckpointSegments(void)
22102214

22112215
/*-------
22122216
* Calculate the distance at which to trigger a checkpoint, to avoid
2213-
* exceeding max_wal_size. This is based on two assumptions:
2217+
* exceeding max_wal_size_mb. This is based on two assumptions:
22142218
*
22152219
* a) we keep WAL for two checkpoint cycles, back to the "prev" checkpoint.
22162220
* b) during checkpoint, we consume checkpoint_completion_target *
22172221
* number of segments consumed between checkpoints.
22182222
*-------
22192223
*/
2220-
target = (double) max_wal_size / (2.0 + CheckPointCompletionTarget);
2224+
target = (double) ConvertToXSegs(max_wal_size_mb) / (2.0 + CheckPointCompletionTarget);
22212225

22222226
/* round down */
22232227
CheckPointSegments = (int) target;
@@ -2229,7 +2233,7 @@ CalculateCheckpointSegments(void)
22292233
void
22302234
assign_max_wal_size(int newval, void *extra)
22312235
{
2232-
max_wal_size = newval;
2236+
max_wal_size_mb = newval;
22332237
CalculateCheckpointSegments();
22342238
}
22352239

@@ -2253,12 +2257,12 @@ XLOGfileslop(XLogRecPtr PriorRedoPtr)
22532257
XLogSegNo recycleSegNo;
22542258

22552259
/*
2256-
* Calculate the segment numbers that min_wal_size and max_wal_size
2260+
* Calculate the segment numbers that min_wal_size_mb and max_wal_size_mb
22572261
* correspond to. Always recycle enough segments to meet the minimum, and
22582262
* remove enough segments to stay below the maximum.
22592263
*/
2260-
minSegNo = PriorRedoPtr / XLOG_SEG_SIZE + min_wal_size - 1;
2261-
maxSegNo = PriorRedoPtr / XLOG_SEG_SIZE + max_wal_size - 1;
2264+
minSegNo = PriorRedoPtr / XLOG_SEG_SIZE + ConvertToXSegs(min_wal_size_mb) - 1;
2265+
maxSegNo = PriorRedoPtr / XLOG_SEG_SIZE + ConvertToXSegs(max_wal_size_mb) - 1;
22622266

22632267
/*
22642268
* Between those limits, recycle enough segments to get us through to the

src/backend/utils/misc/guc.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,11 @@ static const unit_conversion memory_unit_conversion_table[] =
729729
{"MB", GUC_UNIT_KB, 1024},
730730
{"kB", GUC_UNIT_KB, 1},
731731

732+
{"TB", GUC_UNIT_MB, 1024 * 1024},
733+
{"GB", GUC_UNIT_MB, 1024},
734+
{"MB", GUC_UNIT_MB, 1},
735+
{"kB", GUC_UNIT_MB, -1024},
736+
732737
{"TB", GUC_UNIT_BLOCKS, (1024 * 1024 * 1024) / (BLCKSZ / 1024)},
733738
{"GB", GUC_UNIT_BLOCKS, (1024 * 1024) / (BLCKSZ / 1024)},
734739
{"MB", GUC_UNIT_BLOCKS, 1024 / (BLCKSZ / 1024)},
@@ -739,11 +744,6 @@ static const unit_conversion memory_unit_conversion_table[] =
739744
{"MB", GUC_UNIT_XBLOCKS, 1024 / (XLOG_BLCKSZ / 1024)},
740745
{"kB", GUC_UNIT_XBLOCKS, -(XLOG_BLCKSZ / 1024)},
741746

742-
{"TB", GUC_UNIT_XSEGS, (1024 * 1024 * 1024) / (XLOG_SEG_SIZE / 1024)},
743-
{"GB", GUC_UNIT_XSEGS, (1024 * 1024) / (XLOG_SEG_SIZE / 1024)},
744-
{"MB", GUC_UNIT_XSEGS, -(XLOG_SEG_SIZE / (1024 * 1024))},
745-
{"kB", GUC_UNIT_XSEGS, -(XLOG_SEG_SIZE / 1024)},
746-
747747
{""} /* end of table marker */
748748
};
749749

@@ -2236,21 +2236,21 @@ static struct config_int ConfigureNamesInt[] =
22362236
{"min_wal_size", PGC_SIGHUP, WAL_CHECKPOINTS,
22372237
gettext_noop("Sets the minimum size to shrink the WAL to."),
22382238
NULL,
2239-
GUC_UNIT_XSEGS
2239+
GUC_UNIT_MB
22402240
},
2241-
&min_wal_size,
2242-
5, 2, INT_MAX,
2241+
&min_wal_size_mb,
2242+
5 * (XLOG_SEG_SIZE/ (1024 * 1024)), 2, MAX_KILOBYTES,
22432243
NULL, NULL, NULL
22442244
},
22452245

22462246
{
22472247
{"max_wal_size", PGC_SIGHUP, WAL_CHECKPOINTS,
22482248
gettext_noop("Sets the WAL size that triggers a checkpoint."),
22492249
NULL,
2250-
GUC_UNIT_XSEGS
2250+
GUC_UNIT_MB
22512251
},
2252-
&max_wal_size,
2253-
64, 2, INT_MAX,
2252+
&max_wal_size_mb,
2253+
64 * (XLOG_SEG_SIZE/ (1024 * 1024)), 2, MAX_KILOBYTES,
22542254
NULL, assign_max_wal_size, NULL
22552255
},
22562256

@@ -8085,6 +8085,9 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
80858085
case GUC_UNIT_KB:
80868086
values[2] = "kB";
80878087
break;
8088+
case GUC_UNIT_MB:
8089+
values[2] = "MB";
8090+
break;
80888091
case GUC_UNIT_BLOCKS:
80898092
snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
80908093
values[2] = pstrdup(buffer);
@@ -8093,11 +8096,6 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
80938096
snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
80948097
values[2] = pstrdup(buffer);
80958098
break;
8096-
case GUC_UNIT_XSEGS:
8097-
snprintf(buffer, sizeof(buffer), "%dMB",
8098-
XLOG_SEG_SIZE / (1024 * 1024));
8099-
values[2] = pstrdup(buffer);
8100-
break;
81018099
case GUC_UNIT_MS:
81028100
values[2] = "ms";
81038101
break;

src/include/access/xlog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ extern PGDLLIMPORT XLogRecPtr XactLastCommitEnd;
9494
extern bool reachedConsistency;
9595

9696
/* these variables are GUC parameters related to XLOG */
97-
extern int min_wal_size;
98-
extern int max_wal_size;
97+
extern int min_wal_size_mb;
98+
extern int max_wal_size_mb;
9999
extern int wal_keep_segments;
100100
extern int XLOGbuffers;
101101
extern int XLogArchiveTimeout;

src/include/utils/guc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ typedef enum
218218
#define GUC_UNIT_KB 0x1000 /* value is in kilobytes */
219219
#define GUC_UNIT_BLOCKS 0x2000 /* value is in blocks */
220220
#define GUC_UNIT_XBLOCKS 0x3000 /* value is in xlog blocks */
221-
#define GUC_UNIT_XSEGS 0x4000 /* value is in xlog segments */
221+
#define GUC_UNIT_MB 0x4000 /* value is in megabytes */
222222
#define GUC_UNIT_MEMORY 0xF000 /* mask for size-related units */
223223

224224
#define GUC_UNIT_MS 0x10000 /* value is in milliseconds */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy