Re: Reducing the chunk header sizes on all memory context types

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Amit Kapila <amit.kapila16@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>, Andres Freund <andres@anarazel.de>, Robert Haas <robertmhaas@gmail.com>, Yura Sokolov <y.sokolov@postgrespro.ru>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2022-08-29T14:55:42Z
Lists: pgsql-hackers
Amit Kapila <amit.kapila16@gmail.com> writes:
> Yeah, I also thought that way but couldn't find a reason. I think if
> David is able to reproduce it on one of his systems then he can try
> locally reverting both the commits one by one.

It seems to repro easily on any 32-bit platform.  Aside from the
buildfarm results, I've now duplicated it on 32-bit ARM (which
eliminates the possibility that it's big-endian specific).

"bt full" from the first crash gives

#0  0xb6d7126c in raise () from /lib/libc.so.6
No symbol table info available.
#1  0xb6d5c360 in abort () from /lib/libc.so.6
No symbol table info available.
#2  0x00572430 in ExceptionalCondition (
    conditionName=conditionName@entry=0x745110 "pointer == (void *) MAXALIGN(pointer)", errorType=errorType@entry=0x5d18d0 "FailedAssertion", 
    fileName=fileName@entry=0x7450dc "../../../../src/include/utils/memutils_internal.h", lineNumber=lineNumber@entry=120) at assert.c:69
No locals.
#3  0x005a0d90 in GetMemoryChunkMethodID (pointer=<optimized out>)
    at ../../../../src/include/utils/memutils_internal.h:120
        header = <optimized out>
#4  0x005a231c in GetMemoryChunkMethodID (pointer=<optimized out>)
    at ../../../../src/include/utils/memutils_internal.h:119
        header = <optimized out>
        header = <optimized out>
#5  pfree (pointer=<optimized out>) at mcxt.c:1242
No locals.
#6  0x003c8fdc in ReorderBufferCleanupTXN (rb=0x7450dc, rb@entry=0x1f, 
    txn=0x745110, txn@entry=0xe1f800) at reorderbuffer.c:1493
        change = <optimized out>
        found = false
        iter = {cur = <optimized out>, next = 0xddcb18, end = 0xde4e64}
#7  0x003ca968 in ReorderBufferProcessTXN (rb=0x1f, rb@entry=0xe1f800, 
    txn=0xe1f800, commit_lsn=<optimized out>, snapshot_now=<optimized out>, 
    command_id=<optimized out>, streaming=false) at reorderbuffer.c:2514
        change = 0x0
        _save_exception_stack = 0x0
        _save_context_stack = 0x1
        _local_sigjmp_buf = {{__jmpbuf = {-552117431, 1640676937, -1092521468, 
              14569068, 14569068, 14568932, 729, 0, 228514434, 166497, 0, 
              8195960, 8196088, 7, 0 <repeats 13 times>, 13847224, 0, 196628, 
              0, 1844909312, 5178548, -1092520644, 13979392, 13979388, 
              14801472, 0, 8195960, 8196088, 7, 0, 8108342, 8108468, 1, 
              715827883, -1030792151, 0, 8195960, 729, 7, 0, 14809088, 
              14809088, 14542436, 0, 26303888, 0, 14568932, 3978796, 156, 0, 
              1, 0}, __mask_was_saved = 0, __saved_mask = {__val = {64, 
                7242472, 14740696, 7244624, 14809088, 14741512, 5, 14740696, 
                7244624, 7245864, 3982844, 14542436, 0, 14809092, 0, 26303888, 
                729, 14569112, 14809092, 7242472, 729, 14741512, 32, 14809088, 
                0, 228514434, 166497, 0, 0, 26303888, 3980968, 0}}}}
        _do_rethrow = <optimized out>
        using_subtxn = 228
        ccxt = 0x7aae68 <my_wait_event_info>
        iterstate = 0x0
        prev_lsn = 26303888
        specinsert = 0x0
        stream_started = false
        curtxn = 0x0
        __func__ = "ReorderBufferProcessTXN"
#8  0x003cb460 in ReorderBufferReplay (txn=<optimized out>, 
    rb=rb@entry=0xe1f800, commit_lsn=<optimized out>, end_lsn=<optimized out>, 
    commit_time=715099169882112, origin_id=0, origin_lsn=0, xid=729)
    at reorderbuffer.c:2641
        snapshot_now = <optimized out>
#9  0x003cbedc in ReorderBufferCommit (rb=rb@entry=0xe1f800, 
    xid=xid@entry=729, commit_lsn=<optimized out>, end_lsn=<optimized out>, 
    commit_time=<optimized out>, commit_time@entry=715099398396546, 
    origin_id=<optimized out>, origin_id@entry=0, origin_lsn=0, 
    origin_lsn@entry=5906902891454464) at reorderbuffer.c:2665
        txn = <optimized out>
#10 0x003bb19c in DecodeCommit (two_phase=false, xid=729, parsed=0xbee17478, 
    buf=<optimized out>, ctx=0xe1d7f8) at decode.c:682
        origin_lsn = <optimized out>
        commit_time = <optimized out>
        origin_id = 0
        i = <optimized out>
        origin_lsn = <optimized out>
        commit_time = <optimized out>
        origin_id = <optimized out>
        i = <optimized out>
#11 xact_decode (ctx=0xe1d7f8, buf=<optimized out>) at decode.c:216
        xlrec = <optimized out>
        parsed = {xact_time = 715099398396546, xinfo = 73, dbId = 16384, 
          tsId = 1663, nsubxacts = 0, subxacts = 0x0, nrels = 0, 
          xlocators = 0x0, nstats = 0, stats = 0x0, nmsgs = 70, 
          msgs = 0xe2b828, twophase_xid = 0, 
          twophase_gid = '\000' <repeats 199 times>, nabortrels = 0, 
          abortlocators = 0x0, nabortstats = 0, abortstats = 0x0, 
          origin_lsn = 0, origin_timestamp = 0}
        xid = <optimized out>
        two_phase = false
        builder = <optimized out>
        reorder = <optimized out>
        r = <optimized out>
        info = <optimized out>
        __func__ = "xact_decode"
#12 0x003babf0 in LogicalDecodingProcessRecord (ctx=ctx@entry=0xe1d7f8, 
    record=0xe1dad0) at decode.c:119
        buf = {origptr = 26303888, endptr = 26305088, record = 0xe1dad0}
        txid = <optimized out>
        rmgr = <optimized out>
#13 0x003c0390 in pg_logical_slot_get_changes_guts (fcinfo=0x0, 
    confirm=<optimized out>, binary=<optimized out>) at logicalfuncs.c:271
        record = <optimized out>
        errm = 0x0
        _save_exception_stack = 0xd60380
        _save_context_stack = 0x1
        _local_sigjmp_buf = {{__jmpbuf = {-552117223, 1640638557, 4, 14770368, 
              -1092519792, -1, 14770320, 8, 1, 14691520, 0, 8195960, 8196088, 
              7, 0 <repeats 12 times>, 3398864, 0, 13849464, 13848680, 
              14650600, 3399100, 4, 3125412, 0, 144, 0, 0, 8192, 7616300, 0, 
              1576, 7616452, 14585296, 8192, 7616300, 14651128, 0, 0, 
              14651128, -1092519880, 3398864, 0, 13849464, 13848680, 3399100, 
              0, 5904972, 8112272, -1, 14591624, -1375937000, -1375937248, 
              14591376}, __mask_was_saved = 0, __saved_mask = {__val = {
                14530312, 14528852, 2348328335, 14527224, 5699140, 3202447388, 
                4, 14527080, 5699156, 14530312, 5769228, 2918792552, 0, 0, 0, 
                14767888, 3067834868, 14591600, 13824008, 1023, 3068719720, 1, 
                184, 14589688, 14586024, 14587400, 14691504, 14586024, 
                14585752, 14586200, 2615480, 8112268}}}}
        _do_rethrow = <optimized out>
        name = 0xe16090
        upto_lsn = 3933972
        upto_nchanges = 14707744
        rsinfo = <optimized out>
        per_query_ctx = <optimized out>
        oldcontext = 0xe06cc0
        end_of_wal = 0
        ctx = 0xe1d7f8
        old_resowner = 0xd35568
        arr = <optimized out>
        ndim = <optimized out>
        options = 0x0
        p = 0xe02cb0
        __func__ = "pg_logical_slot_get_changes_guts"
#14 0x00292864 in ExecMakeTableFunctionResult (setexpr=0xdea9b0, 
    econtext=0xde90a8, argContext=<optimized out>, expectedDesc=0x1, 
    randomAccess=false) at execSRF.c:234
        result = 2590380
        tupstore = 0x0
        tupdesc = 0x0
        funcrettype = 8040208
        returnsTuple = <optimized out>
        returnsSet = 32
        fcinfo = 0xe02cb0
        fcusage = {fs = 0x0, save_f_total_time = {tv_sec = 14592432, 
            tv_nsec = 7093408}, save_total = {tv_sec = 0, tv_nsec = 0}, 
          f_start = {tv_sec = 14767936, tv_nsec = 14767940}}
        rsinfo = {type = T_ReturnSetInfo, econtext = 0xde90a8, 
          expectedDesc = 0xdea7a0, allowedModes = 11, 
          returnMode = SFRM_Materialize, isDone = ExprSingleResult, 
          setResult = 0xe16548, setDesc = 0xe16338}
        tmptup = {t_len = 3, t_self = {ip_blkid = {bi_hi = 0, bi_lo = 0}, 
            ip_posid = 0}, t_tableOid = 0, t_data = 0x3}
        callerContext = 0xdea7a0
        first_time = true
        __func__ = "ExecMakeTableFunctionResult"
... etc ...

Anything ring a bell?

			regards, tom lane



Commits

  1. Harden memory context allocators against bogus chunk pointers.

  2. Improve our ability to detect bogus pointers passed to pfree et al.

  3. Remove MemoryContextContains().

  4. Remove uses of MemoryContextContains in nodeAgg.c and nodeWindowAgg.c.

  5. Temporarily make MemoryContextContains return false

  6. Make MemoryContextContains work correctly again

  7. Make more effort to put a sentinel at the end of allocated memory

  8. Fix some possibly latent bugs in slab.c

  9. Various cleanups of the new memory context header code

  10. Revert "Add missing padding from MemoryChunk struct"

  11. Use MAXALIGN() in calculations using sizeof(SlabBlock)

  12. Add missing padding from MemoryChunk struct

  13. Improve performance of and reduce overheads of memory management