1996-08-28 01:59:28 +00:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* bufmgr.h--
|
|
|
|
* POSTGRES buffer manager definitions.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1997-08-19 21:40:56 +00:00
|
|
|
* $Id: bufmgr.h,v 1.11 1997/08/19 21:39:45 momjian Exp $
|
1996-08-28 01:59:28 +00:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef BUFMGR_H
|
|
|
|
#define BUFMGR_H
|
|
|
|
|
1996-10-19 06:27:33 +00:00
|
|
|
#include <stdio.h>
|
1996-11-05 06:11:08 +00:00
|
|
|
|
|
|
|
#include <storage/ipc.h>
|
|
|
|
#include <storage/block.h>
|
|
|
|
#include <storage/buf.h>
|
|
|
|
#include <utils/rel.h>
|
1996-08-28 01:59:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the maximum size of a disk block for any possible installation.
|
|
|
|
*
|
|
|
|
* in theory this could be anything, but in practice this is actually
|
|
|
|
* limited to 2^13 bytes because we have limited ItemIdData.lp_off and
|
|
|
|
* ItemIdData.lp_len to 13 bits (see itemid.h).
|
|
|
|
*/
|
|
|
|
#define MAXBLCKSZ 8192
|
|
|
|
|
|
|
|
typedef void *Block;
|
|
|
|
|
|
|
|
|
|
|
|
/* special pageno for bget */
|
|
|
|
#define P_NEW InvalidBlockNumber /* grow the file to get a new page */
|
|
|
|
|
|
|
|
typedef bits16 BufferLock;
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
the rest is function defns in the bufmgr that are externally callable
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These routines are beaten on quite heavily, hence the macroization.
|
|
|
|
* See buf_internals.h for a related comment.
|
|
|
|
*/
|
|
|
|
#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BufferIsPinned --
|
|
|
|
* True iff the buffer is pinned (and therefore valid)
|
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* Smenatics are identical to BufferIsValid
|
|
|
|
* XXX - need to remove either one eventually.
|
|
|
|
*/
|
|
|
|
#define BufferIsPinned BufferIsValid
|
|
|
|
|
|
|
|
|
|
|
|
extern int ShowPinTrace;
|
|
|
|
|
1997-01-16 07:53:27 +00:00
|
|
|
/*
|
|
|
|
* BufferWriteModes (settable via SetBufferWriteMode)
|
|
|
|
*/
|
|
|
|
#define BUFFER_FLUSH_WRITE 0 /* immediate write */
|
|
|
|
#define BUFFER_LATE_WRITE 1 /* delayed write: mark as DIRTY */
|
|
|
|
|
1996-08-28 01:59:28 +00:00
|
|
|
/*
|
|
|
|
* prototypes for functions in bufmgr.c
|
|
|
|
*/
|
|
|
|
extern Buffer RelationGetBufferWithBuffer(Relation relation,
|
|
|
|
BlockNumber blockNumber, Buffer buffer);
|
|
|
|
extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum);
|
|
|
|
extern int WriteBuffer(Buffer buffer);
|
|
|
|
extern int WriteNoReleaseBuffer(Buffer buffer);
|
|
|
|
extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation,
|
|
|
|
BlockNumber blockNum);
|
|
|
|
|
|
|
|
extern void InitBufferPool(IPCKey key);
|
|
|
|
extern void PrintBufferUsage(FILE *statfp);
|
|
|
|
extern void ResetBufferUsage(void);
|
|
|
|
extern void ResetBufferPool(void);
|
|
|
|
extern int BufferPoolCheckLeak(void);
|
|
|
|
extern void FlushBufferPool(int StableMainMemoryFlag);
|
|
|
|
extern bool BufferIsValid(Buffer bufnum);
|
|
|
|
extern BlockNumber BufferGetBlockNumber(Buffer buffer);
|
|
|
|
extern Relation BufferGetRelation(Buffer buffer);
|
|
|
|
extern BlockNumber RelationGetNumberOfBlocks(Relation relation);
|
|
|
|
extern Block BufferGetBlock(Buffer buffer);
|
1997-01-14 05:36:15 +00:00
|
|
|
extern void ReleaseRelationBuffers(Relation rdesc);
|
1996-08-28 01:59:28 +00:00
|
|
|
extern void DropBuffers(Oid dbid);
|
|
|
|
extern void PrintBufferDescs(void);
|
|
|
|
extern void PrintPinnedBufs(void);
|
|
|
|
extern int BufferShmemSize(void);
|
|
|
|
extern void IncrBufferRefCount(Buffer buffer);
|
|
|
|
extern int ReleaseBuffer(Buffer buffer);
|
|
|
|
|
|
|
|
extern void BufferRefCountReset(int *refcountsave);
|
|
|
|
extern void BufferRefCountRestore(int *refcountsave);
|
1997-01-16 07:53:27 +00:00
|
|
|
extern int SetBufferWriteMode (int mode);
|
From: Dan McGuirk <mcguirk@indirect.com>
Reply-To: hackers@hub.org, Dan McGuirk <mcguirk@indirect.com>
To: hackers@hub.org
Subject: [HACKERS] tmin writeback optimization
I was doing some profiling of the backend, and noticed that during a certain
benchmark I was running somewhere between 30% and 75% of the backend's CPU
time was being spent in calls to TransactionIdDidCommit() from
HeapTupleSatisfiesNow() or HeapTupleSatisfiesItself() to determine that
changed rows' transactions had in fact been committed even though the rows'
tmin values had not yet been set.
When a query looks at a given row, it needs to figure out whether the
transaction that changed the row has been committed and hence it should pay
attention to the row, or whether on the other hand the transaction is still
in progress or has been aborted and hence the row should be ignored. If
a tmin value is set, it is known definitively that the row's transaction
has been committed. However, if tmin is not set, the transaction
referred to in xmin must be looked up in pg_log, and this is what the
backend was spending a lot of time doing during my benchmark.
So, implementing a method suggested by Vadim, I created the following
patch that, the first time a query finds a committed row whose tmin value
is not set, sets it, and marks the buffer where the row is stored as
dirty. (It works for tmax, too.) This doesn't result in the boost in
real time performance I was hoping for, however it does decrease backend
CPU usage by up to two-thirds in certain situations, so it could be
rather beneficial in high-concurrency settings.
1997-03-28 07:06:53 +00:00
|
|
|
extern void SetBufferCommitInfoNeedsSave(Buffer buffer);
|
1996-08-28 01:59:28 +00:00
|
|
|
|
|
|
|
#endif /* !defined(BufMgrIncluded) */
|
|
|
|
|