pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Avoid using potentially-under-aligned page buffers. 7+ messages / 1 participants [nested] [flat]
* pgsql: Avoid using potentially-under-aligned page buffers. @ 2018-09-01 19:27 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-09-01 19:27 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid using potentially-under-aligned page buffers. There's a project policy against using plain "char buf[BLCKSZ]" local or static variables as page buffers; preferred style is to palloc or malloc each buffer to ensure it is MAXALIGN'd. However, that policy's been ignored in an increasing number of places. We've apparently got away with it so far, probably because (a) relatively few people use platforms on which misalignment causes core dumps and/or (b) the variables chance to be sufficiently aligned anyway. But this is not something to rely on. Moreover, even if we don't get a core dump, we might be paying a lot of cycles for misaligned accesses. To fix, invent new union types PGAlignedBlock and PGAlignedXLogBlock that the compiler must allocate with sufficient alignment, and use those in place of plain char arrays. I used these types even for variables where there's no risk of a misaligned access, since ensuring proper alignment should make kernel data transfers faster. I also changed some places where we had been palloc'ing short-lived buffers, for coding style uniformity and to save palloc/pfree overhead. Since this seems to be a live portability hazard (despite the lack of field reports), back-patch to all supported versions. Patch by me; thanks to Michael Paquier for review. Discussion: https://postgr.es/m/1535618100.1286.3.camel@credativ.de Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/44cac9346479d4b0cc9195b0267fd13eb4e7442c Modified Files -------------- contrib/bloom/blinsert.c | 12 ++++----- contrib/pg_prewarm/pg_prewarm.c | 4 +-- contrib/pg_standby/pg_standby.c | 10 +++----- src/backend/access/gin/ginentrypage.c | 6 ++--- src/backend/access/gin/ginfast.c | 11 +++----- src/backend/access/hash/hashpage.c | 8 +++--- src/backend/access/heap/heapam.c | 16 +++--------- src/backend/access/heap/visibilitymap.c | 11 +++----- src/backend/access/transam/generic_xlog.c | 21 +++++++-------- src/backend/access/transam/xlog.c | 26 +++++++++---------- src/backend/access/transam/xloginsert.c | 14 +++++----- src/backend/access/transam/xlogreader.c | 6 ++--- src/backend/commands/tablecmds.c | 20 +++++---------- src/backend/replication/walsender.c | 6 ++--- src/backend/storage/file/buffile.c | 10 ++++---- src/backend/storage/freespace/freespace.c | 11 +++----- src/backend/utils/sort/logtape.c | 6 ++--- src/bin/pg_basebackup/walmethods.c | 20 +++++---------- src/bin/pg_resetwal/pg_resetwal.c | 14 +++++----- src/bin/pg_rewind/copy_fetch.c | 6 ++--- src/bin/pg_upgrade/file.c | 31 ++++++++--------------- src/bin/pg_verify_checksums/pg_verify_checksums.c | 8 +++--- src/bin/pg_waldump/pg_waldump.c | 6 ++--- src/include/c.h | 26 +++++++++++++++++++ 24 files changed, 141 insertions(+), 168 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid using potentially-under-aligned page buffers. @ 2018-09-01 19:27 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-09-01 19:27 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid using potentially-under-aligned page buffers. There's a project policy against using plain "char buf[BLCKSZ]" local or static variables as page buffers; preferred style is to palloc or malloc each buffer to ensure it is MAXALIGN'd. However, that policy's been ignored in an increasing number of places. We've apparently got away with it so far, probably because (a) relatively few people use platforms on which misalignment causes core dumps and/or (b) the variables chance to be sufficiently aligned anyway. But this is not something to rely on. Moreover, even if we don't get a core dump, we might be paying a lot of cycles for misaligned accesses. To fix, invent new union types PGAlignedBlock and PGAlignedXLogBlock that the compiler must allocate with sufficient alignment, and use those in place of plain char arrays. I used these types even for variables where there's no risk of a misaligned access, since ensuring proper alignment should make kernel data transfers faster. I also changed some places where we had been palloc'ing short-lived buffers, for coding style uniformity and to save palloc/pfree overhead. Since this seems to be a live portability hazard (despite the lack of field reports), back-patch to all supported versions. Patch by me; thanks to Michael Paquier for review. Discussion: https://postgr.es/m/1535618100.1286.3.camel@credativ.de Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/f5c93cf92223534df862ab7d8c698f05d5b38485 Modified Files -------------- contrib/bloom/blinsert.c | 12 ++++----- contrib/pg_prewarm/pg_prewarm.c | 4 +-- contrib/pg_standby/pg_standby.c | 10 +++----- src/backend/access/gin/ginentrypage.c | 6 ++--- src/backend/access/gin/ginfast.c | 11 +++----- src/backend/access/hash/hashpage.c | 8 +++--- src/backend/access/heap/heapam.c | 16 +++--------- src/backend/access/heap/visibilitymap.c | 11 +++----- src/backend/access/transam/generic_xlog.c | 21 +++++++-------- src/backend/access/transam/xlog.c | 26 +++++++++---------- src/backend/access/transam/xloginsert.c | 14 +++++----- src/backend/access/transam/xlogreader.c | 6 ++--- src/backend/commands/tablecmds.c | 17 +++---------- src/backend/replication/walsender.c | 6 ++--- src/backend/storage/file/buffile.c | 10 ++++---- src/backend/storage/freespace/freespace.c | 11 +++----- src/backend/utils/sort/logtape.c | 6 ++--- src/bin/pg_basebackup/walmethods.c | 20 +++++---------- src/bin/pg_resetwal/pg_resetwal.c | 14 +++++----- src/bin/pg_rewind/copy_fetch.c | 6 ++--- src/bin/pg_upgrade/file.c | 31 ++++++++--------------- src/bin/pg_verify_checksums/pg_verify_checksums.c | 8 +++--- src/bin/pg_waldump/pg_waldump.c | 6 ++--- src/include/c.h | 26 +++++++++++++++++++ 24 files changed, 139 insertions(+), 167 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid using potentially-under-aligned page buffers. @ 2018-09-01 19:27 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-09-01 19:27 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid using potentially-under-aligned page buffers. There's a project policy against using plain "char buf[BLCKSZ]" local or static variables as page buffers; preferred style is to palloc or malloc each buffer to ensure it is MAXALIGN'd. However, that policy's been ignored in an increasing number of places. We've apparently got away with it so far, probably because (a) relatively few people use platforms on which misalignment causes core dumps and/or (b) the variables chance to be sufficiently aligned anyway. But this is not something to rely on. Moreover, even if we don't get a core dump, we might be paying a lot of cycles for misaligned accesses. To fix, invent new union types PGAlignedBlock and PGAlignedXLogBlock that the compiler must allocate with sufficient alignment, and use those in place of plain char arrays. I used these types even for variables where there's no risk of a misaligned access, since ensuring proper alignment should make kernel data transfers faster. I also changed some places where we had been palloc'ing short-lived buffers, for coding style uniformity and to save palloc/pfree overhead. Since this seems to be a live portability hazard (despite the lack of field reports), back-patch to all supported versions. Patch by me; thanks to Michael Paquier for review. Discussion: https://postgr.es/m/1535618100.1286.3.camel@credativ.de Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/10b9af3ebbedfcbe696bf93d4db861db8de0de32 Modified Files -------------- contrib/bloom/blinsert.c | 12 ++++++------ contrib/pg_prewarm/pg_prewarm.c | 4 ++-- src/backend/access/gin/ginentrypage.c | 6 +++--- src/backend/access/gin/ginfast.c | 11 +++-------- src/backend/access/hash/hashpage.c | 8 ++++---- src/backend/access/heap/heapam.c | 16 ++++------------ src/backend/access/heap/visibilitymap.c | 11 ++++------- src/backend/access/transam/generic_xlog.c | 21 +++++++++------------ src/backend/access/transam/xlog.c | 26 ++++++++++++-------------- src/backend/access/transam/xloginsert.c | 14 +++++++------- src/backend/access/transam/xlogreader.c | 6 +++--- src/backend/commands/tablecmds.c | 17 ++++------------- src/backend/replication/walsender.c | 6 +++--- src/backend/storage/file/buffile.c | 10 +++++----- src/backend/storage/freespace/freespace.c | 11 ++++------- src/backend/utils/sort/logtape.c | 6 +++--- src/bin/pg_basebackup/walmethods.c | 20 +++++++------------- src/bin/pg_resetwal/pg_resetwal.c | 14 ++++++-------- src/bin/pg_rewind/copy_fetch.c | 6 +++--- src/bin/pg_upgrade/file.c | 31 +++++++++++-------------------- src/include/c.h | 26 ++++++++++++++++++++++++++ 21 files changed, 129 insertions(+), 153 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid using potentially-under-aligned page buffers. @ 2018-09-01 19:27 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-09-01 19:27 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid using potentially-under-aligned page buffers. There's a project policy against using plain "char buf[BLCKSZ]" local or static variables as page buffers; preferred style is to palloc or malloc each buffer to ensure it is MAXALIGN'd. However, that policy's been ignored in an increasing number of places. We've apparently got away with it so far, probably because (a) relatively few people use platforms on which misalignment causes core dumps and/or (b) the variables chance to be sufficiently aligned anyway. But this is not something to rely on. Moreover, even if we don't get a core dump, we might be paying a lot of cycles for misaligned accesses. To fix, invent new union types PGAlignedBlock and PGAlignedXLogBlock that the compiler must allocate with sufficient alignment, and use those in place of plain char arrays. I used these types even for variables where there's no risk of a misaligned access, since ensuring proper alignment should make kernel data transfers faster. I also changed some places where we had been palloc'ing short-lived buffers, for coding style uniformity and to save palloc/pfree overhead. Since this seems to be a live portability hazard (despite the lack of field reports), back-patch to all supported versions. Patch by me; thanks to Michael Paquier for review. Discussion: https://postgr.es/m/1535618100.1286.3.camel@credativ.de Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/826980424538cb149670f9c89eedf34387ff674f Modified Files -------------- contrib/bloom/blinsert.c | 12 ++++++------ contrib/pg_prewarm/pg_prewarm.c | 4 ++-- src/backend/access/gin/ginentrypage.c | 6 +++--- src/backend/access/gin/ginfast.c | 11 +++-------- src/backend/access/hash/hashpage.c | 6 +++--- src/backend/access/heap/heapam.c | 16 ++++------------ src/backend/access/heap/visibilitymap.c | 11 ++++------- src/backend/access/transam/generic_xlog.c | 21 +++++++++------------ src/backend/access/transam/xlog.c | 19 +++++++------------ src/backend/access/transam/xloginsert.c | 14 +++++++------- src/backend/access/transam/xlogreader.c | 6 +++--- src/backend/commands/tablecmds.c | 17 ++++------------- src/backend/replication/walsender.c | 6 +++--- src/backend/storage/file/buffile.c | 10 +++++----- src/backend/storage/freespace/freespace.c | 11 ++++------- src/bin/pg_basebackup/receivelog.c | 8 +++----- src/bin/pg_resetxlog/pg_resetxlog.c | 14 ++++++-------- src/bin/pg_rewind/copy_fetch.c | 6 +++--- src/bin/pg_upgrade/file.c | 31 +++++++++++-------------------- src/include/c.h | 26 ++++++++++++++++++++++++++ 20 files changed, 116 insertions(+), 139 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid using potentially-under-aligned page buffers. @ 2018-09-01 19:27 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-09-01 19:27 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid using potentially-under-aligned page buffers. There's a project policy against using plain "char buf[BLCKSZ]" local or static variables as page buffers; preferred style is to palloc or malloc each buffer to ensure it is MAXALIGN'd. However, that policy's been ignored in an increasing number of places. We've apparently got away with it so far, probably because (a) relatively few people use platforms on which misalignment causes core dumps and/or (b) the variables chance to be sufficiently aligned anyway. But this is not something to rely on. Moreover, even if we don't get a core dump, we might be paying a lot of cycles for misaligned accesses. To fix, invent new union types PGAlignedBlock and PGAlignedXLogBlock that the compiler must allocate with sufficient alignment, and use those in place of plain char arrays. I used these types even for variables where there's no risk of a misaligned access, since ensuring proper alignment should make kernel data transfers faster. I also changed some places where we had been palloc'ing short-lived buffers, for coding style uniformity and to save palloc/pfree overhead. Since this seems to be a live portability hazard (despite the lack of field reports), back-patch to all supported versions. Patch by me; thanks to Michael Paquier for review. Discussion: https://postgr.es/m/1535618100.1286.3.camel@credativ.de Branch ------ REL9_5_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/03ffe5553c1d6238dc235e8d5e8f1295734e5c79 Modified Files -------------- contrib/pg_prewarm/pg_prewarm.c | 4 ++-- src/backend/access/gin/ginentrypage.c | 6 +++--- src/backend/access/gin/ginfast.c | 11 +++-------- src/backend/access/hash/hashpage.c | 6 +++--- src/backend/access/heap/heapam.c | 16 ++++------------ src/backend/access/heap/visibilitymap.c | 11 ++++------- src/backend/access/transam/xlog.c | 19 +++++++------------ src/backend/access/transam/xloginsert.c | 14 +++++++------- src/backend/access/transam/xlogreader.c | 6 +++--- src/backend/commands/tablecmds.c | 17 ++++------------- src/backend/replication/walsender.c | 6 +++--- src/backend/storage/file/buffile.c | 10 +++++----- src/backend/storage/freespace/freespace.c | 11 ++++------- src/bin/pg_basebackup/receivelog.c | 8 +++----- src/bin/pg_resetxlog/pg_resetxlog.c | 14 ++++++-------- src/bin/pg_rewind/copy_fetch.c | 6 +++--- src/include/c.h | 26 ++++++++++++++++++++++++++ 17 files changed, 90 insertions(+), 101 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid using potentially-under-aligned page buffers. @ 2018-09-01 19:27 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-09-01 19:27 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid using potentially-under-aligned page buffers. There's a project policy against using plain "char buf[BLCKSZ]" local or static variables as page buffers; preferred style is to palloc or malloc each buffer to ensure it is MAXALIGN'd. However, that policy's been ignored in an increasing number of places. We've apparently got away with it so far, probably because (a) relatively few people use platforms on which misalignment causes core dumps and/or (b) the variables chance to be sufficiently aligned anyway. But this is not something to rely on. Moreover, even if we don't get a core dump, we might be paying a lot of cycles for misaligned accesses. To fix, invent new union types PGAlignedBlock and PGAlignedXLogBlock that the compiler must allocate with sufficient alignment, and use those in place of plain char arrays. I used these types even for variables where there's no risk of a misaligned access, since ensuring proper alignment should make kernel data transfers faster. I also changed some places where we had been palloc'ing short-lived buffers, for coding style uniformity and to save palloc/pfree overhead. Since this seems to be a live portability hazard (despite the lack of field reports), back-patch to all supported versions. Patch by me; thanks to Michael Paquier for review. Discussion: https://postgr.es/m/1535618100.1286.3.camel@credativ.de Branch ------ REL9_4_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/083d9ced14e4af4b48e7607bd6cc7567a68ec899 Modified Files -------------- contrib/pg_prewarm/pg_prewarm.c | 4 ++-- src/backend/access/gin/ginentrypage.c | 10 +++++----- src/backend/access/gin/ginfast.c | 11 +++-------- src/backend/access/hash/hashpage.c | 6 +++--- src/backend/access/heap/heapam.c | 16 ++++------------ src/backend/access/heap/visibilitymap.c | 11 ++++------- src/backend/access/transam/xlog.c | 25 ++++++++++--------------- src/backend/commands/tablecmds.c | 17 ++++------------- src/backend/replication/walsender.c | 6 +++--- src/backend/storage/file/buffile.c | 10 +++++----- src/backend/storage/freespace/freespace.c | 11 ++++------- src/bin/pg_basebackup/receivelog.c | 8 +++----- src/bin/pg_resetxlog/pg_resetxlog.c | 14 ++++++-------- src/include/c.h | 26 ++++++++++++++++++++++++++ 14 files changed, 82 insertions(+), 93 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Avoid using potentially-under-aligned page buffers. @ 2018-09-01 19:27 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-09-01 19:27 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid using potentially-under-aligned page buffers. There's a project policy against using plain "char buf[BLCKSZ]" local or static variables as page buffers; preferred style is to palloc or malloc each buffer to ensure it is MAXALIGN'd. However, that policy's been ignored in an increasing number of places. We've apparently got away with it so far, probably because (a) relatively few people use platforms on which misalignment causes core dumps and/or (b) the variables chance to be sufficiently aligned anyway. But this is not something to rely on. Moreover, even if we don't get a core dump, we might be paying a lot of cycles for misaligned accesses. To fix, invent new union types PGAlignedBlock and PGAlignedXLogBlock that the compiler must allocate with sufficient alignment, and use those in place of plain char arrays. I used these types even for variables where there's no risk of a misaligned access, since ensuring proper alignment should make kernel data transfers faster. I also changed some places where we had been palloc'ing short-lived buffers, for coding style uniformity and to save palloc/pfree overhead. Since this seems to be a live portability hazard (despite the lack of field reports), back-patch to all supported versions. Patch by me; thanks to Michael Paquier for review. Discussion: https://postgr.es/m/1535618100.1286.3.camel@credativ.de Branch ------ REL9_3_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5af055ed74467f3a2c77d16179e1000b593e04e9 Modified Files -------------- src/backend/access/gin/ginentrypage.c | 8 ++++---- src/backend/access/gin/ginfast.c | 11 +++-------- src/backend/access/hash/hashpage.c | 6 +++--- src/backend/access/heap/heapam.c | 16 ++++------------ src/backend/access/heap/visibilitymap.c | 11 ++++------- src/backend/access/transam/xlog.c | 25 ++++++++++--------------- src/backend/commands/tablecmds.c | 17 ++++------------- src/backend/replication/walsender.c | 6 +++--- src/backend/storage/file/buffile.c | 10 +++++----- src/backend/storage/freespace/freespace.c | 11 ++++------- src/bin/pg_basebackup/receivelog.c | 8 +++----- src/bin/pg_resetxlog/pg_resetxlog.c | 14 ++++++-------- src/include/c.h | 26 ++++++++++++++++++++++++++ 13 files changed, 79 insertions(+), 90 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2018-09-01 19:27 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2018-09-01 19:27 pgsql: Avoid using potentially-under-aligned page buffers. Tom Lane <tgl@sss.pgh.pa.us> 2018-09-01 19:27 pgsql: Avoid using potentially-under-aligned page buffers. Tom Lane <tgl@sss.pgh.pa.us> 2018-09-01 19:27 pgsql: Avoid using potentially-under-aligned page buffers. Tom Lane <tgl@sss.pgh.pa.us> 2018-09-01 19:27 pgsql: Avoid using potentially-under-aligned page buffers. Tom Lane <tgl@sss.pgh.pa.us> 2018-09-01 19:27 pgsql: Avoid using potentially-under-aligned page buffers. Tom Lane <tgl@sss.pgh.pa.us> 2018-09-01 19:27 pgsql: Avoid using potentially-under-aligned page buffers. Tom Lane <tgl@sss.pgh.pa.us> 2018-09-01 19:27 pgsql: Avoid using potentially-under-aligned page buffers. Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox