Skip to content

Commit 3c60d0f

Browse files
committed
Remove dsm_resize() and dsm_remap().
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
1 parent b0a1ff8 commit 3c60d0f

File tree

4 files changed

+12
-174
lines changed

4 files changed

+12
-174
lines changed

src/backend/storage/ipc/dsm.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -653,38 +653,6 @@ dsm_detach_all(void)
653653
&dsm_control_mapped_size, ERROR);
654654
}
655655

656-
/*
657-
* Resize an existing shared memory segment.
658-
*
659-
* This may cause the shared memory segment to be remapped at a different
660-
* address. For the caller's convenience, we return the mapped address.
661-
*/
662-
void *
663-
dsm_resize(dsm_segment *seg, Size size)
664-
{
665-
Assert(seg->control_slot != INVALID_CONTROL_SLOT);
666-
dsm_impl_op(DSM_OP_RESIZE, seg->handle, size, &seg->impl_private,
667-
&seg->mapped_address, &seg->mapped_size, ERROR);
668-
return seg->mapped_address;
669-
}
670-
671-
/*
672-
* Remap an existing shared memory segment.
673-
*
674-
* This is intended to be used when some other process has extended the
675-
* mapping using dsm_resize(), but we've still only got the initial
676-
* portion mapped. Since this might change the address at which the
677-
* segment is mapped, we return the new mapped address.
678-
*/
679-
void *
680-
dsm_remap(dsm_segment *seg)
681-
{
682-
dsm_impl_op(DSM_OP_ATTACH, seg->handle, 0, &seg->impl_private,
683-
&seg->mapped_address, &seg->mapped_size, ERROR);
684-
685-
return seg->mapped_address;
686-
}
687-
688656
/*
689657
* Detach from a shared memory segment, destroying the segment if we
690658
* remove the last reference.

src/backend/storage/ipc/dsm_impl.c

Lines changed: 11 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,17 @@ int dynamic_shared_memory_type;
127127
* map it.
128128
*
129129
* DSM_OP_ATTACH. Map the segment, whose size must be the request_size.
130-
* The segment may already be mapped; any existing mapping should be removed
131-
* before creating a new one.
132130
*
133131
* DSM_OP_DETACH. Unmap the segment.
134132
*
135-
* DSM_OP_RESIZE. Resize the segment to the given request_size and
136-
* remap the segment at that new size.
137-
*
138133
* DSM_OP_DESTROY. Unmap the segment, if it is mapped. Destroy the
139134
* segment.
140135
*
141136
* Arguments:
142137
* op: The operation to be performed.
143138
* handle: The handle of an existing object, or for DSM_OP_CREATE, the
144139
* a new handle the caller wants created.
145-
* request_size: For DSM_OP_CREATE, the requested size. For DSM_OP_RESIZE,
146-
* the new size. Otherwise, 0.
140+
* request_size: For DSM_OP_CREATE, the requested size. Otherwise, 0.
147141
* impl_private: Private, implementation-specific data. Will be a pointer
148142
* to NULL for the first operation on a shared memory segment within this
149143
* 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,
165159
void **impl_private, void **mapped_address, Size *mapped_size,
166160
int elevel)
167161
{
168-
Assert(op == DSM_OP_CREATE || op == DSM_OP_RESIZE || request_size == 0);
162+
Assert(op == DSM_OP_CREATE || request_size == 0);
169163
Assert((op != DSM_OP_CREATE && op != DSM_OP_ATTACH) ||
170164
(*mapped_address == NULL && *mapped_size == 0));
171165

@@ -198,31 +192,6 @@ dsm_impl_op(dsm_op op, dsm_handle handle, Size request_size,
198192
}
199193
}
200194

201-
/*
202-
* Does the current dynamic shared memory implementation support resizing
203-
* segments? (The answer here could be platform-dependent in the future,
204-
* since AIX allows shmctl(shmid, SHM_RESIZE, &buffer), though you apparently
205-
* can't resize segments to anything larger than 256MB that way. For now,
206-
* we keep it simple.)
207-
*/
208-
bool
209-
dsm_impl_can_resize(void)
210-
{
211-
switch (dynamic_shared_memory_type)
212-
{
213-
case DSM_IMPL_POSIX:
214-
return true;
215-
case DSM_IMPL_SYSV:
216-
return false;
217-
case DSM_IMPL_WINDOWS:
218-
return false;
219-
case DSM_IMPL_MMAP:
220-
return true;
221-
default:
222-
return false; /* should not happen */
223-
}
224-
}
225-
226195
#ifdef USE_DSM_POSIX
227196
/*
228197
* Operating system primitives to support POSIX shared memory.
@@ -296,7 +265,7 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
296265

297266
/*
298267
* If we're attaching the segment, determine the current size; if we are
299-
* creating or resizing the segment, set the size to the requested value.
268+
* creating the segment, set the size to the requested value.
300269
*/
301270
if (op == DSM_OP_ATTACH)
302271
{
@@ -319,16 +288,14 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
319288
}
320289
request_size = st.st_size;
321290
}
322-
else if (*mapped_size != request_size &&
323-
dsm_impl_posix_resize(fd, request_size) != 0)
291+
else if (dsm_impl_posix_resize(fd, request_size) != 0)
324292
{
325293
int save_errno;
326294

327295
/* Back out what's already been done. */
328296
save_errno = errno;
329297
close(fd);
330-
if (op == DSM_OP_CREATE)
331-
shm_unlink(name);
298+
shm_unlink(name);
332299
errno = save_errno;
333300

334301
/*
@@ -346,35 +313,6 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
346313
return false;
347314
}
348315

349-
/*
350-
* If we're reattaching or resizing, we must remove any existing mapping,
351-
* unless we've already got the right thing mapped.
352-
*/
353-
if (*mapped_address != NULL)
354-
{
355-
if (*mapped_size == request_size)
356-
return true;
357-
if (munmap(*mapped_address, *mapped_size) != 0)
358-
{
359-
int save_errno;
360-
361-
/* Back out what's already been done. */
362-
save_errno = errno;
363-
close(fd);
364-
if (op == DSM_OP_CREATE)
365-
shm_unlink(name);
366-
errno = save_errno;
367-
368-
ereport(elevel,
369-
(errcode_for_dynamic_shared_memory(),
370-
errmsg("could not unmap shared memory segment \"%s\": %m",
371-
name)));
372-
return false;
373-
}
374-
*mapped_address = NULL;
375-
*mapped_size = 0;
376-
}
377-
378316
/* Map it. */
379317
address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
380318
MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);
@@ -457,10 +395,9 @@ dsm_impl_posix_resize(int fd, off_t size)
457395
* Operating system primitives to support System V shared memory.
458396
*
459397
* System V shared memory segments are manipulated using shmget(), shmat(),
460-
* shmdt(), and shmctl(). There's no portable way to resize such
461-
* segments. As the default allocation limits for System V shared memory
462-
* are usually quite low, the POSIX facilities may be preferable; but
463-
* those are not supported everywhere.
398+
* shmdt(), and shmctl(). As the default allocation limits for System V
399+
* shared memory are usually quite low, the POSIX facilities may be
400+
* preferable; but those are not supported everywhere.
464401
*/
465402
static bool
466403
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,
473410
char name[64];
474411
int *ident_cache;
475412

476-
/* Resize is not supported for System V shared memory. */
477-
if (op == DSM_OP_RESIZE)
478-
{
479-
elog(elevel, "System V shared memory segments cannot be resized");
480-
return false;
481-
}
482-
483413
/* Since resize isn't supported, reattach is a no-op. */
484414
if (op == DSM_OP_ATTACH && *mapped_address != NULL)
485415
return true;
@@ -670,13 +600,6 @@ dsm_impl_windows(dsm_op op, dsm_handle handle, Size request_size,
670600
char name[64];
671601
MEMORY_BASIC_INFORMATION info;
672602

673-
/* Resize is not supported for Windows shared memory. */
674-
if (op == DSM_OP_RESIZE)
675-
{
676-
elog(elevel, "Windows shared memory segments cannot be resized");
677-
return false;
678-
}
679-
680603
/* Since resize isn't supported, reattach is a no-op. */
681604
if (op == DSM_OP_ATTACH && *mapped_address != NULL)
682605
return true;
@@ -905,7 +828,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
905828

906829
/*
907830
* If we're attaching the segment, determine the current size; if we are
908-
* creating or resizing the segment, set the size to the requested value.
831+
* creating the segment, set the size to the requested value.
909832
*/
910833
if (op == DSM_OP_ATTACH)
911834
{
@@ -928,24 +851,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
928851
}
929852
request_size = st.st_size;
930853
}
931-
else if (*mapped_size > request_size && ftruncate(fd, request_size))
932-
{
933-
int save_errno;
934-
935-
/* Back out what's already been done. */
936-
save_errno = errno;
937-
CloseTransientFile(fd);
938-
if (op == DSM_OP_CREATE)
939-
unlink(name);
940-
errno = save_errno;
941-
942-
ereport(elevel,
943-
(errcode_for_dynamic_shared_memory(),
944-
errmsg("could not resize shared memory segment \"%s\" to %zu bytes: %m",
945-
name, request_size)));
946-
return false;
947-
}
948-
else if (*mapped_size < request_size)
854+
else
949855
{
950856
/*
951857
* Allocate a buffer full of zeros.
@@ -985,8 +891,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
985891
/* Back out what's already been done. */
986892
save_errno = errno;
987893
CloseTransientFile(fd);
988-
if (op == DSM_OP_CREATE)
989-
unlink(name);
894+
unlink(name);
990895
errno = save_errno ? save_errno : ENOSPC;
991896

992897
ereport(elevel,
@@ -997,35 +902,6 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
997902
}
998903
}
999904

1000-
/*
1001-
* If we're reattaching or resizing, we must remove any existing mapping,
1002-
* unless we've already got the right thing mapped.
1003-
*/
1004-
if (*mapped_address != NULL)
1005-
{
1006-
if (*mapped_size == request_size)
1007-
return true;
1008-
if (munmap(*mapped_address, *mapped_size) != 0)
1009-
{
1010-
int save_errno;
1011-
1012-
/* Back out what's already been done. */
1013-
save_errno = errno;
1014-
CloseTransientFile(fd);
1015-
if (op == DSM_OP_CREATE)
1016-
unlink(name);
1017-
errno = save_errno;
1018-
1019-
ereport(elevel,
1020-
(errcode_for_dynamic_shared_memory(),
1021-
errmsg("could not unmap shared memory segment \"%s\": %m",
1022-
name)));
1023-
return false;
1024-
}
1025-
*mapped_address = NULL;
1026-
*mapped_size = 0;
1027-
}
1028-
1029905
/* Map it. */
1030906
address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
1031907
MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);

src/include/storage/dsm.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ extern void dsm_detach_all(void);
3333
extern void dsm_set_control_handle(dsm_handle h);
3434
#endif
3535

36-
/* Functions that create, update, or remove mappings. */
36+
/* Functions that create or remove mappings. */
3737
extern dsm_segment *dsm_create(Size size, int flags);
3838
extern dsm_segment *dsm_attach(dsm_handle h);
39-
extern void *dsm_resize(dsm_segment *seg, Size size);
40-
extern void *dsm_remap(dsm_segment *seg);
4139
extern void dsm_detach(dsm_segment *seg);
4240

4341
/* Resource management functions. */

src/include/storage/dsm_impl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ typedef enum
5959
DSM_OP_CREATE,
6060
DSM_OP_ATTACH,
6161
DSM_OP_DETACH,
62-
DSM_OP_RESIZE,
6362
DSM_OP_DESTROY
6463
} dsm_op;
6564

@@ -68,9 +67,6 @@ extern bool dsm_impl_op(dsm_op op, dsm_handle handle, Size request_size,
6867
void **impl_private, void **mapped_address, Size *mapped_size,
6968
int elevel);
7069

71-
/* Some implementations cannot resize segments. Can this one? */
72-
extern bool dsm_impl_can_resize(void);
73-
7470
/* Implementation-dependent actions required to keep segment until shutdown. */
7571
extern void dsm_impl_pin_segment(dsm_handle handle, void *impl_private,
7672
void **impl_private_pm_handle);

0 commit comments

Comments
 (0)