&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.
* 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.
*
* 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
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));
}
}
-/*
- * 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.
/*
* 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)
{
}
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;
/*
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);
* 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,
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;
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;
/*
* 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)
{
}
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.
/* 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,
}
}
- /*
- * 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);