diff options
author | Kevin Grittner | 2011-12-24 19:07:13 +0000 |
---|---|---|
committer | Kevin Grittner | 2011-12-25 12:45:17 +0000 |
commit | fad1f23c20e5bd0eb73cb8e124f063ac95cb307d (patch) | |
tree | 5f09164c5acea7fd4f27733c9e34db616ac7008c | |
parent | 046f3f32d769c672c29a74d66e5e00c04728eb53 (diff) |
WIP on background hinting.bghinter
-rw-r--r-- | src/backend/storage/buffer/bufmgr.c | 48 | ||||
-rw-r--r-- | src/include/storage/bufmgr.h | 1 |
2 files changed, 48 insertions, 1 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index bc9c2da427..46daa3c471 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -49,6 +49,10 @@ #include "utils/resowner.h" #include "utils/timestamp.h" +/* Is the buffer in a suitable state for backgroun hinting? */ +#define BufferNeedsHinting(bufHdr) (((BM_DIRTY | BM_VALID | BM_TAG_VALID | BM_IO_IN_PROGRESS) \ + & ((bufHdr)->flags)) \ + == (BM_DIRTY | BM_VALID | BM_TAG_VALID)) /* Note: these two macros only work on shared buffers, not local ones! */ #define BufHdrGetBlock(bufHdr) ((Block) (BufferBlocks + ((Size) (bufHdr)->buf_id) * BLCKSZ)) @@ -1304,13 +1308,55 @@ BufferSync(int flags) } /* - * BgHintBuffers -- hint any dirty buffers that are ripe for it + * BgHintBuffers -- Hint any dirty buffers that are ripe for it. * * TODO: Fill this in. */ void BgHintBuffers(void) { + int buf_id; + + /* Make sure we can handle the pin inside HintOneBuffer */ + ResourceOwnerEnlargeBuffers(CurrentResourceOwner); + + for (buf_id = 0; buf_id < NBuffers; buf_id++) + { + volatile BufferDesc *bufHdr = &BufferDescriptors[buf_id]; + + /* TODO: Is anything special needed here regarding local buffers? */ + + if (!BufferNeedsHinting(bufHdr)) + continue; + + if (!PinBuffer(bufHdr)) + { + /* Buffer was not valid on pin; move on with minimum work. */ + UnpinBuffer(bufHdr, true); + continue; + } + + if (BufferNeedsHinting(bufHdr)) + { + LWLockAcquire(bufHdr->content_lock, LW_SHARED); + HintOneBuffer(BufferDescriptorGetBuffer(bufHdr)); + LWLockRelease(bufHdr->content_lock); + } + + UnpinBuffer(bufHdr, true); + } +} + +/* + * BgHintBuffers -- Set hint bits where possible for a pinned and locked buffer. + * + * Buffer must be pinned and content-locked by caller. + * + * TODO: Fill this in. + */ +void +HintOneBuffer(Buffer buffer) +{ } diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index ee52cbf4fd..fc3c0b177d 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -216,6 +216,7 @@ extern void BufmgrCommit(void); extern void BgBufferSync(void); extern void BgHintBuffers(void); +extern void HintOneBuffer(Buffer buffer); extern void AtProcExit_LocalBuffers(void); |