1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Implement new 'lightweight lock manager' that's intermediate between

existing lock manager and spinlocks: it understands exclusive vs shared
lock but has few other fancy features.  Replace most uses of spinlocks
with lightweight locks.  All remaining uses of spinlocks have very short
lock hold times (a few dozen instructions), so tweak spinlock backoff
code to work efficiently given this assumption.  All per my proposal on
pghackers 26-Sep-01.
This commit is contained in:
Tom Lane
2001-09-29 04:02:27 +00:00
parent 818fb55ac4
commit 499abb0c0f
46 changed files with 1595 additions and 1355 deletions

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: proc.h,v 1.47 2001/09/21 17:06:12 tgl Exp $
* $Id: proc.h,v 1.48 2001/09/29 04:02:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -16,10 +16,9 @@
#include "access/xlog.h"
#include "storage/backendid.h"
#include "storage/ipc.h"
#include "storage/lock.h"
/* configurable option */
extern int DeadlockTimeout;
typedef struct
{
@ -35,10 +34,9 @@ typedef struct
* the PROC is linked into that lock's waitProcs queue. A recycled PROC
* is linked into ProcGlobal's freeProcs list.
*/
struct proc
struct PROC
{
/* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
SHM_QUEUE links; /* list link if process is in a list */
SEMA sem; /* ONE semaphore to sleep on */
@ -51,6 +49,9 @@ struct proc
* were starting our xact: vacuum must not
* remove tuples deleted by xid >= xmin ! */
int pid; /* This backend's process id */
Oid databaseId; /* OID of database this backend is using */
/*
* XLOG location of first XLOG record written by this backend's
* current transaction. If backend is not in a transaction or hasn't
@ -58,6 +59,11 @@ struct proc
*/
XLogRecPtr logRec;
/* Info about LWLock the process is currently waiting for, if any. */
bool lwWaiting; /* true if waiting for an LW lock */
bool lwExclusive; /* true if waiting for exclusive access */
struct PROC *lwWaitLink; /* next waiter for same LW lock */
/* Info about lock the process is currently waiting for, if any. */
/* waitLock and waitHolder are NULL if not currently waiting. */
LOCK *waitLock; /* Lock object we're sleeping on ... */
@ -66,32 +72,15 @@ struct proc
LOCKMASK heldLocks; /* bitmask for lock types already held on
* this lock object by this backend */
int pid; /* This backend's process id */
Oid databaseId; /* OID of database this backend is using */
short sLocks[MAX_SPINS]; /* Spin lock stats */
SHM_QUEUE procHolders; /* list of HOLDER objects for locks held
* or awaited by this backend */
};
/* NOTE: "typedef struct proc PROC" appears in storage/lock.h. */
/* NOTE: "typedef struct PROC PROC" appears in storage/lock.h. */
extern PROC *MyProc;
extern SPINLOCK ProcStructLock;
#define PROC_INCR_SLOCK(lock) \
do { \
if (MyProc) (MyProc->sLocks[(lock)])++; \
} while (0)
#define PROC_DECR_SLOCK(lock) \
do { \
if (MyProc) (MyProc->sLocks[(lock)])--; \
} while (0)
/*
* There is one ProcGlobal struct for the whole installation.
@ -120,7 +109,7 @@ typedef struct
*/
} SEM_MAP_ENTRY;
typedef struct procglobal
typedef struct PROC_HDR
{
/* Head of list of free PROC structures */
SHMEM_OFFSET freeProcs;
@ -134,11 +123,17 @@ typedef struct procglobal
SEM_MAP_ENTRY procSemMap[1];
} PROC_HDR;
/* configurable option */
extern int DeadlockTimeout;
/*
* Function Prototypes
*/
extern void InitProcGlobal(int maxBackends);
extern void InitProcess(void);
extern void InitDummyProcess(void);
extern void ProcReleaseLocks(bool isCommit);
extern void ProcQueueInit(PROC_QUEUE *queue);
@ -146,7 +141,6 @@ extern int ProcSleep(LOCKMETHODTABLE *lockMethodTable, LOCKMODE lockmode,
LOCK *lock, HOLDER *holder);
extern PROC *ProcWakeup(PROC *proc, int errType);
extern void ProcLockWakeup(LOCKMETHODTABLE *lockMethodTable, LOCK *lock);
extern void ProcReleaseSpins(PROC *proc);
extern bool LockWaitCancel(void);
extern void HandleDeadLock(SIGNAL_ARGS);