Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8735978

Browse files
committed
Pad XLogReaderState's main_data buffer more aggressively.
Originally, we palloc'd this buffer just barely big enough to hold thelargest xlog record seen so far. It turns out that that can result invalgrind complaints, because some compilers will emit code that assumesit can safely fetch padding bytes at the end of a struct, and thosepadding bytes were unallocated so far as aset.c was concerned. We canfix that by MAXALIGN'ing the palloc request size, ensuring that it is bigenough to include any possible padding that might've been omitted fromthe on-disk record.An additional objection to the original coding is that it could result inmany repeated palloc cycles, in the worst case where we see a series ofgradually larger xlog records. We can ameliorate that cheaply byimposing a minimum buffer size that's large enough for most xlog records.BLCKSZ/2 was chosen after a bit of discussion.In passing, remove an obsolete comment in struct xl_heap_new_cid that thecombocid field is free due to alignment considerations. Perhaps that wastrue at some point, but it's not now.Back-patch to 9.5 where this code came in.Discussion:https://postgr.es/m/E1eHa4J-0006hI-Q8@gemulon.postgresql.org
1 parent752714d commit8735978

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

‎src/backend/access/transam/xlogreader.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,22 @@ DecodeXLogRecord(XLogReaderState *state, XLogRecord *record, char **errormsg)
12791279
{
12801280
if (state->main_data)
12811281
pfree(state->main_data);
1282-
state->main_data_bufsz=state->main_data_len;
1282+
1283+
/*
1284+
* main_data_bufsz must be MAXALIGN'ed. In many xlog record
1285+
* types, we omit trailing struct padding on-disk to save a few
1286+
* bytes; but compilers may generate accesses to the xlog struct
1287+
* that assume that padding bytes are present. If the palloc
1288+
* request is not large enough to include such padding bytes then
1289+
* we'll get valgrind complaints due to otherwise-harmless fetches
1290+
* of the padding bytes.
1291+
*
1292+
* In addition, force the initial request to be reasonably large
1293+
* so that we don't waste time with lots of trips through this
1294+
* stanza. BLCKSZ / 2 seems like a good compromise choice.
1295+
*/
1296+
state->main_data_bufsz=MAXALIGN(Max(state->main_data_len,
1297+
BLCKSZ /2));
12831298
state->main_data=palloc(state->main_data_bufsz);
12841299
}
12851300
memcpy(state->main_data,ptr,state->main_data_len);

‎src/include/access/heapam_xlog.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,7 @@ typedef struct xl_heap_new_cid
339339
TransactionIdtop_xid;
340340
CommandIdcmin;
341341
CommandIdcmax;
342-
343-
/*
344-
* don't really need the combocid since we have the actual values right in
345-
* this struct, but the padding makes it free and its useful for
346-
* debugging.
347-
*/
348-
CommandIdcombocid;
342+
CommandIdcombocid;/* just for debugging */
349343

350344
/*
351345
* Store the relfilenode/ctid pair to facilitate lookups.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp