When I wrote the dynamic shared memory patch, I used uint64 everywhere
to measure sizes - rather than, as we do for the main shared memory
segment, Size.  This now seems to me to have been the wrong decision;
I'm finding that it's advantageous to make dynamic shared memory
behave as much like the main shared memory segment as is reasonably
possible, and using Size facilitates the use of MAXALIGN(),
TYPEALIGN(), etc. as well as things like add_size() and mul_size()
which are just as relevant in the dynamic shared memory case as they
are for the main shared memory segment.

Therefore, I propose to apply the attached patch.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c
index e516197..4d7fb08 100644
--- a/src/backend/storage/ipc/dsm.c
+++ b/src/backend/storage/ipc/dsm.c
@@ -67,7 +67,7 @@ struct dsm_segment
 	uint32		control_slot;		/* Slot in control segment. */
 	void       *impl_private;		/* Implementation-specific private data. */
 	void	   *mapped_address;		/* Mapping address, or NULL if unmapped. */
-	uint64		mapped_size;		/* Size of our mapping. */
+	Size		mapped_size;		/* Size of our mapping. */
 };
 
 /* Shared-memory state for a dynamic shared memory segment. */
@@ -94,7 +94,7 @@ static void dsm_postmaster_shutdown(int code, Datum arg);
 static void dsm_backend_shutdown(int code, Datum arg);
 static dsm_segment *dsm_create_descriptor(void);
 static bool dsm_control_segment_sane(dsm_control_header *control,
-						 uint64 mapped_size);
+						 Size mapped_size);
 static uint64 dsm_control_bytes_needed(uint32 nitems);
 
 /* 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);
  */
 static dsm_handle dsm_control_handle;
 static dsm_control_header *dsm_control;
-static uint64 dsm_control_mapped_size = 0;
+static Size dsm_control_mapped_size = 0;
 static void	*dsm_control_impl_private = NULL;
 
 /*
@@ -142,7 +142,7 @@ dsm_postmaster_startup(void)
 {
 	void	   *dsm_control_address = NULL;
 	uint32		maxitems;
-	uint64		segsize;
+	Size		segsize;
 
 	Assert(!IsUnderPostmaster);
 
@@ -214,8 +214,8 @@ dsm_cleanup_using_control_segment(void)
 	void	   *junk_mapped_address = NULL;
 	void	   *impl_private = NULL;
 	void	   *junk_impl_private = NULL;
-	uint64		mapped_size = 0;
-	uint64		junk_mapped_size = 0;
+	Size		mapped_size = 0;
+	Size		junk_mapped_size = 0;
 	uint32		nitems;
 	uint32		i;
 	dsm_handle	old_control_handle;
@@ -453,7 +453,7 @@ dsm_postmaster_shutdown(int code, Datum arg)
 	void	   *dsm_control_address;
 	void	   *junk_mapped_address = NULL;
 	void	   *junk_impl_private = NULL;
-	uint64		junk_mapped_size = 0;
+	Size		junk_mapped_size = 0;
 
 	/*
 	 * If some other backend exited uncleanly, it might have corrupted the
@@ -562,7 +562,7 @@ dsm_backend_startup(void)
  * Create a new dynamic shared memory segment.
  */
 dsm_segment *
-dsm_create(uint64 size)
+dsm_create(Size size)
 {
 	dsm_segment	   *seg = dsm_create_descriptor();
 	uint32			i;
@@ -733,7 +733,7 @@ dsm_backend_shutdown(int code, Datum arg)
  * address.  For the caller's convenience, we return the mapped address.
  */
 void *
-dsm_resize(dsm_segment *seg, uint64 size)
+dsm_resize(dsm_segment *seg, Size size)
 {
 	Assert(seg->control_slot != INVALID_CONTROL_SLOT);
 	dsm_impl_op(DSM_OP_RESIZE, seg->handle, size, &seg->impl_private,
@@ -887,7 +887,7 @@ dsm_segment_address(dsm_segment *seg)
 /*
  * Get the size of a mapping.
  */
-uint64
+Size
 dsm_segment_map_length(dsm_segment *seg)
 {
 	Assert(seg->mapped_address != NULL);
@@ -947,7 +947,7 @@ dsm_create_descriptor(void)
  * our segments at all.
  */
 static bool
-dsm_control_segment_sane(dsm_control_header *control, uint64 mapped_size)
+dsm_control_segment_sane(dsm_control_header *control, Size mapped_size)
 {
 	if (mapped_size < offsetof(dsm_control_header, item))
 		return false;			/* Mapped size too short to read header. */
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index 627f00b..2056668 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -69,24 +69,24 @@
 #include "utils/memutils.h"
 
 #ifdef USE_DSM_POSIX
-static bool dsm_impl_posix(dsm_op op, dsm_handle handle, uint64 request_size,
+static bool dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
 			   void **impl_private, void **mapped_address,
-			   uint64 *mapped_size, int elevel);
+			   Size *mapped_size, int elevel);
 #endif
 #ifdef USE_DSM_SYSV
-static bool dsm_impl_sysv(dsm_op op, dsm_handle handle, uint64 request_size,
+static bool dsm_impl_sysv(dsm_op op, dsm_handle handle, Size request_size,
 			   void **impl_private, void **mapped_address,
-			   uint64 *mapped_size, int elevel);
+			   Size *mapped_size, int elevel);
 #endif
 #ifdef USE_DSM_WINDOWS
-static bool dsm_impl_windows(dsm_op op, dsm_handle handle, uint64 request_size,
+static bool dsm_impl_windows(dsm_op op, dsm_handle handle, Size request_size,
 			  void **impl_private, void **mapped_address,
-			  uint64 *mapped_size, int elevel);
+			  Size *mapped_size, int elevel);
 #endif
 #ifdef USE_DSM_MMAP
-static bool dsm_impl_mmap(dsm_op op, dsm_handle handle, uint64 request_size,
+static bool dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
 			  void **impl_private, void **mapped_address,
-			  uint64 *mapped_size, int elevel);
+			  Size *mapped_size, int elevel);
 #endif
 static int errcode_for_dynamic_shared_memory(void);
 
@@ -156,19 +156,14 @@ int dynamic_shared_memory_type;
  *-----
  */
 bool
-dsm_impl_op(dsm_op op, dsm_handle handle, uint64 request_size,
-			void **impl_private, void **mapped_address, uint64 *mapped_size,
+dsm_impl_op(dsm_op op, dsm_handle handle, Size request_size,
+			void **impl_private, void **mapped_address, Size *mapped_size,
 			int elevel)
 {
 	Assert(op == DSM_OP_CREATE || op == DSM_OP_RESIZE || request_size == 0);
 	Assert((op != DSM_OP_CREATE && op != DSM_OP_ATTACH) ||
 			(*mapped_address == NULL && *mapped_size == 0));
 
-	if (request_size > (size_t) -1)
-		ereport(ERROR,
-				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-				 errmsg("requested shared memory size overflows size_t")));
-
 	switch (dynamic_shared_memory_type)
 	{
 #ifdef USE_DSM_POSIX
@@ -241,8 +236,8 @@ dsm_impl_can_resize(void)
  * a different shared memory implementation.
  */
 static bool
-dsm_impl_posix(dsm_op op, dsm_handle handle, uint64 request_size,
-			   void **impl_private, void **mapped_address, uint64 *mapped_size,
+dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
+			   void **impl_private, void **mapped_address, Size *mapped_size,
 			   int elevel)
 {
 	char	name[64];
@@ -407,8 +402,8 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, uint64 request_size,
  * those are not supported everywhere.
  */
 static bool
-dsm_impl_sysv(dsm_op op, dsm_handle handle, uint64 request_size,
-			  void **impl_private, void **mapped_address, uint64 *mapped_size,
+dsm_impl_sysv(dsm_op op, dsm_handle handle, Size request_size,
+			  void **impl_private, void **mapped_address, Size *mapped_size,
 			  int elevel)
 {
 	key_t	key;
@@ -612,9 +607,9 @@ dsm_impl_sysv(dsm_op op, dsm_handle handle, uint64 request_size,
  * when the process containing the reference exits.
  */
 static bool
-dsm_impl_windows(dsm_op op, dsm_handle handle, uint64 request_size,
+dsm_impl_windows(dsm_op op, dsm_handle handle, Size request_size,
 				 void **impl_private, void **mapped_address,
-				 uint64 *mapped_size, int elevel)
+				 Size *mapped_size, int elevel)
 {
 	char   *address;
 	HANDLE		hmap;
@@ -780,8 +775,8 @@ dsm_impl_windows(dsm_op op, dsm_handle handle, uint64 request_size,
  * directory to a ramdisk to avoid this problem, if available.
  */
 static bool
-dsm_impl_mmap(dsm_op op, dsm_handle handle, uint64 request_size,
-			  void **impl_private, void **mapped_address, uint64 *mapped_size,
+dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
+			  void **impl_private, void **mapped_address, Size *mapped_size,
 			  int elevel)
 {
 	char	name[64];
@@ -892,7 +887,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, uint64 request_size,
 		 */
 		while (success && remaining > 0)
 		{
-			uint64	goal = remaining;
+			Size	goal = remaining;
 
 			if (goal > ZBUFFER_SIZE)
 				goal = ZBUFFER_SIZE;
diff --git a/src/include/storage/dsm.h b/src/include/storage/dsm.h
index 2b5e722..d906eba 100644
--- a/src/include/storage/dsm.h
+++ b/src/include/storage/dsm.h
@@ -21,9 +21,9 @@ typedef struct dsm_segment dsm_segment;
 extern void dsm_postmaster_startup(void);
 
 /* Functions that create, update, or remove mappings. */
-extern dsm_segment *dsm_create(uint64 size);
+extern dsm_segment *dsm_create(Size size);
 extern dsm_segment *dsm_attach(dsm_handle h);
-extern void *dsm_resize(dsm_segment *seg, uint64 size);
+extern void *dsm_resize(dsm_segment *seg, Size size);
 extern void *dsm_remap(dsm_segment *seg);
 extern void dsm_detach(dsm_segment *seg);
 
@@ -33,7 +33,7 @@ extern dsm_segment *dsm_find_mapping(dsm_handle h);
 
 /* Informational functions. */
 extern void *dsm_segment_address(dsm_segment *seg);
-extern uint64 dsm_segment_map_length(dsm_segment *seg);
+extern Size dsm_segment_map_length(dsm_segment *seg);
 extern dsm_handle dsm_segment_handle(dsm_segment *seg);
 
 #endif   /* DSM_H */
diff --git a/src/include/storage/dsm_impl.h b/src/include/storage/dsm_impl.h
index 13f1f48..52d8562 100644
--- a/src/include/storage/dsm_impl.h
+++ b/src/include/storage/dsm_impl.h
@@ -65,8 +65,8 @@ typedef enum
 } dsm_op;
 
 /* Create, attach to, detach from, resize, or destroy a segment. */
-extern bool dsm_impl_op(dsm_op op, dsm_handle handle, uint64 request_size,
-			void **impl_private, void **mapped_address, uint64 *mapped_size,
+extern bool dsm_impl_op(dsm_op op, dsm_handle handle, Size request_size,
+			void **impl_private, void **mapped_address, Size *mapped_size,
 			int elevel);
 
 /* Some implementations cannot resize segments.  Can this one? */
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to