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."
 

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

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 36 of file dsm_impl.h.

◆ DSM_IMPL_MMAP

#define DSM_IMPL_MMAP   4

Definition at line 20 of file dsm_impl.h.

Referenced by dsm_impl_op(), and dsm_postmaster_startup().

◆ DSM_IMPL_POSIX

#define DSM_IMPL_POSIX   1

Definition at line 17 of file dsm_impl.h.

Referenced by dsm_impl_op().

◆ DSM_IMPL_SYSV

#define DSM_IMPL_SYSV   2

Definition at line 18 of file dsm_impl.h.

Referenced by dsm_impl_op().

◆ DSM_IMPL_WINDOWS

#define DSM_IMPL_WINDOWS   3

Definition at line 19 of file dsm_impl.h.

Referenced by dsm_impl_op(), dsm_impl_pin_segment(), and dsm_impl_unpin_segment().

◆ PG_DYNSHMEM_DIR

#define PG_DYNSHMEM_DIR   "pg_dynshmem"

Definition at line 50 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 51 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 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 54 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 57 of file dsm_impl.h.

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

References Assert, CHECK_FOR_INTERRUPTS, close, 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_DESTROY, DSM_OP_DETACH, dynamic_shared_memory_type, EINTR, elevel, elog, ereport, errcode_for_dynamic_shared_memory(), errmsg(), ERROR, fd(), ftruncate, MAP_FAILED, MAP_HASSEMAPHORE, MAP_NOSYNC, name, PG_FILE_MODE_OWNER, pgstat_report_wait_end(), pgstat_report_wait_start(), ProcDiePending, QueryCancelPending, ReleaseExternalFD(), ReserveExternalFD(), snprintf, stat, and WAIT_EVENT_DSM_FILL_ZERO_WRITE.

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

161 {
162  Assert(op == DSM_OP_CREATE || request_size == 0);
163  Assert((op != DSM_OP_CREATE && op != DSM_OP_ATTACH) ||
164  (*mapped_address == NULL && *mapped_size == 0));
165 
167  {
168 #ifdef USE_DSM_POSIX
169  case DSM_IMPL_POSIX:
170  return dsm_impl_posix(op, handle, request_size, impl_private,
171  mapped_address, mapped_size, elevel);
172 #endif
173 #ifdef USE_DSM_SYSV
174  case DSM_IMPL_SYSV:
175  return dsm_impl_sysv(op, handle, request_size, impl_private,
176  mapped_address, mapped_size, elevel);
177 #endif
178 #ifdef USE_DSM_WINDOWS
179  case DSM_IMPL_WINDOWS:
180  return dsm_impl_windows(op, handle, request_size, impl_private,
181  mapped_address, mapped_size, elevel);
182 #endif
183 #ifdef USE_DSM_MMAP
184  case DSM_IMPL_MMAP:
185  return dsm_impl_mmap(op, handle, request_size, impl_private,
186  mapped_address, mapped_size, elevel);
187 #endif
188  default:
189  elog(ERROR, "unexpected dynamic shared memory type: %d",
191  return false;
192  }
193 }
#define DSM_IMPL_MMAP
Definition: dsm_impl.h:20
#define DSM_IMPL_SYSV
Definition: dsm_impl.h:18
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:19
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:781
#define ERROR
Definition: elog.h:43
#define DSM_IMPL_POSIX
Definition: dsm_impl.h:17
int dynamic_shared_memory_type
Definition: dsm_impl.c:114
static int elevel
Definition: vacuumlazy.c:330
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:412
#define Assert(condition)
Definition: c.h:745
#define elog(elevel,...)
Definition: elog.h:214

◆ dsm_impl_pin_segment()

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

Definition at line 952 of file dsm_impl.c.

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

Referenced by dsm_pin_segment().

954 {
956  {
957 #ifdef USE_DSM_WINDOWS
958  case DSM_IMPL_WINDOWS:
959  {
960  HANDLE hmap;
961 
962  if (!DuplicateHandle(GetCurrentProcess(), impl_private,
963  PostmasterHandle, &hmap, 0, FALSE,
964  DUPLICATE_SAME_ACCESS))
965  {
966  char name[64];
967 
968  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
969  _dosmaperr(GetLastError());
970  ereport(ERROR,
972  errmsg("could not duplicate handle for \"%s\": %m",
973  name)));
974  }
975 
976  /*
977  * Here, we remember the handle that we created in the
978  * postmaster process. This handle isn't actually usable in
979  * any process other than the postmaster, but that doesn't
980  * matter. We're just holding onto it so that, if the segment
981  * is unpinned, dsm_impl_unpin_segment can close it.
982  */
983  *impl_private_pm_handle = hmap;
984  break;
985  }
986 #endif
987  default:
988  break;
989  }
990 }
void _dosmaperr(unsigned long)
Definition: win32error.c:171
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:19
static int errcode_for_dynamic_shared_memory(void)
Definition: dsm_impl.c:1034
#define ERROR
Definition: elog.h:43
#define SEGMENT_NAME_PREFIX
Definition: dsm_impl.c:119
int dynamic_shared_memory_type
Definition: dsm_impl.c:114
#define ereport(elevel,...)
Definition: elog.h:144
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define snprintf
Definition: port.h:193

◆ dsm_impl_unpin_segment()

void dsm_impl_unpin_segment ( dsm_handle  handle,
void **  impl_private 
)

Definition at line 1002 of file dsm_impl.c.

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

Referenced by dsm_unpin_segment().

1003 {
1005  {
1006 #ifdef USE_DSM_WINDOWS
1007  case DSM_IMPL_WINDOWS:
1008  {
1009  if (*impl_private &&
1010  !DuplicateHandle(PostmasterHandle, *impl_private,
1011  NULL, NULL, 0, FALSE,
1012  DUPLICATE_CLOSE_SOURCE))
1013  {
1014  char name[64];
1015 
1016  snprintf(name, 64, "%s.%u", SEGMENT_NAME_PREFIX, handle);
1017  _dosmaperr(GetLastError());
1018  ereport(ERROR,
1020  errmsg("could not duplicate handle for \"%s\": %m",
1021  name)));
1022  }
1023 
1024  *impl_private = NULL;
1025  break;
1026  }
1027 #endif
1028  default:
1029  break;
1030  }
1031 }
void _dosmaperr(unsigned long)
Definition: win32error.c:171
#define DSM_IMPL_WINDOWS
Definition: dsm_impl.h:19
static int errcode_for_dynamic_shared_memory(void)
Definition: dsm_impl.c:1034
#define ERROR
Definition: elog.h:43
#define SEGMENT_NAME_PREFIX
Definition: dsm_impl.c:119
int dynamic_shared_memory_type
Definition: dsm_impl.c:114
#define ereport(elevel,...)
Definition: elog.h:144
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define snprintf
Definition: port.h:193

Variable Documentation

◆ dynamic_shared_memory_type

int dynamic_shared_memory_type