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_NONE   0
 
#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."
 

Typedefs

typedef uint32 dsm_handle
 

Enumerations

enum  dsm_op {
  DSM_OP_CREATE, DSM_OP_ATTACH, DSM_OP_DETACH, DSM_OP_RESIZE,
  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)
 
bool dsm_impl_can_resize (void)
 
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

int dynamic_shared_memory_type
 

Macro Definition Documentation

◆ DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE

#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE   DSM_IMPL_SYSV

Definition at line 37 of file dsm_impl.h.

◆ DSM_IMPL_MMAP

#define DSM_IMPL_MMAP   4

Definition at line 21 of file dsm_impl.h.

Referenced by dsm_impl_can_resize(), dsm_impl_op(), and dsm_postmaster_startup().

◆ DSM_IMPL_NONE

◆ DSM_IMPL_POSIX

#define DSM_IMPL_POSIX   1

Definition at line 18 of file dsm_impl.h.

Referenced by dsm_impl_can_resize(), and dsm_impl_op().

◆ DSM_IMPL_SYSV

#define DSM_IMPL_SYSV   2

Definition at line 19 of file dsm_impl.h.

Referenced by dsm_impl_can_resize(), and dsm_impl_op().

◆ DSM_IMPL_WINDOWS

#define DSM_IMPL_WINDOWS   3

◆ PG_DYNSHMEM_DIR

#define PG_DYNSHMEM_DIR   "pg_dynshmem"

Definition at line 51 of file dsm_impl.h.

Referenced by dsm_cleanup_for_mmap(), and dsm_impl_mmap().

◆ PG_DYNSHMEM_MMAP_FILE_PREFIX

#define PG_DYNSHMEM_MMAP_FILE_PREFIX   "mmap."

Definition at line 52 of file dsm_impl.h.

Referenced by dsm_cleanup_for_mmap(), and dsm_impl_mmap().

◆ USE_DSM_MMAP

#define USE_DSM_MMAP

Definition at line 39 of file dsm_impl.h.

◆ USE_DSM_SYSV

#define USE_DSM_SYSV

Definition at line 35 of file dsm_impl.h.

Typedef Documentation

◆ 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_RESIZE 
DSM_OP_DESTROY 

Definition at line 58 of file dsm_impl.h.

Function Documentation

◆ dsm_impl_can_resize()

bool dsm_impl_can_resize ( void  )

Definition at line 208 of file dsm_impl.c.

References close, DSM_IMPL_MMAP, DSM_IMPL_NONE, DSM_IMPL_POSIX, DSM_IMPL_SYSV, DSM_IMPL_WINDOWS, DSM_OP_ATTACH, DSM_OP_CREATE, DSM_OP_DESTROY, DSM_OP_DETACH, dynamic_shared_memory_type, EINTR, elevel, ereport, errcode_for_dynamic_shared_memory(), errmsg(), fd(), ftruncate, MAP_FAILED, MAP_HASSEMAPHORE, MAP_NOSYNC, name, snprintf(), and stat.

209 {
211  {
212  case DSM_IMPL_NONE:
213  return false;
214  case DSM_IMPL_POSIX:
215  return true;
216  case DSM_IMPL_SYSV:
217  return false;
218  case DSM_IMPL_WINDOWS:
219  return false;
220  case DSM_IMPL_MMAP:
221  return true;
222  default:
223  return false; /* should not happen */
224  }
225 }
#define DSM_IMPL_MMAP
Definition: dsm_impl.h:21
#define DSM_IMPL_SYSV
Definition: dsm_impl.h:19
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:20
#define DSM_IMPL_POSIX
Definition: dsm_impl.h:18
int dynamic_shared_memory_type
Definition: dsm_impl.c:113
#define DSM_IMPL_NONE
Definition: dsm_impl.h:17

◆ 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 163 of file dsm_impl.c.

References Assert, DSM_IMPL_MMAP, dsm_impl_mmap(), DSM_IMPL_POSIX, DSM_IMPL_SYSV, dsm_impl_sysv(), DSM_IMPL_WINDOWS, DSM_OP_ATTACH, DSM_OP_CREATE, DSM_OP_RESIZE, 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(), dsm_remap(), dsm_resize(), and dsm_unpin_segment().

166 {
167  Assert(op == DSM_OP_CREATE || op == DSM_OP_RESIZE || request_size == 0);
168  Assert((op != DSM_OP_CREATE && op != DSM_OP_ATTACH) ||
169  (*mapped_address == NULL && *mapped_size == 0));
170 
172  {
173 #ifdef USE_DSM_POSIX
174  case DSM_IMPL_POSIX:
175  return dsm_impl_posix(op, handle, request_size, impl_private,
176  mapped_address, mapped_size, elevel);
177 #endif
178 #ifdef USE_DSM_SYSV
179  case DSM_IMPL_SYSV:
180  return dsm_impl_sysv(op, handle, request_size, impl_private,
181  mapped_address, mapped_size, elevel);
182 #endif
183 #ifdef USE_DSM_WINDOWS
184  case DSM_IMPL_WINDOWS:
185  return dsm_impl_windows(op, handle, request_size, impl_private,
186  mapped_address, mapped_size, elevel);
187 #endif
188 #ifdef USE_DSM_MMAP
189  case DSM_IMPL_MMAP:
190  return dsm_impl_mmap(op, handle, request_size, impl_private,
191  mapped_address, mapped_size, elevel);
192 #endif
193  default:
194  elog(ERROR, "unexpected dynamic shared memory type: %d",
196  return false;
197  }
198 }
#define DSM_IMPL_MMAP
Definition: dsm_impl.h:21
#define DSM_IMPL_SYSV
Definition: dsm_impl.h:19
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:20
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:846
#define ERROR
Definition: elog.h:43
#define DSM_IMPL_POSIX
Definition: dsm_impl.h:18
int dynamic_shared_memory_type
Definition: dsm_impl.c:113
static int elevel
Definition: vacuumlazy.c:136
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:455
#define Assert(condition)
Definition: c.h:670
#define elog
Definition: elog.h:219

◆ dsm_impl_pin_segment()

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

Definition at line 1056 of file dsm_impl.c.

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

Referenced by dsm_pin_segment().

1058 {
1060  {
1061 #ifdef USE_DSM_WINDOWS
1062  case DSM_IMPL_WINDOWS:
1063  {
1064  HANDLE hmap;
1065 
1066  if (!DuplicateHandle(GetCurrentProcess(), impl_private,
1067  PostmasterHandle, &hmap, 0, FALSE,
1068  DUPLICATE_SAME_ACCESS))
1069  {
1070  char name[64];
1071 
1072  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
1073  _dosmaperr(GetLastError());
1074  ereport(ERROR,
1076  errmsg("could not duplicate handle for \"%s\": %m",
1077  name)));
1078  }
1079 
1080  /*
1081  * Here, we remember the handle that we created in the
1082  * postmaster process. This handle isn't actually usable in
1083  * any process other than the postmaster, but that doesn't
1084  * matter. We're just holding onto it so that, if the segment
1085  * is unpinned, dsm_impl_unpin_segment can close it.
1086  */
1087  *impl_private_pm_handle = hmap;
1088  break;
1089  }
1090 #endif
1091  default:
1092  break;
1093  }
1094 }
#define FALSE
Definition: ecpglib.h:39
void _dosmaperr(unsigned long)
Definition: win32error.c:171
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:20
static int errcode_for_dynamic_shared_memory(void)
Definition: dsm_impl.c:1138
#define ERROR
Definition: elog.h:43
#define SEGMENT_NAME_PREFIX
Definition: dsm_impl.c:118
int dynamic_shared_memory_type
Definition: dsm_impl.c:113
#define ereport(elevel, rest)
Definition: elog.h:122
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ dsm_impl_unpin_segment()

void dsm_impl_unpin_segment ( dsm_handle  handle,
void **  impl_private 
)

Definition at line 1106 of file dsm_impl.c.

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

Referenced by dsm_unpin_segment().

1107 {
1109  {
1110 #ifdef USE_DSM_WINDOWS
1111  case DSM_IMPL_WINDOWS:
1112  {
1113  if (*impl_private &&
1114  !DuplicateHandle(PostmasterHandle, *impl_private,
1115  NULL, NULL, 0, FALSE,
1116  DUPLICATE_CLOSE_SOURCE))
1117  {
1118  char name[64];
1119 
1120  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
1121  _dosmaperr(GetLastError());
1122  ereport(ERROR,
1124  errmsg("could not duplicate handle for \"%s\": %m",
1125  name)));
1126  }
1127 
1128  *impl_private = NULL;
1129  break;
1130  }
1131 #endif
1132  default:
1133  break;
1134  }
1135 }
#define FALSE
Definition: ecpglib.h:39
void _dosmaperr(unsigned long)
Definition: win32error.c:171
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:20
static int errcode_for_dynamic_shared_memory(void)
Definition: dsm_impl.c:1138
#define ERROR
Definition: elog.h:43
#define SEGMENT_NAME_PREFIX
Definition: dsm_impl.c:118
int dynamic_shared_memory_type
Definition: dsm_impl.c:113
#define ereport(elevel, rest)
Definition: elog.h:122
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

Variable Documentation

◆ dynamic_shared_memory_type