1
/*-------------------------------------------------------------------------
4
* Internal definitions for buffer manager and the buffer replacement
8
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
9
* Portions Copyright (c) 1994, Regents of the University of California
11
* $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.75.4.1 2005-02-03 23:30:12 tgl Exp $
13
*-------------------------------------------------------------------------
15
#ifndef BUFMGR_INTERNALS_H
16
#define BUFMGR_INTERNALS_H
18
#include "storage/backendid.h"
19
#include "storage/buf.h"
20
#include "storage/lwlock.h"
21
#include "storage/shmem.h"
22
#include "utils/rel.h"
26
* Flags for buffer descriptors
28
#define BM_DIRTY (1 << 0) /* data needs writing */
29
#define BM_VALID (1 << 1) /* data is valid */
30
#define BM_IO_IN_PROGRESS (1 << 2) /* read or write in
32
#define BM_IO_ERROR (1 << 3) /* previous I/O failed */
33
#define BM_JUST_DIRTIED (1 << 4) /* dirtied since write
35
#define BM_PIN_COUNT_WAITER (1 << 5) /* have waiter for sole
38
typedef bits16 BufFlags;
41
* Buffer tag identifies which disk block the buffer contains.
43
* Note: the BufferTag data must be sufficient to determine where to write the
44
* block, without reference to pg_class or pg_tablespace entries. It's
45
* possible that the backend flushing the buffer doesn't even believe the
46
* relation is visible yet (its xact may have started before the xact that
47
* created the rel). The storage manager must be able to cope anyway.
49
* Note: if there's any pad bytes in the struct, INIT_BUFFERTAG will have
50
* to be fixed to zero them, since this struct is used as a hash key.
54
RelFileNode rnode; /* physical relation identifier */
55
BlockNumber blockNum; /* blknum relative to begin of reln */
58
#define CLEAR_BUFFERTAG(a) \
60
(a).rnode.spcNode = InvalidOid, \
61
(a).rnode.dbNode = InvalidOid, \
62
(a).rnode.relNode = InvalidOid, \
63
(a).blockNum = InvalidBlockNumber \
66
#define INIT_BUFFERTAG(a,xx_reln,xx_blockNum) \
68
(a).rnode = (xx_reln)->rd_node, \
69
(a).blockNum = (xx_blockNum) \
72
#define BUFFERTAGS_EQUAL(a,b) \
74
RelFileNodeEquals((a).rnode, (b).rnode) && \
75
(a).blockNum == (b).blockNum \
79
* BufferDesc -- shared descriptor/state data for a single shared buffer.
81
typedef struct sbufdesc
83
Buffer bufNext; /* link in freelist chain */
84
SHMEM_OFFSET data; /* pointer to data in buf pool */
86
/* tag and id must be together for table lookup (still true?) */
87
BufferTag tag; /* file/block identifier */
88
int buf_id; /* buffer's index number (from 0) */
90
BufFlags flags; /* see bit definitions above */
91
unsigned refcount; /* # of backends holding pins on buffer */
93
LWLockId io_in_progress_lock; /* to wait for I/O to complete */
94
LWLockId cntx_lock; /* to lock access to page context */
96
bool cntxDirty; /* new way to mark block as dirty */
99
* We can't physically remove items from a disk page if another
100
* backend has the buffer pinned. Hence, a backend may need to wait
101
* for all other pins to go away. This is signaled by storing its own
102
* backend ID into wait_backend_id and setting flag bit
103
* BM_PIN_COUNT_WAITER. At present, there can be only one such waiter
106
BackendId wait_backend_id; /* backend ID of pin-count waiter */
109
#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
113
extern BufferDesc *BufferDescriptors;
116
extern BufferDesc *LocalBufferDescriptors;
118
/* counters in buf_init.c */
119
extern long int ReadBufferCount;
120
extern long int ReadLocalBufferCount;
121
extern long int BufferHitCount;
122
extern long int LocalBufferHitCount;
123
extern long int BufferFlushCount;
124
extern long int LocalBufferFlushCount;
128
* Internal routines: only called by bufmgr
132
extern BufferDesc *StrategyBufferLookup(BufferTag *tagPtr, bool recheck,
133
int *cdb_found_index);
134
extern BufferDesc *StrategyGetBuffer(int *cdb_replace_index);
135
extern void StrategyReplaceBuffer(BufferDesc *buf, BufferTag *newTag,
136
int cdb_found_index, int cdb_replace_index);
137
extern void StrategyInvalidateBuffer(BufferDesc *buf);
138
extern void StrategyHintVacuum(bool vacuum_active);
139
extern int StrategyDirtyBufferList(BufferDesc **buffers, BufferTag *buftags,
141
extern int StrategyShmemSize(void);
142
extern void StrategyInitialize(bool init);
145
extern int BufTableShmemSize(int size);
146
extern void InitBufTable(int size);
147
extern int BufTableLookup(BufferTag *tagPtr);
148
extern void BufTableInsert(BufferTag *tagPtr, int buf_id);
149
extern void BufTableDelete(BufferTag *tagPtr);
152
extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum,
154
extern void WriteLocalBuffer(Buffer buffer, bool release);
155
extern void AtEOXact_LocalBuffers(bool isCommit);
157
#endif /* BUFMGR_INTERNALS_H */