diff options
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/pg_config.h.in | 3 | ||||
| -rw-r--r-- | src/include/portability/mem.h | 40 | ||||
| -rw-r--r-- | src/include/storage/dsm.h | 39 | ||||
| -rw-r--r-- | src/include/storage/dsm_impl.h | 75 | ||||
| -rw-r--r-- | src/include/storage/lwlock.h | 1 | ||||
| -rw-r--r-- | src/include/utils/resowner_private.h | 8 |
6 files changed, 166 insertions, 0 deletions
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 8aabf3c87a4..5eac52d93a9 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -424,6 +424,9 @@ /* Define to 1 if you have the `setsid' function. */ #undef HAVE_SETSID +/* Define to 1 if you have the `shm_open' function. */ +#undef HAVE_SHM_OPEN + /* Define to 1 if you have the `sigprocmask' function. */ #undef HAVE_SIGPROCMASK diff --git a/src/include/portability/mem.h b/src/include/portability/mem.h new file mode 100644 index 00000000000..2a07c10f1ee --- /dev/null +++ b/src/include/portability/mem.h @@ -0,0 +1,40 @@ +/*------------------------------------------------------------------------- + * + * mem.h + * portability definitions for various memory operations + * + * Copyright (c) 2001-2013, PostgreSQL Global Development Group + * + * src/include/portability/mem.h + * + *------------------------------------------------------------------------- + */ +#ifndef MEM_H +#define MEM_H + +#define IPCProtection (0600) /* access/modify by user only */ + +#ifdef SHM_SHARE_MMU /* use intimate shared memory on Solaris */ +#define PG_SHMAT_FLAGS SHM_SHARE_MMU +#else +#define PG_SHMAT_FLAGS 0 +#endif + +/* Linux prefers MAP_ANONYMOUS, but the flag is called MAP_ANON on other systems. */ +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif + +/* BSD-derived systems have MAP_HASSEMAPHORE, but it's not present (or needed) on Linux. */ +#ifndef MAP_HASSEMAPHORE +#define MAP_HASSEMAPHORE 0 +#endif + +#define PG_MMAP_FLAGS (MAP_SHARED|MAP_ANONYMOUS|MAP_HASSEMAPHORE) + +/* Some really old systems don't define MAP_FAILED. */ +#ifndef MAP_FAILED +#define MAP_FAILED ((void *) -1) +#endif + +#endif /* MEM_H */ diff --git a/src/include/storage/dsm.h b/src/include/storage/dsm.h new file mode 100644 index 00000000000..2b5e7227a0e --- /dev/null +++ b/src/include/storage/dsm.h @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + * + * dsm.h + * manage dynamic shared memory segments + * + * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/dsm.h + * + *------------------------------------------------------------------------- + */ +#ifndef DSM_H +#define DSM_H + +#include "storage/dsm_impl.h" + +typedef struct dsm_segment dsm_segment; + +/* Initialization function. */ +extern void dsm_postmaster_startup(void); + +/* Functions that create, update, or remove mappings. */ +extern dsm_segment *dsm_create(uint64 size); +extern dsm_segment *dsm_attach(dsm_handle h); +extern void *dsm_resize(dsm_segment *seg, uint64 size); +extern void *dsm_remap(dsm_segment *seg); +extern void dsm_detach(dsm_segment *seg); + +/* Resource management functions. */ +extern void dsm_keep_mapping(dsm_segment *seg); +extern dsm_segment *dsm_find_mapping(dsm_handle h); + +/* Informational functions. */ +extern void *dsm_segment_address(dsm_segment *seg); +extern uint64 dsm_segment_map_length(dsm_segment *seg); +extern dsm_handle dsm_segment_handle(dsm_segment *seg); + +#endif /* DSM_H */ diff --git a/src/include/storage/dsm_impl.h b/src/include/storage/dsm_impl.h new file mode 100644 index 00000000000..13f1f48b237 --- /dev/null +++ b/src/include/storage/dsm_impl.h @@ -0,0 +1,75 @@ +/*------------------------------------------------------------------------- + * + * dsm_impl.h + * low-level dynamic shared memory primitives + * + * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/dsm_impl.h + * + *------------------------------------------------------------------------- + */ +#ifndef DSM_IMPL_H +#define DSM_IMPL_H + +/* Dynamic shared memory implementations. */ +#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 + +/* + * Determine which dynamic shared memory implementations will be supported + * on this platform, and which one will be the default. + */ +#ifdef WIN32 +#define USE_DSM_WINDOWS +#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_WINDOWS +#else +#ifdef HAVE_SHM_OPEN +#define USE_DSM_POSIX +#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_POSIX +#endif +#define USE_DSM_SYSV +#ifndef DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE +#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_SYSV +#endif +#define USE_DSM_MMAP +#endif + +/* GUC. */ +extern int dynamic_shared_memory_type; + +/* + * Directory for on-disk state. + * + * This is used by all implementations for crash recovery and by the mmap + * implementation for storage. + */ +#define PG_DYNSHMEM_DIR "pg_dynshmem" +#define PG_DYNSHMEM_MMAP_FILE_PREFIX "mmap." + +/* A "name" for a dynamic shared memory segment. */ +typedef uint32 dsm_handle; + +/* All the shared-memory operations we know about. */ +typedef enum +{ + DSM_OP_CREATE, + DSM_OP_ATTACH, + DSM_OP_DETACH, + DSM_OP_RESIZE, + DSM_OP_DESTROY +} dsm_op; + +/* Create, attach to, detach from, resize, or destroy a segment. */ +extern bool dsm_impl_op(dsm_op op, dsm_handle handle, uint64 request_size, + void **impl_private, void **mapped_address, uint64 *mapped_size, + int elevel); + +/* Some implementations cannot resize segments. Can this one? */ +extern bool dsm_impl_can_resize(void); + +#endif /* DSM_IMPL_H */ diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h index 39415a398a6..730c47ba686 100644 --- a/src/include/storage/lwlock.h +++ b/src/include/storage/lwlock.h @@ -80,6 +80,7 @@ typedef enum LWLockId OldSerXidLock, SyncRepLock, BackgroundWorkerLock, + DynamicSharedMemoryControlLock, /* Individual lock IDs end here */ FirstBufMappingLock, FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS, diff --git a/src/include/utils/resowner_private.h b/src/include/utils/resowner_private.h index a5d8707be2f..6693483368b 100644 --- a/src/include/utils/resowner_private.h +++ b/src/include/utils/resowner_private.h @@ -16,6 +16,7 @@ #ifndef RESOWNER_PRIVATE_H #define RESOWNER_PRIVATE_H +#include "storage/dsm.h" #include "storage/fd.h" #include "storage/lock.h" #include "utils/catcache.h" @@ -80,4 +81,11 @@ extern void ResourceOwnerRememberFile(ResourceOwner owner, extern void ResourceOwnerForgetFile(ResourceOwner owner, File file); +/* support for dynamic shared memory management */ +extern void ResourceOwnerEnlargeDSMs(ResourceOwner owner); +extern void ResourceOwnerRememberDSM(ResourceOwner owner, + dsm_segment *); +extern void ResourceOwnerForgetDSM(ResourceOwner owner, + dsm_segment *); + #endif /* RESOWNER_PRIVATE_H */ |
