8000 Fix more DSA problems uncovered by the buildfarm. · postgrespro/postgres@88f626f · GitHub
[go: up one dir, main page]

Skip to content
  • Commit 88f626f

    Browse files
    committed
    Fix more DSA problems uncovered by the buildfarm.
    On 32-bit systems, don't try to use 64-bit DSA pointers, because the computation of DSA_MAX_SEGMENT_SIZE overflows Size. Cast 1 to Size before shifting it, so that the compiler doesn't produce a result of the wrong width. In passing, change one use of size_t to Size.
    1 parent 670b3bc commit 88f626f

    File tree

    2 files changed

    +16
    -11
    lines changed

    2 files changed

    +16
    -11
    lines changed

    src/backend/utils/mmgr/dsa.c

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -98,7 +98,7 @@
    9898
    #define DSA_OFFSET_BITMASK (((dsa_pointer) 1 << DSA_OFFSET_WIDTH) - 1)
    9999

    100100
    /* The maximum size of a DSM segment. */
    101-
    #define DSA_MAX_SEGMENT_SIZE ((size_t) 1 << DSA_OFFSET_WIDTH)
    101+
    #define DSA_MAX_SEGMENT_SIZE ((Size) 1 << DSA_OFFSET_WIDTH)
    102102

    103103
    /* Number of pages (see FPM_PAGE_SIZE) per regular superblock. */
    104104
    #define DSA_PAGES_PER_SUPERBLOCK 16
    @@ -1919,7 +1919,7 @@ get_best_segment(dsa_area *area, Size npages)
    19191919
    * The minimum contiguous size that any segment in this bin should
    19201920
    * have. We'll re-bin if we see segments with fewer.
    19211921
    */
    1922-
    Size threshold = 1 << (bin - 1);
    1922+
    Size threshold = (Size) 1 << (bin - 1);
    19231923
    dsa_segment_index segment_index;
    19241924

    19251925
    /* Search this bin for a segment with enough contiguous space. */

    src/include/utils/dsa.h

    Lines changed: 14 additions & 9 deletions
    Original file line numberDiff line numberDiff line change
    @@ -24,20 +24,25 @@ struct dsa_area;
    2424
    typedef struct dsa_area dsa_area;
    2525

    2626
    /*
    27-
    * If this system doesn't support atomic operations on 64 bit values then
    28-
    * we fall back to 32 bit dsa_pointer. For testing purposes,
    29-
    * USE_SMALL_DSA_POINTER can be defined to force the use of 32 bit
    30-
    * dsa_pointer even on systems that support 64 bit atomics.
    27+
    * If this system only uses a 32-bit value for Size, then use the 32-bit
    28+
    * implementation of DSA. This limits the amount of DSA that can be created
    29+
    * to something significantly less than the entire 4GB address space because
    30+
    * the DSA pointer must encode both a segment identifier and an offset, but
    31+
    * that shouldn't be a significant limitation in practice.
    32+
    *
    33+
    * If this system doesn't support atomic operations on 64-bit values, then
    34+
    * we fall back to 32-bit dsa_pointer for lack of other options.
    35+
    *
    36+
    * For testing purposes, USE_SMALL_DSA_POINTER can be defined to force the use
    37+
    * of 32-bit dsa_pointer even on systems capable of supporting a 64-bit
    38+
    * dsa_pointer.
    3139
    */
    32-
    #ifndef PG_HAVE_ATOMIC_U64_SUPPORT
    33-
    #define SIZEOF_DSA_POINTER 4
    34-
    #else
    35-
    #ifdef USE_SMALL_DSA_POINTER
    40+
    #if SIZEOF_SIZE_T == 4 || !defined(PG_HAVE_ATOMIC_U64_SUPPORT) || \
    41+
    defined(USE_SMALL_DSA_POINTER)
    3642
    #define SIZEOF_DSA_POINTER 4
    3743
    #else
    3844
    #define SIZEOF_DSA_POINTER 8
    3945
    #endif
    40-
    #endif
    4146

    4247
    /*
    4348
    * The type of 'relative pointers' to memory allocated by a dynamic shared

    0 commit comments

    Comments
     (0)
    0