summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2005-12-06 18:10:06 +0000
committerTom Lane2005-12-06 18:10:06 +0000
commita615acf555c0e9ea6ed1c5398d14b81ff2179e6c (patch)
tree553e5845c030e029e955db1830eed3f8f695a09e /src/include
parent953208a34cbb7585ed4ae782141052461d35739b (diff)
Arrange for read-only accesses to SLRU page buffers to take only a shared
lock, not exclusive, if the desired page is already in memory. This can be demonstrated to be a significant win on the pg_subtrans cache when there is a large window of open transactions. It should be useful for pg_clog as well. I didn't try to make GetMultiXactIdMembers() use the code, as that would have taken some restructuring, and what with the local cache for multixact contents it probably wouldn't really make a difference. Per my recent proposal.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/slru.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/include/access/slru.h b/src/include/access/slru.h
index def801e34a5..62acb43c4e9 100644
--- a/src/include/access/slru.h
+++ b/src/include/access/slru.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.15 2005/11/05 21:19:47 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.16 2005/12/06 18:10:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -46,17 +46,26 @@ typedef struct SlruSharedData
/*
* Info for each buffer slot. Page number is undefined when status is
- * EMPTY. lru_count is essentially the number of page switches since last
- * use of this page; the page with highest lru_count is the best candidate
- * to replace.
+ * EMPTY.
*/
char *page_buffer[NUM_SLRU_BUFFERS];
SlruPageStatus page_status[NUM_SLRU_BUFFERS];
bool page_dirty[NUM_SLRU_BUFFERS];
int page_number[NUM_SLRU_BUFFERS];
- unsigned int page_lru_count[NUM_SLRU_BUFFERS];
+ int page_lru_count[NUM_SLRU_BUFFERS];
LWLockId buffer_locks[NUM_SLRU_BUFFERS];
+ /*----------
+ * We mark a page "most recently used" by setting
+ * page_lru_count[slotno] = ++cur_lru_count;
+ * The oldest page is therefore the one with the highest value of
+ * cur_lru_count - page_lru_count[slotno]
+ * The counts will eventually wrap around, but this calculation still
+ * works as long as no page's age exceeds INT_MAX counts.
+ *----------
+ */
+ int cur_lru_count;
+
/*
* latest_page_number is the page number of the current end of the log;
* this is not critical data, since we use it only to avoid swapping out
@@ -106,6 +115,8 @@ extern void SimpleLruInit(SlruCtl ctl, const char *name,
LWLockId ctllock, const char *subdir);
extern int SimpleLruZeroPage(SlruCtl ctl, int pageno);
extern int SimpleLruReadPage(SlruCtl ctl, int pageno, TransactionId xid);
+extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno,
+ TransactionId xid);
extern void SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata);
extern void SimpleLruFlush(SlruCtl ctl, bool checkpoint);
extern void SimpleLruTruncate(SlruCtl ctl, int cutoffPage);