]> granicus.if.org Git - postgresql/commitdiff
Remove dsm_resize() and dsm_remap().
authorThomas Munro <tmunro@postgresql.org>
Tue, 6 Nov 2018 03:11:12 +0000 (16:11 +1300)
committerThomas Munro <tmunro@postgresql.org>
Tue, 6 Nov 2018 03:11:12 +0000 (16:11 +1300)
These interfaces were never used in core, didn't handle failure of
posix_fallocate() correctly and weren't supported on all platforms.
We agreed to remove them in 12.

Author: Thomas Munro
Reported-by: Andres Freund
Discussion: https://postgr.es/m/CAA4eK1%2B%3DyAFUvpFoHXFi_gm8YqmXN-TtkFH%2BVYjvDLS6-SFq-Q%40mail.gmail.com

src/backend/storage/ipc/dsm.c
src/backend/storage/ipc/dsm_impl.c
src/include/storage/dsm.h
src/include/storage/dsm_impl.h

index d4bd6ef44901f69d2b9db0851273a0e74f495820..edee89c116515e3b0cce865f5f3a3b2723ff7313 100644 (file)
@@ -653,38 +653,6 @@ dsm_detach_all(void)
                                        &dsm_control_mapped_size, ERROR);
 }
 
-/*
- * Resize an existing shared memory segment.
- *
- * This may cause the shared memory segment to be remapped at a different
- * address.  For the caller's convenience, we return the mapped address.
- */
-void *
-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,
-                               &seg->mapped_address, &seg->mapped_size, ERROR);
-       return seg->mapped_address;
-}
-
-/*
- * Remap an existing shared memory segment.
- *
- * This is intended to be used when some other process has extended the
- * mapping using dsm_resize(), but we've still only got the initial
- * portion mapped.  Since this might change the address at which the
- * segment is mapped, we return the new mapped address.
- */
-void *
-dsm_remap(dsm_segment *seg)
-{
-       dsm_impl_op(DSM_OP_ATTACH, seg->handle, 0, &seg->impl_private,
-                               &seg->mapped_address, &seg->mapped_size, ERROR);
-
-       return seg->mapped_address;
-}
-
 /*
  * Detach from a shared memory segment, destroying the segment if we
  * remove the last reference.
index 70f899e7658b34887745d8c8038e6d2b434ffd9a..78154010aaf3d4c8024bf4c97924036fb5c6bd8c 100644 (file)
@@ -127,14 +127,9 @@ int                        dynamic_shared_memory_type;
  * map it.
  *
  * DSM_OP_ATTACH.  Map the segment, whose size must be the request_size.
- * The segment may already be mapped; any existing mapping should be removed
- * before creating a new one.
  *
  * DSM_OP_DETACH.  Unmap the segment.
  *
- * DSM_OP_RESIZE.  Resize the segment to the given request_size and
- * remap the segment at that new size.
- *
  * DSM_OP_DESTROY.  Unmap the segment, if it is mapped.  Destroy the
  * segment.
  *
@@ -142,8 +137,7 @@ int                 dynamic_shared_memory_type;
  *      op: The operation to be performed.
  *      handle: The handle of an existing object, or for DSM_OP_CREATE, the
  *        a new handle the caller wants created.
- *      request_size: For DSM_OP_CREATE, the requested size.  For DSM_OP_RESIZE,
- *        the new size.  Otherwise, 0.
+ *      request_size: For DSM_OP_CREATE, the requested size.  Otherwise, 0.
  *      impl_private: Private, implementation-specific data.  Will be a pointer
  *        to NULL for the first operation on a shared memory segment within this
  *        backend; thereafter, it will point to the value to which it was set
@@ -165,7 +159,7 @@ 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 || request_size == 0);
        Assert((op != DSM_OP_CREATE && op != DSM_OP_ATTACH) ||
                   (*mapped_address == NULL && *mapped_size == 0));
 
@@ -198,31 +192,6 @@ dsm_impl_op(dsm_op op, dsm_handle handle, Size request_size,
        }
 }
 
-/*
- * Does the current dynamic shared memory implementation support resizing
- * segments?  (The answer here could be platform-dependent in the future,
- * since AIX allows shmctl(shmid, SHM_RESIZE, &buffer), though you apparently
- * can't resize segments to anything larger than 256MB that way.  For now,
- * we keep it simple.)
- */
-bool
-dsm_impl_can_resize(void)
-{
-       switch (dynamic_shared_memory_type)
-       {
-               case DSM_IMPL_POSIX:
-                       return true;
-               case DSM_IMPL_SYSV:
-                       return false;
-               case DSM_IMPL_WINDOWS:
-                       return false;
-               case DSM_IMPL_MMAP:
-                       return true;
-               default:
-                       return false;           /* should not happen */
-       }
-}
-
 #ifdef USE_DSM_POSIX
 /*
  * Operating system primitives to support POSIX shared memory.
@@ -296,7 +265,7 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
 
        /*
         * If we're attaching the segment, determine the current size; if we are
-        * creating or resizing the segment, set the size to the requested value.
+        * creating the segment, set the size to the requested value.
         */
        if (op == DSM_OP_ATTACH)
        {
@@ -319,16 +288,14 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
                }
                request_size = st.st_size;
        }
-       else if (*mapped_size != request_size &&
-                        dsm_impl_posix_resize(fd, request_size) != 0)
+       else if (dsm_impl_posix_resize(fd, request_size) != 0)
        {
                int                     save_errno;
 
                /* Back out what's already been done. */
                save_errno = errno;
                close(fd);
-               if (op == DSM_OP_CREATE)
-                       shm_unlink(name);
+               shm_unlink(name);
                errno = save_errno;
 
                /*
@@ -346,35 +313,6 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
                return false;
        }
 
-       /*
-        * If we're reattaching or resizing, we must remove any existing mapping,
-        * unless we've already got the right thing mapped.
-        */
-       if (*mapped_address != NULL)
-       {
-               if (*mapped_size == request_size)
-                       return true;
-               if (munmap(*mapped_address, *mapped_size) != 0)
-               {
-                       int                     save_errno;
-
-                       /* Back out what's already been done. */
-                       save_errno = errno;
-                       close(fd);
-                       if (op == DSM_OP_CREATE)
-                               shm_unlink(name);
-                       errno = save_errno;
-
-                       ereport(elevel,
-                                       (errcode_for_dynamic_shared_memory(),
-                                        errmsg("could not unmap shared memory segment \"%s\": %m",
-                                                       name)));
-                       return false;
-               }
-               *mapped_address = NULL;
-               *mapped_size = 0;
-       }
-
        /* Map it. */
        address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
                                   MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);
@@ -457,10 +395,9 @@ dsm_impl_posix_resize(int fd, off_t size)
  * Operating system primitives to support System V shared memory.
  *
  * System V shared memory segments are manipulated using shmget(), shmat(),
- * shmdt(), and shmctl().  There's no portable way to resize such
- * segments.  As the default allocation limits for System V shared memory
- * are usually quite low, the POSIX facilities may be preferable; but
- * those are not supported everywhere.
+ * shmdt(), and shmctl().  As the default allocation limits for System V
+ * shared memory are usually quite low, the POSIX facilities may be
+ * preferable; but those are not supported everywhere.
  */
 static bool
 dsm_impl_sysv(dsm_op op, dsm_handle handle, Size request_size,
@@ -473,13 +410,6 @@ dsm_impl_sysv(dsm_op op, dsm_handle handle, Size request_size,
        char            name[64];
        int                *ident_cache;
 
-       /* Resize is not supported for System V shared memory. */
-       if (op == DSM_OP_RESIZE)
-       {
-               elog(elevel, "System V shared memory segments cannot be resized");
-               return false;
-       }
-
        /* Since resize isn't supported, reattach is a no-op. */
        if (op == DSM_OP_ATTACH && *mapped_address != NULL)
                return true;
@@ -670,13 +600,6 @@ dsm_impl_windows(dsm_op op, dsm_handle handle, Size request_size,
        char            name[64];
        MEMORY_BASIC_INFORMATION info;
 
-       /* Resize is not supported for Windows shared memory. */
-       if (op == DSM_OP_RESIZE)
-       {
-               elog(elevel, "Windows shared memory segments cannot be resized");
-               return false;
-       }
-
        /* Since resize isn't supported, reattach is a no-op. */
        if (op == DSM_OP_ATTACH && *mapped_address != NULL)
                return true;
@@ -905,7 +828,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
 
        /*
         * If we're attaching the segment, determine the current size; if we are
-        * creating or resizing the segment, set the size to the requested value.
+        * creating the segment, set the size to the requested value.
         */
        if (op == DSM_OP_ATTACH)
        {
@@ -928,24 +851,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
                }
                request_size = st.st_size;
        }
-       else if (*mapped_size > request_size && ftruncate(fd, request_size))
-       {
-               int                     save_errno;
-
-               /* Back out what's already been done. */
-               save_errno = errno;
-               CloseTransientFile(fd);
-               if (op == DSM_OP_CREATE)
-                       unlink(name);
-               errno = save_errno;
-
-               ereport(elevel,
-                               (errcode_for_dynamic_shared_memory(),
-                                errmsg("could not resize shared memory segment \"%s\" to %zu bytes: %m",
-                                               name, request_size)));
-               return false;
-       }
-       else if (*mapped_size < request_size)
+       else
        {
                /*
                 * Allocate a buffer full of zeros.
@@ -985,8 +891,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
                        /* Back out what's already been done. */
                        save_errno = errno;
                        CloseTransientFile(fd);
-                       if (op == DSM_OP_CREATE)
-                               unlink(name);
+                       unlink(name);
                        errno = save_errno ? save_errno : ENOSPC;
 
                        ereport(elevel,
@@ -997,35 +902,6 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
                }
        }
 
-       /*
-        * If we're reattaching or resizing, we must remove any existing mapping,
-        * unless we've already got the right thing mapped.
-        */
-       if (*mapped_address != NULL)
-       {
-               if (*mapped_size == request_size)
-                       return true;
-               if (munmap(*mapped_address, *mapped_size) != 0)
-               {
-                       int                     save_errno;
-
-                       /* Back out what's already been done. */
-                       save_errno = errno;
-                       CloseTransientFile(fd);
-                       if (op == DSM_OP_CREATE)
-                               unlink(name);
-                       errno = save_errno;
-
-                       ereport(elevel,
-                                       (errcode_for_dynamic_shared_memory(),
-                                        errmsg("could not unmap shared memory segment \"%s\": %m",
-                                                       name)));
-                       return false;
-               }
-               *mapped_address = NULL;
-               *mapped_size = 0;
-       }
-
        /* Map it. */
        address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
                                   MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);
index 169de946f7b07dab7278a0bbc562cd45795caa9a..b4654cb5ca5d2b1e0b068ada2079d78301055acb 100644 (file)
@@ -33,11 +33,9 @@ extern void dsm_detach_all(void);
 extern void dsm_set_control_handle(dsm_handle h);
 #endif
 
-/* Functions that create, update, or remove mappings. */
+/* Functions that create or remove mappings. */
 extern dsm_segment *dsm_create(Size size, int flags);
 extern dsm_segment *dsm_attach(dsm_handle h);
-extern void *dsm_resize(dsm_segment *seg, Size size);
-extern void *dsm_remap(dsm_segment *seg);
 extern void dsm_detach(dsm_segment *seg);
 
 /* Resource management functions. */
index e7acdff355209cbc623bef188d5ef1a33e1e5082..9485446c91469f113355ac7ebf2bc407a30fa531 100644 (file)
@@ -59,7 +59,6 @@ typedef enum
        DSM_OP_CREATE,
        DSM_OP_ATTACH,
        DSM_OP_DETACH,
-       DSM_OP_RESIZE,
        DSM_OP_DESTROY
 } dsm_op;
 
@@ -68,9 +67,6 @@ 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? */
-extern bool dsm_impl_can_resize(void);
-
 /* Implementation-dependent actions required to keep segment until shutdown. */
 extern void dsm_impl_pin_segment(dsm_handle handle, void *impl_private,
                                         void **impl_private_pm_handle);