pg_shmem.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pg_shmem.h
  4. * Platform-independent API for shared memory support.
  5. *
  6. * Every port is expected to support shared memory with approximately
  7. * SysV-ish semantics; in particular, a memory block is not anonymous
  8. * but has an ID, and we must be able to tell whether there are any
  9. * remaining processes attached to a block of a specified ID.
  10. *
  11. * To simplify life for the SysV implementation, the ID is assumed to
  12. * consist of two unsigned long values (these are key and ID in SysV
  13. * terms). Other platforms may ignore the second value if they need
  14. * only one ID number.
  15. *
  16. *
  17. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  18. * Portions Copyright (c) 1994, Regents of the University of California
  19. *
  20. * src/include/storage/pg_shmem.h
  21. *
  22. *-------------------------------------------------------------------------
  23. */
  24. #ifndef PG_SHMEM_H
  25. #define PG_SHMEM_H
  26. #include "storage/dsm_impl.h"
  27. typedef struct PGShmemHeader /* standard header for all Postgres shmem */
  28. {
  29. int32 magic; /* magic # to identify Postgres segments */
  30. #define PGShmemMagic 679834894
  31. pid_t creatorPID; /* PID of creating process (set but unread) */
  32. Size totalsize; /* total size of segment */
  33. Size freeoffset; /* offset to first free space */
  34. dsm_handle dsm_control; /* ID of dynamic shared memory control seg */
  35. void *index; /* pointer to ShmemIndex table */
  36. #ifndef WIN32 /* Windows doesn't have useful inode#s */
  37. dev_t device; /* device data directory is on */
  38. ino_t inode; /* inode number of data directory */
  39. #endif
  40. } PGShmemHeader;
  41. /* GUC variables */
  42. extern PGDLLIMPORT int shared_memory_type;
  43. extern PGDLLIMPORT int huge_pages;
  44. extern PGDLLIMPORT int huge_page_size;
  45. /* Possible values for huge_pages */
  46. typedef enum
  47. {
  48. HUGE_PAGES_OFF,
  49. HUGE_PAGES_ON,
  50. HUGE_PAGES_TRY
  51. } HugePagesType;
  52. /* Possible values for shared_memory_type */
  53. typedef enum
  54. {
  55. SHMEM_TYPE_WINDOWS,
  56. SHMEM_TYPE_SYSV,
  57. SHMEM_TYPE_MMAP
  58. } PGShmemType;
  59. #ifndef WIN32
  60. extern PGDLLIMPORT unsigned long UsedShmemSegID;
  61. #else
  62. extern PGDLLIMPORT HANDLE UsedShmemSegID;
  63. extern PGDLLIMPORT void *ShmemProtectiveRegion;
  64. #endif
  65. extern PGDLLIMPORT void *UsedShmemSegAddr;
  66. #if !defined(WIN32) && !defined(EXEC_BACKEND)
  67. #define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_MMAP
  68. #elif !defined(WIN32)
  69. #define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_SYSV
  70. #else
  71. #define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_WINDOWS
  72. #endif
  73. #ifdef EXEC_BACKEND
  74. extern void PGSharedMemoryReAttach(void);
  75. extern void PGSharedMemoryNoReAttach(void);
  76. #endif
  77. extern PGShmemHeader *PGSharedMemoryCreate(Size size,
  78. PGShmemHeader **shim);
  79. extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);
  80. extern void PGSharedMemoryDetach(void);
  81. extern void GetHugePageSize(Size *hugepagesize, int *mmap_flags);
  82. #endif /* PG_SHMEM_H */