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

Commit88f626f

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 thecomputation of DSA_MAX_SEGMENT_SIZE overflows Size.Cast 1 to Size before shifting it, so that the compiler doesn'tproduce a result of the wrong width.In passing, change one use of size_t to Size.
1 parent670b3bc commit88f626f

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
#defineDSA_OFFSET_BITMASK (((dsa_pointer) 1 << DSA_OFFSET_WIDTH) - 1)
9999

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

103103
/* Number of pages (see FPM_PAGE_SIZE) per regular superblock. */
104104
#defineDSA_PAGES_PER_SUPERBLOCK16
@@ -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-
Sizethreshold=1 << (bin-1);
1922+
Sizethreshold=(Size)1 << (bin-1);
19231923
dsa_segment_indexsegment_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
typedefstructdsa_areadsa_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-
#ifndefPG_HAVE_ATOMIC_U64_SUPPORT
33-
#defineSIZEOF_DSA_POINTER 4
34-
#else
35-
#ifdefUSE_SMALL_DSA_POINTER
40+
#ifSIZEOF_SIZE_T==4|| !defined(PG_HAVE_ATOMIC_U64_SUPPORT)|| \
41+
defined(USE_SMALL_DSA_POINTER)
3642
#defineSIZEOF_DSA_POINTER 4
3743
#else
3844
#defineSIZEOF_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)

[8]ページ先頭

©2009-2025 Movatter.jp