diff options
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/storage/buf_internals.h | 20 | ||||
| -rw-r--r-- | src/include/storage/lock.h | 14 | ||||
| -rw-r--r-- | src/include/storage/lwlock.h | 21 |
3 files changed, 37 insertions, 18 deletions
diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h index 4effa0d740f..18239176b8e 100644 --- a/src/include/storage/buf_internals.h +++ b/src/include/storage/buf_internals.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.86 2006/03/31 23:32:07 tgl Exp $ + * $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.87 2006/07/23 03:07:58 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -87,6 +87,17 @@ typedef struct buftag ) /* + * The shared buffer mapping table is partitioned to reduce contention. + * To determine which partition lock a given tag requires, compute the tag's + * hash code with BufTableHashCode(), then apply BufMappingPartitionLock(). + * NB: NUM_BUFFER_PARTITIONS must be a power of 2! + */ +#define BufTableHashPartition(hashcode) \ + ((hashcode) % NUM_BUFFER_PARTITIONS) +#define BufMappingPartitionLock(hashcode) \ + ((LWLockId) (FirstBufMappingLock + BufTableHashPartition(hashcode))) + +/* * BufferDesc -- shared descriptor/state data for a single shared buffer. * * Note: buf_hdr_lock must be held to examine or change the tag, flags, @@ -182,9 +193,10 @@ extern void StrategyInitialize(bool init); /* buf_table.c */ extern Size BufTableShmemSize(int size); extern void InitBufTable(int size); -extern int BufTableLookup(BufferTag *tagPtr); -extern int BufTableInsert(BufferTag *tagPtr, int buf_id); -extern void BufTableDelete(BufferTag *tagPtr); +extern uint32 BufTableHashCode(BufferTag *tagPtr); +extern int BufTableLookup(BufferTag *tagPtr, uint32 hashcode); +extern int BufTableInsert(BufferTag *tagPtr, uint32 hashcode, int buf_id); +extern void BufTableDelete(BufferTag *tagPtr, uint32 hashcode); /* localbuf.c */ extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum, diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h index 136299c060d..d471293b702 100644 --- a/src/include/storage/lock.h +++ b/src/include/storage/lock.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.94 2006/03/05 15:58:59 momjian Exp $ + * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.95 2006/07/23 03:07:58 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -19,23 +19,15 @@ #include "storage/shmem.h" -/* - * Number of partitions the shared lock tables are divided into. - * - * See LockTagToPartition() if you change this. - */ -#define NUM_LOCK_PARTITIONS 16 +/* struct PGPROC is declared in proc.h, but must forward-reference it */ +typedef struct PGPROC PGPROC; -/* originally in procq.h */ typedef struct PROC_QUEUE { SHM_QUEUE links; /* head of list of PGPROC objects */ int size; /* number of entries in list */ } PROC_QUEUE; -/* struct PGPROC is declared in proc.h, but must forward-reference it */ -typedef struct PGPROC PGPROC; - /* GUC variables */ extern int max_locks_per_xact; diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h index 47742c02c59..2810326597e 100644 --- a/src/include/storage/lwlock.h +++ b/src/include/storage/lwlock.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.28 2006/05/08 00:00:17 tgl Exp $ + * $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.29 2006/07/23 03:07:58 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -15,6 +15,18 @@ #define LWLOCK_H /* + * It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS + * here, but we need them to set up enum LWLockId correctly, and having + * this file include lock.h or bufmgr.h would be backwards. + */ + +/* Number of partitions of the shared buffer mapping hashtable */ +#define NUM_BUFFER_PARTITIONS 16 + +/* Number of partitions the shared lock tables are divided into */ +#define NUM_LOCK_PARTITIONS 16 + +/* * We have a number of predefined LWLocks, plus a bunch of LWLocks that are * dynamically assigned (e.g., for shared buffers). The LWLock structures * live in shared memory (since they contain shared data) and are identified @@ -25,7 +37,6 @@ */ typedef enum LWLockId { - BufMappingLock, BufFreelistLock, ShmemIndexLock, OidGenLock, @@ -48,7 +59,11 @@ typedef enum LWLockId TwoPhaseStateLock, TablespaceCreateLock, BtreeVacuumLock, - FirstLockMgrLock, /* must be last except for MaxDynamicLWLock */ + FirstBufMappingLock, + FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS, + + /* must be last except for MaxDynamicLWLock: */ + NumFixedLWLocks = FirstLockMgrLock + NUM_LOCK_PARTITIONS, MaxDynamicLWLock = 1000000000 } LWLockId; |
