1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* shmem.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* shared memory management structures
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2008-11-02 22:24:52 +01:00
|
|
|
* Historical note:
|
|
|
|
* A long time ago, Postgres' shared memory region was allowed to be mapped
|
|
|
|
* at a different address in each process, and shared memory "pointers" were
|
|
|
|
* passed around as offsets relative to the start of the shared memory region.
|
|
|
|
* That is no longer the case: each process must map the shared memory region
|
|
|
|
* at the same address. This means shared memory pointers can be passed
|
|
|
|
* around directly between different processes.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2015-01-06 17:43:47 +01:00
|
|
|
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/storage/shmem.h
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef SHMEM_H
|
1996-08-28 03:59:28 +02:00
|
|
|
#define SHMEM_H
|
|
|
|
|
1999-07-16 19:07:40 +02:00
|
|
|
#include "utils/hsearch.h"
|
1996-11-05 07:11:08 +01:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2002-08-17 15:04:19 +02:00
|
|
|
/* shmqueue.c */
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct SHM_QUEUE
|
|
|
|
{
|
2008-11-02 22:24:52 +01:00
|
|
|
struct SHM_QUEUE *prev;
|
|
|
|
struct SHM_QUEUE *next;
|
1997-09-08 23:56:23 +02:00
|
|
|
} SHM_QUEUE;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* shmem.c */
|
2006-01-04 22:06:32 +01:00
|
|
|
extern void InitShmemAccess(void *seghdr);
|
|
|
|
extern void InitShmemAllocation(void);
|
2000-06-28 05:33:33 +02:00
|
|
|
extern void *ShmemAlloc(Size size);
|
Implement genuine serializable isolation level.
Until now, our Serializable mode has in fact been what's called Snapshot
Isolation, which allows some anomalies that could not occur in any
serialized ordering of the transactions. This patch fixes that using a
method called Serializable Snapshot Isolation, based on research papers by
Michael J. Cahill (see README-SSI for full references). In Serializable
Snapshot Isolation, transactions run like they do in Snapshot Isolation,
but a predicate lock manager observes the reads and writes performed and
aborts transactions if it detects that an anomaly might occur. This method
produces some false positives, ie. it sometimes aborts transactions even
though there is no anomaly.
To track reads we implement predicate locking, see storage/lmgr/predicate.c.
Whenever a tuple is read, a predicate lock is acquired on the tuple. Shared
memory is finite, so when a transaction takes many tuple-level locks on a
page, the locks are promoted to a single page-level lock, and further to a
single relation level lock if necessary. To lock key values with no matching
tuple, a sequential scan always takes a relation-level lock, and an index
scan acquires a page-level lock that covers the search key, whether or not
there are any matching keys at the moment.
A predicate lock doesn't conflict with any regular locks or with another
predicate locks in the normal sense. They're only used by the predicate lock
manager to detect the danger of anomalies. Only serializable transactions
participate in predicate locking, so there should be no extra overhead for
for other transactions.
Predicate locks can't be released at commit, but must be remembered until
all the transactions that overlapped with it have completed. That means that
we need to remember an unbounded amount of predicate locks, so we apply a
lossy but conservative method of tracking locks for committed transactions.
If we run short of shared memory, we overflow to a new "pg_serial" SLRU
pool.
We don't currently allow Serializable transactions in Hot Standby mode.
That would be hard, because even read-only transactions can cause anomalies
that wouldn't otherwise occur.
Serializable isolation mode now means the new fully serializable level.
Repeatable Read gives you the old Snapshot Isolation level that we have
always had.
Kevin Grittner and Dan Ports, reviewed by Jeff Davis, Heikki Linnakangas and
Anssi Kääriäinen
2011-02-07 22:46:51 +01:00
|
|
|
extern bool ShmemAddrIsValid(const void *addr);
|
2001-09-29 06:02:27 +02:00
|
|
|
extern void InitShmemIndex(void);
|
2001-10-05 19:28:13 +02:00
|
|
|
extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
|
1997-09-08 23:56:23 +02:00
|
|
|
HASHCTL *infoP, int hash_flags);
|
2001-10-05 19:28:13 +02:00
|
|
|
extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
|
2005-08-21 01:26:37 +02:00
|
|
|
extern Size add_size(Size s1, Size s2);
|
|
|
|
extern Size mul_size(Size s1, Size s2);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2006-10-16 00:04:08 +02:00
|
|
|
/* ipci.c */
|
|
|
|
extern void RequestAddinShmemSpace(Size size);
|
|
|
|
|
1998-06-27 17:47:48 +02:00
|
|
|
/* size constants for the shmem index table */
|
1997-09-07 07:04:48 +02:00
|
|
|
/* max size of data structure string name */
|
2001-10-01 07:36:17 +02:00
|
|
|
#define SHMEM_INDEX_KEYSIZE (48)
|
2008-11-02 22:24:52 +01:00
|
|
|
/* estimated size of the shmem index table (not a hard limit) */
|
2011-03-31 12:37:01 +02:00
|
|
|
#define SHMEM_INDEX_SIZE (64)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-06-27 17:47:48 +02:00
|
|
|
/* this is a hash bucket in the shmem index table */
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
char key[SHMEM_INDEX_KEYSIZE]; /* string name */
|
2009-06-11 16:49:15 +02:00
|
|
|
void *location; /* location in shared mem */
|
|
|
|
Size size; /* # bytes allocated for the structure */
|
1999-05-26 00:43:53 +02:00
|
|
|
} ShmemIndexEnt;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions in shmqueue.c
|
|
|
|
*/
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void SHMQueueInit(SHM_QUEUE *queue);
|
|
|
|
extern void SHMQueueElemInit(SHM_QUEUE *queue);
|
|
|
|
extern void SHMQueueDelete(SHM_QUEUE *queue);
|
2001-01-22 23:30:06 +01:00
|
|
|
extern void SHMQueueInsertBefore(SHM_QUEUE *queue, SHM_QUEUE *elem);
|
2011-03-06 23:49:16 +01:00
|
|
|
extern void SHMQueueInsertAfter(SHM_QUEUE *queue, SHM_QUEUE *elem);
|
Implement genuine serializable isolation level.
Until now, our Serializable mode has in fact been what's called Snapshot
Isolation, which allows some anomalies that could not occur in any
serialized ordering of the transactions. This patch fixes that using a
method called Serializable Snapshot Isolation, based on research papers by
Michael J. Cahill (see README-SSI for full references). In Serializable
Snapshot Isolation, transactions run like they do in Snapshot Isolation,
but a predicate lock manager observes the reads and writes performed and
aborts transactions if it detects that an anomaly might occur. This method
produces some false positives, ie. it sometimes aborts transactions even
though there is no anomaly.
To track reads we implement predicate locking, see storage/lmgr/predicate.c.
Whenever a tuple is read, a predicate lock is acquired on the tuple. Shared
memory is finite, so when a transaction takes many tuple-level locks on a
page, the locks are promoted to a single page-level lock, and further to a
single relation level lock if necessary. To lock key values with no matching
tuple, a sequential scan always takes a relation-level lock, and an index
scan acquires a page-level lock that covers the search key, whether or not
there are any matching keys at the moment.
A predicate lock doesn't conflict with any regular locks or with another
predicate locks in the normal sense. They're only used by the predicate lock
manager to detect the danger of anomalies. Only serializable transactions
participate in predicate locking, so there should be no extra overhead for
for other transactions.
Predicate locks can't be released at commit, but must be remembered until
all the transactions that overlapped with it have completed. That means that
we need to remember an unbounded amount of predicate locks, so we apply a
lossy but conservative method of tracking locks for committed transactions.
If we run short of shared memory, we overflow to a new "pg_serial" SLRU
pool.
We don't currently allow Serializable transactions in Hot Standby mode.
That would be hard, because even read-only transactions can cause anomalies
that wouldn't otherwise occur.
Serializable isolation mode now means the new fully serializable level.
Repeatable Read gives you the old Snapshot Isolation level that we have
always had.
Kevin Grittner and Dan Ports, reviewed by Jeff Davis, Heikki Linnakangas and
Anssi Kääriäinen
2011-02-07 22:46:51 +01:00
|
|
|
extern Pointer SHMQueueNext(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
|
2001-03-22 05:01:46 +01:00
|
|
|
Size linkOffset);
|
2011-03-06 23:49:16 +01:00
|
|
|
extern Pointer SHMQueuePrev(const SHM_QUEUE *queue, const SHM_QUEUE *curElem,
|
|
|
|
Size linkOffset);
|
Implement genuine serializable isolation level.
Until now, our Serializable mode has in fact been what's called Snapshot
Isolation, which allows some anomalies that could not occur in any
serialized ordering of the transactions. This patch fixes that using a
method called Serializable Snapshot Isolation, based on research papers by
Michael J. Cahill (see README-SSI for full references). In Serializable
Snapshot Isolation, transactions run like they do in Snapshot Isolation,
but a predicate lock manager observes the reads and writes performed and
aborts transactions if it detects that an anomaly might occur. This method
produces some false positives, ie. it sometimes aborts transactions even
though there is no anomaly.
To track reads we implement predicate locking, see storage/lmgr/predicate.c.
Whenever a tuple is read, a predicate lock is acquired on the tuple. Shared
memory is finite, so when a transaction takes many tuple-level locks on a
page, the locks are promoted to a single page-level lock, and further to a
single relation level lock if necessary. To lock key values with no matching
tuple, a sequential scan always takes a relation-level lock, and an index
scan acquires a page-level lock that covers the search key, whether or not
there are any matching keys at the moment.
A predicate lock doesn't conflict with any regular locks or with another
predicate locks in the normal sense. They're only used by the predicate lock
manager to detect the danger of anomalies. Only serializable transactions
participate in predicate locking, so there should be no extra overhead for
for other transactions.
Predicate locks can't be released at commit, but must be remembered until
all the transactions that overlapped with it have completed. That means that
we need to remember an unbounded amount of predicate locks, so we apply a
lossy but conservative method of tracking locks for committed transactions.
If we run short of shared memory, we overflow to a new "pg_serial" SLRU
pool.
We don't currently allow Serializable transactions in Hot Standby mode.
That would be hard, because even read-only transactions can cause anomalies
that wouldn't otherwise occur.
Serializable isolation mode now means the new fully serializable level.
Repeatable Read gives you the old Snapshot Isolation level that we have
always had.
Kevin Grittner and Dan Ports, reviewed by Jeff Davis, Heikki Linnakangas and
Anssi Kääriäinen
2011-02-07 22:46:51 +01:00
|
|
|
extern bool SHMQueueEmpty(const SHM_QUEUE *queue);
|
|
|
|
extern bool SHMQueueIsDetached(const SHM_QUEUE *queue);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* SHMEM_H */
|