Skip to content

Commit d2aecae

Browse files
committed
Modify dynamic shared memory code to use Size rather than uint64.
This is more consistent with what we do elsewhere.
1 parent c737a2e commit d2aecae

File tree

4 files changed

+35
-40
lines changed

4 files changed

+35
-40
lines changed

src/backend/storage/ipc/dsm.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct dsm_segment
6767
uint32 control_slot; /* Slot in control segment. */
6868
void *impl_private; /* Implementation-specific private data. */
6969
void *mapped_address; /* Mapping address, or NULL if unmapped. */
70-
uint64 mapped_size; /* Size of our mapping. */
70+
Size mapped_size; /* Size of our mapping. */
7171
};
7272

7373
/* Shared-memory state for a dynamic shared memory segment. */
@@ -94,7 +94,7 @@ static void dsm_postmaster_shutdown(int code, Datum arg);
9494
static void dsm_backend_shutdown(int code, Datum arg);
9595
static dsm_segment *dsm_create_descriptor(void);
9696
static bool dsm_control_segment_sane(dsm_control_header *control,
97-
uint64 mapped_size);
97+
Size mapped_size);
9898
static uint64 dsm_control_bytes_needed(uint32 nitems);
9999

100100
/* Has this backend initialized the dynamic shared memory system yet? */
@@ -128,7 +128,7 @@ static dlist_head dsm_segment_list = DLIST_STATIC_INIT(dsm_segment_list);
128128
*/
129129
static dsm_handle dsm_control_handle;
130130
static dsm_control_header *dsm_control;
131-
static uint64 dsm_control_mapped_size = 0;
131+
static Size dsm_control_mapped_size = 0;
132132
static void *dsm_control_impl_private = NULL;
133133

134134
/*
@@ -142,7 +142,7 @@ dsm_postmaster_startup(void)
142142
{
143143
void *dsm_control_address = NULL;
144144
uint32 maxitems;
145-
uint64 segsize;
145+
Size segsize;
146146

147147
Assert(!IsUnderPostmaster);
148148

@@ -214,8 +214,8 @@ dsm_cleanup_using_control_segment(void)
214214
void *junk_mapped_address = NULL;
215215
void *impl_private = NULL;
216216
void *junk_impl_private = NULL;
217-
uint64 mapped_size = 0;
218-
uint64 junk_mapped_size = 0;
217+
Size mapped_size = 0;
218+
Size junk_mapped_size = 0;
219219
uint32 nitems;
220220
uint32 i;
221221
dsm_handle old_control_handle;
@@ -453,7 +453,7 @@ dsm_postmaster_shutdown(int code, Datum arg)
453453
void *dsm_control_address;
454454
void *junk_mapped_address = NULL;
455455
void *junk_impl_private = NULL;
456-
uint64 junk_mapped_size = 0;
456+
Size junk_mapped_size = 0;
457457

458458
/*
459459
* If some other backend exited uncleanly, it might have corrupted the
@@ -562,7 +562,7 @@ dsm_backend_startup(void)
562562
* Create a new dynamic shared memory segment.
563563
*/
564564
dsm_segment *
565-
dsm_create(uint64 size)
565+
dsm_create(Size size)
566566
{
567567
dsm_segment *seg = dsm_create_descriptor();
568568
uint32 i;
@@ -733,7 +733,7 @@ dsm_backend_shutdown(int code, Datum arg)
733733
* address. For the caller's convenience, we return the mapped address.
734734
*/
735735
void *
736-
dsm_resize(dsm_segment *seg, uint64 size)
736+
dsm_resize(dsm_segment *seg, Size size)
737737
{
738738
Assert(seg->control_slot != INVALID_CONTROL_SLOT);
739739
dsm_impl_op(DSM_OP_RESIZE, seg->handle, size, &seg->impl_private,
@@ -887,7 +887,7 @@ dsm_segment_address(dsm_segment *seg)
887887
/*
888888
* Get the size of a mapping.
889889
*/
890-
uint64
890+
Size
891891
dsm_segment_map_length(dsm_segment *seg)
892892
{
893893
Assert(seg->mapped_address != NULL);
@@ -947,7 +947,7 @@ dsm_create_descriptor(void)
947947
* our segments at all.
948948
*/
949949
static bool
950-
dsm_control_segment_sane(dsm_control_header *control, uint64 mapped_size)
950+
dsm_control_segment_sane(dsm_control_header *control, Size mapped_size)
951951
{
952952
if (mapped_size < offsetof(dsm_control_header, item))
953953
return false; /* Mapped size too short to read header. */

src/backend/storage/ipc/dsm_impl.c

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,24 @@
6969
#include "utils/memutils.h"
7070

7171
#ifdef USE_DSM_POSIX
72-
static bool dsm_impl_posix(dsm_op op, dsm_handle handle, uint64 request_size,
72+
static bool dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
7373
void **impl_private, void **mapped_address,
74-
uint64 *mapped_size, int elevel);
74+
Size *mapped_size, int elevel);
7575
#endif
7676
#ifdef USE_DSM_SYSV
77-
static bool dsm_impl_sysv(dsm_op op, dsm_handle handle, uint64 request_size,
77+
static bool dsm_impl_sysv(dsm_op op, dsm_handle handle, Size request_size,
7878
void **impl_private, void **mapped_address,
79-
uint64 *mapped_size, int elevel);
79+
Size *mapped_size, int elevel);
8080
#endif
8181
#ifdef USE_DSM_WINDOWS
82-
static bool dsm_impl_windows(dsm_op op, dsm_handle handle, uint64 request_size,
82+
static bool dsm_impl_windows(dsm_op op, dsm_handle handle, Size request_size,
8383
void **impl_private, void **mapped_address,
84-
uint64 *mapped_size, int elevel);
84+
Size *mapped_size, int elevel);
8585
#endif
8686
#ifdef USE_DSM_MMAP
87-
static bool dsm_impl_mmap(dsm_op op, dsm_handle handle, uint64 request_size,
87+
static bool dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
8888
void **impl_private, void **mapped_address,
89-
uint64 *mapped_size, int elevel);
89+
Size *mapped_size, int elevel);
9090
#endif
9191
static int errcode_for_dynamic_shared_memory(void);
9292

@@ -156,19 +156,14 @@ int dynamic_shared_memory_type;
156156
*-----
157157
*/
158158
bool
159-
dsm_impl_op(dsm_op op, dsm_handle handle, uint64 request_size,
160-
void **impl_private, void **mapped_address, uint64 *mapped_size,
159+
dsm_impl_op(dsm_op op, dsm_handle handle, Size request_size,
160+
void **impl_private, void **mapped_address, Size *mapped_size,
161161
int elevel)
162162
{
163163
Assert(op == DSM_OP_CREATE || op == DSM_OP_RESIZE || request_size == 0);
164164
Assert((op != DSM_OP_CREATE && op != DSM_OP_ATTACH) ||
165165
(*mapped_address == NULL && *mapped_size == 0));
166166

167-
if (request_size > (size_t) -1)
168-
ereport(ERROR,
169-
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
170-
errmsg("requested shared memory size overflows size_t")));
171-
172167
switch (dynamic_shared_memory_type)
173168
{
174169
#ifdef USE_DSM_POSIX
@@ -241,8 +236,8 @@ dsm_impl_can_resize(void)
241236
* a different shared memory implementation.
242237
*/
243238
static bool
244-
dsm_impl_posix(dsm_op op, dsm_handle handle, uint64 request_size,
245-
void **impl_private, void **mapped_address, uint64 *mapped_size,
239+
dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
240+
void **impl_private, void **mapped_address, Size *mapped_size,
246241
int elevel)
247242
{
248243
char name[64];
@@ -407,8 +402,8 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, uint64 request_size,
407402
* those are not supported everywhere.
408403
*/
409404
static bool
410-
dsm_impl_sysv(dsm_op op, dsm_handle handle, uint64 request_size,
411-
void **impl_private, void **mapped_address, uint64 *mapped_size,
405+
dsm_impl_sysv(dsm_op op, dsm_handle handle, Size request_size,
406+
void **impl_private, void **mapped_address, Size *mapped_size,
412407
int elevel)
413408
{
414409
key_t key;
@@ -612,9 +607,9 @@ dsm_impl_sysv(dsm_op op, dsm_handle handle, uint64 request_size,
612607
* when the process containing the reference exits.
613608
*/
614609
static bool
615-
dsm_impl_windows(dsm_op op, dsm_handle handle, uint64 request_size,
610+
dsm_impl_windows(dsm_op op, dsm_handle handle, Size request_size,
616611
void **impl_private, void **mapped_address,
617-
uint64 *mapped_size, int elevel)
612+
Size *mapped_size, int elevel)
618613
{
619614
char *address;
620615
HANDLE hmap;
@@ -780,8 +775,8 @@ dsm_impl_windows(dsm_op op, dsm_handle handle, uint64 request_size,
780775
* directory to a ramdisk to avoid this problem, if available.
781776
*/
782777
static bool
783-
dsm_impl_mmap(dsm_op op, dsm_handle handle, uint64 request_size,
784-
void **impl_private, void **mapped_address, uint64 *mapped_size,
778+
dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
779+
void **impl_private, void **mapped_address, Size *mapped_size,
785780
int elevel)
786781
{
787782
char name[64];
@@ -892,7 +887,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, uint64 request_size,
892887
*/
893888
while (success && remaining > 0)
894889
{
895-
uint64 goal = remaining;
890+
Size goal = remaining;
896891

897892
if (goal > ZBUFFER_SIZE)
898893
goal = ZBUFFER_SIZE;

src/include/storage/dsm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ typedef struct dsm_segment dsm_segment;
2121
extern void dsm_postmaster_startup(void);
2222

2323
/* Functions that create, update, or remove mappings. */
24-
extern dsm_segment *dsm_create(uint64 size);
24+
extern dsm_segment *dsm_create(Size size);
2525
extern dsm_segment *dsm_attach(dsm_handle h);
26-
extern void *dsm_resize(dsm_segment *seg, uint64 size);
26+
extern void *dsm_resize(dsm_segment *seg, Size size);
2727
extern void *dsm_remap(dsm_segment *seg);
2828
extern void dsm_detach(dsm_segment *seg);
2929

@@ -33,7 +33,7 @@ extern dsm_segment *dsm_find_mapping(dsm_handle h);
3333

3434
/* Informational functions. */
3535
extern void *dsm_segment_address(dsm_segment *seg);
36-
extern uint64 dsm_segment_map_length(dsm_segment *seg);
36+
extern Size dsm_segment_map_length(dsm_segment *seg);
3737
extern dsm_handle dsm_segment_handle(dsm_segment *seg);
3838

3939
#endif /* DSM_H */

src/include/storage/dsm_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ typedef enum
6565
} dsm_op;
6666

6767
/* Create, attach to, detach from, resize, or destroy a segment. */
68-
extern bool dsm_impl_op(dsm_op op, dsm_handle handle, uint64 request_size,
69-
void **impl_private, void **mapped_address, uint64 *mapped_size,
68+
extern bool dsm_impl_op(dsm_op op, dsm_handle handle, Size request_size,
69+
void **impl_private, void **mapped_address, Size *mapped_size,
7070
int elevel);
7171

7272
/* Some implementations cannot resize segments. Can this one? */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy