PostgreSQL Source Code  git master
dsm_impl.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DSM_IMPL_POSIX   1
 
#define DSM_IMPL_SYSV   2
 
#define DSM_IMPL_WINDOWS   3
 
#define DSM_IMPL_MMAP   4
 
#define USE_DSM_SYSV
 
#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE   DSM_IMPL_SYSV
 
#define USE_DSM_MMAP
 
#define PG_DYNSHMEM_DIR   "pg_dynshmem"
 
#define PG_DYNSHMEM_MMAP_FILE_PREFIX   "mmap."
 
#define DSM_HANDLE_INVALID   ((dsm_handle) 0)
 

Typedefs

typedef uint32 dsm_handle
 

Enumerations

enum  dsm_op { DSM_OP_CREATE , DSM_OP_ATTACH , DSM_OP_DETACH , DSM_OP_DESTROY }
 

Functions

bool dsm_impl_op (dsm_op op, dsm_handle handle, Size request_size, void **impl_private, void **mapped_address, Size *mapped_size, int elevel)
 
void dsm_impl_pin_segment (dsm_handle handle, void *impl_private, void **impl_private_pm_handle)
 
void dsm_impl_unpin_segment (dsm_handle handle, void **impl_private)
 

Variables

PGDLLIMPORT int dynamic_shared_memory_type
 
PGDLLIMPORT int min_dynamic_shared_memory
 

Macro Definition Documentation

◆ DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE

#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE   DSM_IMPL_SYSV

Definition at line 36 of file dsm_impl.h.

◆ DSM_HANDLE_INVALID

#define DSM_HANDLE_INVALID   ((dsm_handle) 0)

Definition at line 58 of file dsm_impl.h.

◆ DSM_IMPL_MMAP

#define DSM_IMPL_MMAP   4

Definition at line 20 of file dsm_impl.h.

◆ DSM_IMPL_POSIX

#define DSM_IMPL_POSIX   1

Definition at line 17 of file dsm_impl.h.

◆ DSM_IMPL_SYSV

#define DSM_IMPL_SYSV   2

Definition at line 18 of file dsm_impl.h.

◆ DSM_IMPL_WINDOWS

#define DSM_IMPL_WINDOWS   3

Definition at line 19 of file dsm_impl.h.

◆ PG_DYNSHMEM_DIR

#define PG_DYNSHMEM_DIR   "pg_dynshmem"

Definition at line 51 of file dsm_impl.h.

◆ PG_DYNSHMEM_MMAP_FILE_PREFIX

#define PG_DYNSHMEM_MMAP_FILE_PREFIX   "mmap."

Definition at line 52 of file dsm_impl.h.

◆ USE_DSM_MMAP

#define USE_DSM_MMAP

Definition at line 38 of file dsm_impl.h.

◆ USE_DSM_SYSV

#define USE_DSM_SYSV

Definition at line 34 of file dsm_impl.h.

Typedef Documentation

◆ dsm_handle

typedef uint32 dsm_handle

Definition at line 55 of file dsm_impl.h.

Enumeration Type Documentation

◆ dsm_op

enum dsm_op
Enumerator
DSM_OP_CREATE 
DSM_OP_ATTACH 
DSM_OP_DETACH 
DSM_OP_DESTROY 

Definition at line 61 of file dsm_impl.h.

62 {
67 } dsm_op;
dsm_op
Definition: dsm_impl.h:62
@ DSM_OP_DETACH
Definition: dsm_impl.h:65
@ DSM_OP_CREATE
Definition: dsm_impl.h:63
@ DSM_OP_DESTROY
Definition: dsm_impl.h:66
@ DSM_OP_ATTACH
Definition: dsm_impl.h:64

Function Documentation

◆ dsm_impl_op()

bool dsm_impl_op ( dsm_op  op,
dsm_handle  handle,
Size  request_size,
void **  impl_private,
void **  mapped_address,
Size mapped_size,
int  elevel 
)

Definition at line 159 of file dsm_impl.c.

162 {
163  Assert(op == DSM_OP_CREATE || request_size == 0);
164  Assert((op != DSM_OP_CREATE && op != DSM_OP_ATTACH) ||
165  (*mapped_address == NULL && *mapped_size == 0));
166 
168  {
169 #ifdef USE_DSM_POSIX
170  case DSM_IMPL_POSIX:
171  return dsm_impl_posix(op, handle, request_size, impl_private,
172  mapped_address, mapped_size, elevel);
173 #endif
174 #ifdef USE_DSM_SYSV
175  case DSM_IMPL_SYSV:
176  return dsm_impl_sysv(op, handle, request_size, impl_private,
177  mapped_address, mapped_size, elevel);
178 #endif
179 #ifdef USE_DSM_WINDOWS
180  case DSM_IMPL_WINDOWS:
181  return dsm_impl_windows(op, handle, request_size, impl_private,
182  mapped_address, mapped_size, elevel);
183 #endif
184 #ifdef USE_DSM_MMAP
185  case DSM_IMPL_MMAP:
186  return dsm_impl_mmap(op, handle, request_size, impl_private,
187  mapped_address, mapped_size, elevel);
188 #endif
189  default:
190  elog(ERROR, "unexpected dynamic shared memory type: %d",
192  return false;
193  }
194 }
#define Assert(condition)
Definition: c.h:858
int dynamic_shared_memory_type
Definition: dsm_impl.c:112
static bool dsm_impl_sysv(dsm_op op, dsm_handle handle, Size request_size, void **impl_private, void **mapped_address, Size *mapped_size, int elevel)
Definition: dsm_impl.c:423
static bool dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size, void **impl_private, void **mapped_address, Size *mapped_size, int elevel)
Definition: dsm_impl.c:212
static bool dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size, void **impl_private, void **mapped_address, Size *mapped_size, int elevel)
Definition: dsm_impl.c:792
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:19
#define DSM_IMPL_POSIX
Definition: dsm_impl.h:17
#define DSM_IMPL_SYSV
Definition: dsm_impl.h:18
#define DSM_IMPL_MMAP
Definition: dsm_impl.h:20
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224

References Assert, dsm_impl_mmap(), DSM_IMPL_MMAP, dsm_impl_posix(), DSM_IMPL_POSIX, dsm_impl_sysv(), DSM_IMPL_SYSV, DSM_IMPL_WINDOWS, DSM_OP_ATTACH, DSM_OP_CREATE, dynamic_shared_memory_type, elog, and ERROR.

Referenced by dsm_attach(), dsm_backend_startup(), dsm_cleanup_using_control_segment(), dsm_create(), dsm_detach(), dsm_detach_all(), dsm_postmaster_shutdown(), dsm_postmaster_startup(), and dsm_unpin_segment().

◆ dsm_impl_pin_segment()

void dsm_impl_pin_segment ( dsm_handle  handle,
void *  impl_private,
void **  impl_private_pm_handle 
)

Definition at line 963 of file dsm_impl.c.

965 {
967  {
968 #ifdef USE_DSM_WINDOWS
969  case DSM_IMPL_WINDOWS:
970  if (IsUnderPostmaster)
971  {
972  HANDLE hmap;
973 
974  if (!DuplicateHandle(GetCurrentProcess(), impl_private,
975  PostmasterHandle, &hmap, 0, FALSE,
976  DUPLICATE_SAME_ACCESS))
977  {
978  char name[64];
979 
980  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
981  _dosmaperr(GetLastError());
982  ereport(ERROR,
984  errmsg("could not duplicate handle for \"%s\": %m",
985  name)));
986  }
987 
988  /*
989  * Here, we remember the handle that we created in the
990  * postmaster process. This handle isn't actually usable in
991  * any process other than the postmaster, but that doesn't
992  * matter. We're just holding onto it so that, if the segment
993  * is unpinned, dsm_impl_unpin_segment can close it.
994  */
995  *impl_private_pm_handle = hmap;
996  }
997  break;
998 #endif
999  default:
1000  break;
1001  }
1002 }
static int errcode_for_dynamic_shared_memory(void)
Definition: dsm_impl.c:1047
#define SEGMENT_NAME_PREFIX
Definition: dsm_impl.c:120
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ereport(elevel,...)
Definition: elog.h:149
bool IsUnderPostmaster
Definition: globals.c:117
#define snprintf
Definition: port.h:238
const char * name
void _dosmaperr(unsigned long)
Definition: win32error.c:177

References _dosmaperr(), DSM_IMPL_WINDOWS, dynamic_shared_memory_type, ereport, errcode_for_dynamic_shared_memory(), errmsg(), ERROR, IsUnderPostmaster, name, SEGMENT_NAME_PREFIX, and snprintf.

Referenced by dsm_pin_segment().

◆ dsm_impl_unpin_segment()

void dsm_impl_unpin_segment ( dsm_handle  handle,
void **  impl_private 
)

Definition at line 1014 of file dsm_impl.c.

1015 {
1017  {
1018 #ifdef USE_DSM_WINDOWS
1019  case DSM_IMPL_WINDOWS:
1020  if (IsUnderPostmaster)
1021  {
1022  if (*impl_private &&
1023  !DuplicateHandle(PostmasterHandle, *impl_private,
1024  NULL, NULL, 0, FALSE,
1025  DUPLICATE_CLOSE_SOURCE))
1026  {
1027  char name[64];
1028 
1029  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
1030  _dosmaperr(GetLastError());
1031  ereport(ERROR,
1033  errmsg("could not duplicate handle for \"%s\": %m",
1034  name)));
1035  }
1036 
1037  *impl_private = NULL;
1038  }
1039  break;
1040 #endif
1041  default:
1042  break;
1043  }
1044 }

References _dosmaperr(), DSM_IMPL_WINDOWS, dynamic_shared_memory_type, ereport, errcode_for_dynamic_shared_memory(), errmsg(), ERROR, IsUnderPostmaster, name, SEGMENT_NAME_PREFIX, and snprintf.

Referenced by dsm_unpin_segment().

Variable Documentation

◆ dynamic_shared_memory_type

PGDLLIMPORT int dynamic_shared_memory_type
extern

◆ min_dynamic_shared_memory

PGDLLIMPORT int min_dynamic_shared_memory
extern

Definition at line 115 of file dsm_impl.c.

Referenced by dsm_estimate_size().