WIP on background hinting. bghinter
authorKevin Grittner <Kevin.Grittner@wicourts.gov>
Sat, 24 Dec 2011 19:07:13 +0000 (13:07 -0600)
committerKevin Grittner <Kevin.Grittner@wicourts.gov>
Sun, 25 Dec 2011 12:45:17 +0000 (06:45 -0600)
src/backend/storage/buffer/bufmgr.c
src/include/storage/bufmgr.h

index bc9c2da427aa7beaa0d17978dc0e3a3352c9940e..46daa3c471fde19715d992d954e8253a1151b078 100644 (file)
 #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,12 +1308,54 @@ 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)
 {
    
 }
index ee52cbf4fd23fadf8a0c1a1f13ee7b3a583ab629..fc3c0b177ded2519475cb3fcfbfa3c0be9db3b45 100644 (file)
@@ -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);