PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE   DSM_IMPL_SYSV

Definition at line 37 of file dsm_impl.h.

#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().

#define DSM_IMPL_POSIX   1

Definition at line 18 of file dsm_impl.h.

Referenced by dsm_impl_can_resize(), and dsm_impl_op().

#define DSM_IMPL_SYSV   2

Definition at line 19 of file dsm_impl.h.

Referenced by dsm_impl_can_resize(), and dsm_impl_op().

#define DSM_IMPL_WINDOWS   3
#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().

#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().

#define USE_DSM_MMAP

Definition at line 39 of file dsm_impl.h.

#define USE_DSM_SYSV

Definition at line 35 of file dsm_impl.h.

Typedef Documentation

Definition at line 55 of file dsm_impl.h.

Enumeration Type Documentation

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

bool dsm_impl_can_resize ( void  )

Definition at line 207 of file dsm_impl.c.

References DSM_IMPL_MMAP, DSM_IMPL_NONE, DSM_IMPL_POSIX, DSM_IMPL_SYSV, DSM_IMPL_WINDOWS, and dynamic_shared_memory_type.

208 {
210  {
211  case DSM_IMPL_NONE:
212  return false;
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 }
#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:112
#define DSM_IMPL_NONE
Definition: dsm_impl.h:17
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 162 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, ERROR, and NULL.

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().

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

Definition at line 1009 of file dsm_impl.c.

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

Referenced by dsm_pin_segment().

1011 {
1013  {
1014 #ifdef USE_DSM_WINDOWS
1015  case DSM_IMPL_WINDOWS:
1016  {
1017  HANDLE hmap;
1018 
1019  if (!DuplicateHandle(GetCurrentProcess(), impl_private,
1020  PostmasterHandle, &hmap, 0, FALSE,
1021  DUPLICATE_SAME_ACCESS))
1022  {
1023  char name[64];
1024 
1025  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
1026  _dosmaperr(GetLastError());
1027  ereport(ERROR,
1029  errmsg("could not duplicate handle for \"%s\": %m",
1030  name)));
1031  }
1032 
1033  /*
1034  * Here, we remember the handle that we created in the
1035  * postmaster process. This handle isn't actually usable in
1036  * any process other than the postmaster, but that doesn't
1037  * matter. We're just holding onto it so that, if the segment
1038  * is unpinned, dsm_impl_unpin_segment can close it.
1039  */
1040  *impl_private_pm_handle = hmap;
1041  break;
1042  }
1043 #endif
1044  default:
1045  break;
1046  }
1047 }
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:1091
#define ERROR
Definition: elog.h:43
#define FALSE
Definition: c.h:221
#define SEGMENT_NAME_PREFIX
Definition: dsm_impl.c:117
int dynamic_shared_memory_type
Definition: dsm_impl.c:112
#define ereport(elevel, rest)
Definition: elog.h:122
void _dosmaperr(unsigned long)
Definition: win32error.c:171
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
void dsm_impl_unpin_segment ( dsm_handle  handle,
void **  impl_private 
)

Definition at line 1059 of file dsm_impl.c.

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

Referenced by dsm_unpin_segment().

1060 {
1062  {
1063 #ifdef USE_DSM_WINDOWS
1064  case DSM_IMPL_WINDOWS:
1065  {
1066  if (*impl_private &&
1067  !DuplicateHandle(PostmasterHandle, *impl_private,
1068  NULL, NULL, 0, FALSE,
1069  DUPLICATE_CLOSE_SOURCE))
1070  {
1071  char name[64];
1072 
1073  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
1074  _dosmaperr(GetLastError());
1075  ereport(ERROR,
1077  errmsg("could not duplicate handle for \"%s\": %m",
1078  name)));
1079  }
1080 
1081  *impl_private = NULL;
1082  break;
1083  }
1084 #endif
1085  default:
1086  break;
1087  }
1088 }
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:1091
#define ERROR
Definition: elog.h:43
#define FALSE
Definition: c.h:221
#define SEGMENT_NAME_PREFIX
Definition: dsm_impl.c:117
int dynamic_shared_memory_type
Definition: dsm_impl.c:112
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:229
void _dosmaperr(unsigned long)
Definition: win32error.c:171
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

Variable Documentation