Skip to content

Commit eb7d814

Browse files
authored
Create 20240330_04.md
1 parent 52f69ba commit eb7d814

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

202403/20240330_04.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
## PostgreSQL 17 preview - 支持在申请时指定动态共享内存区域初始、最大段size
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2024-03-30
8+
9+
### 标签
10+
PostgreSQL , PolarDB , DuckDB , dsa , DSA_DEFAULT_INIT_SEGMENT_SIZE , DSA_MIN_SEGMENT_SIZE , DSA_MAX_SEGMENT_SIZE
11+
12+
----
13+
14+
## 背景
15+
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=bb952c8c8b13279eca039499249cb5dc60991603
16+
```
17+
Allow specifying initial and maximum segment sizes for DSA.
18+
19+
author Masahiko Sawada <[email protected]>
20+
Wed, 27 Mar 2024 02:43:29 +0000 (11:43 +0900)
21+
committer Masahiko Sawada <[email protected]>
22+
Wed, 27 Mar 2024 02:43:29 +0000 (11:43 +0900)
23+
commit bb952c8c8b13279eca039499249cb5dc60991603
24+
tree ba7cc3ced86501cb0da23a66b9170ffae19dcf6c tree
25+
parent 1f42337be535243e665f85916ce21b2d85d9f2b3 commit | diff
26+
Allow specifying initial and maximum segment sizes for DSA.
27+
28+
Previously, the DSA segment size always started with 1MB and grew up
29+
to DSA_MAX_SEGMENT_SIZE. It was inconvenient in certain scenarios,
30+
such as when the caller desired a soft constraint on the total DSA
31+
segment size, limiting it to less than 1MB.
32+
33+
This commit introduces the capability to specify the initial and
34+
maximum DSA segment sizes when creating a DSA area, providing more
35+
flexibility and control over memory usage.
36+
37+
Reviewed-by: John Naylor, Tomas Vondra
38+
Discussion: https://postgr.es/m/CAD21AoAYGGC1ePjVX0H%2Bpp9rH%3D9vuPK19nNOiu12NprdV5TVJA%40mail.gmail.com
39+
```
40+
41+
```
42+
+/*
43+
+ * The number of bits used to represent the offset part of a dsa_pointer.
44+
+ * This controls the maximum size of a segment, the maximum possible
45+
+ * allocation size and also the maximum number of segments per area.
46+
+ */
47+
+#if SIZEOF_DSA_POINTER == 4
48+
+#define DSA_OFFSET_WIDTH 27 /* 32 segments of size up to 128MB */
49+
+#else
50+
+#define DSA_OFFSET_WIDTH 40 /* 1024 segments of size up to 1TB */
51+
+#endif
52+
+
53+
+/*
54+
+ * The default size of the initial DSM segment that backs a dsa_area created
55+
+ * by dsa_create. After creating some number of segments of the initial size
56+
+ * we'll double this size, and so on. Larger segments may be created if
57+
+ * necessary to satisfy large requests.
58+
+ */
59+
+#define DSA_DEFAULT_INIT_SEGMENT_SIZE ((size_t) (1 * 1024 * 1024))
60+
+
61+
+/* The minimum size of a DSM segment. */
62+
+#define DSA_MIN_SEGMENT_SIZE ((size_t) (256 * 1024L))
63+
+
64+
+/* The maximum size of a DSM segment. */
65+
+#define DSA_MAX_SEGMENT_SIZE ((size_t) 1 << DSA_OFFSET_WIDTH)
66+
67+
+/* Create dsa_area with default segment sizes */
68+
+#define dsa_create(tranch_id) \
69+
+ dsa_create_ext(tranch_id, DSA_DEFAULT_INIT_SEGMENT_SIZE, \
70+
+ DSA_MAX_SEGMENT_SIZE)
71+
+
72+
+/* Create dsa_area with default segment sizes in an existing share memory space */
73+
+#define dsa_create_in_place(place, size, tranch_id, segment) \
74+
+ dsa_create_in_place_ext(place, size, tranch_id, segment, \
75+
+ DSA_DEFAULT_INIT_SEGMENT_SIZE, \
76+
+ DSA_MAX_SEGMENT_SIZE)
77+
+
78+
```
79+

0 commit comments

Comments
 (0)