You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{"payload":{"commit":{"oid":"7f242d880b5b5d9642675517466d31373961cf98","url":"/postgres/postgres/commit/7f242d880b5b5d9642675517466d31373961cf98","authoredDate":"2011-01-29T08:08:41.000-05:00","committedDate":"2011-01-29T08:08:41.000-05:00","shortMessage":null,"shortMessageMarkdown":"\u003cdiv\u003eTry to avoid running with a full fsync request queue.\u003c/div\u003e","shortMessageMarkdownLink":null,"bodyMessageHtml":"When we need to insert a new entry and the queue is full, compact the\nentire queue in the hopes of making room for the new entry. Doing this\non every insertion might worsen contention on BgWriterCommLock, but\nwhen the queue it's full, it's far better than allowing the backend to\nperform its own fsync, per testing by Greg Smith as reported in\n\u003ca href=\"http://archives.postgresql.org/pgsql-hackers/2011-01/msg02665.php\" rel=\"nofollow\"\u003ehttp://archives.postgresql.org/pgsql-hackers/2011-01/msg02665.php\u003c/a\u003e\n\nOriginal idea from Greg Smith. Patch by me. Review by Chris Browne\nand Greg Smith","authors":[{"login":"robertmhaas","displayName":"Robert Haas","avatarUrl":"https://avatars.githubusercontent.com/u/886678?v=4","path":"/robertmhaas","isGitHub":false}],"committerAttribution":false,"committer":{"login":"robertmhaas","displayName":"Robert Haas","avatarUrl":"https://avatars.githubusercontent.com/u/886678?v=4","path":"/robertmhaas","isGitHub":false},"parents":["b2826ad52d72195317a13c2074a5cd002c98a338"],"globalRelayId":"MDY6Q29tbWl0OTI3NDQyOjdmMjQyZDg4MGI1YjVkOTY0MjY3NTUxNzQ2NmQzMTM3Mzk2MWNmOTg=","sha1":"b2826ad52d72195317a13c2074a5cd002c98a338","sha2":"7f242d880b5b5d9642675517466d31373961cf98"},"currentUser":null,"repo":{"id":927442,"defaultBranch":"master","name":"postgres","ownerLogin":"postgres","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2010-09-21T11:35:45.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/177543?v=4","public":true,"private":false,"isOrgOwned":true},"diffEntryData":[{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":181,"text":"@@ -182,6 +182,7 @@ static void CheckArchiveTimeout(void);","html":"@@ -182,6 +182,7 @@ static void CheckArchiveTimeout(void);","displayNoNewLineWarning":false,"position":0,"left":181,"right":181},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":182,"text":" static void BgWriterNap(void);","html":" \u003cspan class=pl-k\u003estatic\u003c/span\u003e \u003cspan class=pl-smi\u003evoid\u003c/span\u003e \u003cspan class=pl-en\u003eBgWriterNap\u003c/span\u003e(\u003cspan class=pl-smi\u003evoid\u003c/span\u003e);","displayNoNewLineWarning":false,"position":1,"left":182,"right":182},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":183,"text":" static bool IsCheckpointOnSchedule(double progress);","html":" \u003cspan class=pl-k\u003estatic\u003c/span\u003e \u003cspan class=pl-smi\u003ebool\u003c/span\u003e \u003cspan class=pl-en\u003eIsCheckpointOnSchedule\u003c/span\u003e(\u003cspan class=pl-smi\u003edouble\u003c/span\u003e \u003cspan class=pl-s1\u003eprogress\u003c/span\u003e);","displayNoNewLineWarning":false,"position":2,"left":183,"right":183},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":184,"text":" static bool ImmediateCheckpointRequested(void);","html":" \u003cspan class=pl-k\u003estatic\u003c/span\u003e \u003cspan class=pl-smi\u003ebool\u003c/span\u003e \u003cspan class=pl-en\u003eImmediateCheckpointRequested\u003c/span\u003e(\u003cspan class=pl-smi\u003evoid\u003c/span\u003e);","displayNoNewLineWarning":false,"position":3,"left":184,"right":184},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":185,"text":"+static bool CompactBgwriterRequestQueue(void);","html":"+\u003cspan class=pl-k\u003estatic\u003c/span\u003e \u003cspan class=pl-smi\u003ebool\u003c/span\u003e \u003cspan class=pl-en\u003eCompactBgwriterRequestQueue\u003c/span\u003e(\u003cspan class=pl-smi\u003evoid\u003c/span\u003e);","displayNoNewLineWarning":false,"position":4,"left":184,"right":185},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":186,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":5,"left":185,"right":186},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":187,"text":" /* Signal handlers */","html":" \u003cspan class=pl-c\u003e/* Signal handlers */\u003c/span\u003e","displayNoNewLineWarning":false,"position":6,"left":186,"right":187},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":188,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":7,"left":187,"right":188},{"stylingDirective":null,"type":"HUNK","blobLineNumber":1064,"text":"@@ -1064,14 +1065,15 @@ RequestCheckpoint(int flags)","html":"@@ -1064,14 +1065,15 @@ RequestCheckpoint(int flags)","displayNoNewLineWarning":false,"position":8,"left":1063,"right":1064},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1065,"text":" * use high values for special flags; that's all internal to md.c, which","html":" \u003cspan class=pl-c\u003e * use high values for special flags; that\u0026#39;s all internal to md.c, which\u003c/span\u003e","displayNoNewLineWarning":false,"position":9,"left":1064,"right":1065},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1066,"text":" * see for details.)","html":" \u003cspan class=pl-c\u003e * see for details.)\u003c/span\u003e","displayNoNewLineWarning":false,"position":10,"left":1065,"right":1066},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1067,"text":" *","html":" \u003cspan class=pl-c\u003e *\u003c/span\u003e","displayNoNewLineWarning":false,"position":11,"left":1066,"right":1067},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1067,"text":"- * If we are unable to pass over the request (at present, this can happen","html":"-\u003cspan class=pl-c\u003e * If we are unable to pass over the request (at present, this can happen\u003c/span\u003e","displayNoNewLineWarning":false,"position":12,"left":1067,"right":1067},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1068,"text":"- * if the shared memory queue is full), we return false. That forces","html":"-\u003cspan class=pl-c\u003e * if the shared memory queue is full), we return false. That forces\u003c/span\u003e","displayNoNewLineWarning":false,"position":13,"left":1068,"right":1067},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1069,"text":"- * the backend to do its own fsync. We hope that will be even more seldom.","html":"-\u003cspan class=pl-c\u003e * the backend to do its own fsync. We hope that will be even more seldom.\u003c/span\u003e","displayNoNewLineWarning":false,"position":14,"left":1069,"right":1067},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1070,"text":"- *","html":"-\u003cspan class=pl-c\u003e *\u003c/span\u003e","displayNoNewLineWarning":false,"position":15,"left":1070,"right":1067},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1071,"text":"- * Note: we presently make no attempt to eliminate duplicate requests","html":"-\u003cspan class=pl-c\u003e * Note: we presently make no attempt to eliminate duplicate requests\u003c/span\u003e","displayNoNewLineWarning":false,"position":16,"left":1071,"right":1067},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1072,"text":"- * in the requests[] queue. The bgwriter will have to eliminate dups","html":"-\u003cspan class=pl-c\u003e * in the requests[] queue. The bgwriter will have to eliminate dups\u003c/span\u003e","displayNoNewLineWarning":false,"position":17,"left":1072,"right":1067},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1073,"text":"- * internally anyway, so we may as well avoid holding the lock longer","html":"-\u003cspan class=pl-c\u003e * internally anyway, so we may as well avoid holding the lock longer\u003c/span\u003e","displayNoNewLineWarning":false,"position":18,"left":1073,"right":1067},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1074,"text":"- * than we have to here.","html":"-\u003cspan class=pl-c\u003e * than we have to here.\u003c/span\u003e","displayNoNewLineWarning":false,"position":19,"left":1074,"right":1067},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1068,"text":"+ * To avoid holding the lock for longer than necessary, we normally write","html":"+\u003cspan class=pl-c\u003e * To avoid holding the lock for longer than necessary, we normally write\u003c/span\u003e","displayNoNewLineWarning":false,"position":20,"left":1074,"right":1068},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1069,"text":"+ * to the requests[] queue without checking for duplicates. The bgwriter","html":"+\u003cspan class=pl-c\u003e * to the requests[] queue without checking for duplicates. The bgwriter\u003c/span\u003e","displayNoNewLineWarning":false,"position":21,"left":1074,"right":1069},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1070,"text":"+ * will have to eliminate dups internally anyway. However, if we discover","html":"+\u003cspan class=pl-c\u003e * will have to eliminate dups internally anyway. However, if we discover\u003c/span\u003e","displayNoNewLineWarning":false,"position":22,"left":1074,"right":1070},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1071,"text":"+ * that the queue is full, we make a pass over the entire queue to compact","html":"+\u003cspan class=pl-c\u003e * that the queue is full, we make a pass over the entire queue to compact\u003c/span\u003e","displayNoNewLineWarning":false,"position":23,"left":1074,"right":1071},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1072,"text":"+ * it. This is somewhat expensive, but the alternative is for the backend","html":"+\u003cspan class=pl-c\u003e * it. This is somewhat expensive, but the alternative is for the backend\u003c/span\u003e","displayNoNewLineWarning":false,"position":24,"left":1074,"right":1072},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1073,"text":"+ * to perform its own fsync, which is far more expensive in practice. It","html":"+\u003cspan class=pl-c\u003e * to perform its own fsync, which is far more expensive in practice. It\u003c/span\u003e","displayNoNewLineWarning":false,"position":25,"left":1074,"right":1073},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1074,"text":"+ * is theoretically possible a backend fsync might still be necessary, if","html":"+\u003cspan class=pl-c\u003e * is theoretically possible a backend fsync might still be necessary, if\u003c/span\u003e","displayNoNewLineWarning":false,"position":26,"left":1074,"right":1074},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1075,"text":"+ * the queue is full and contains no duplicate entries. In that case, we","html":"+\u003cspan class=pl-c\u003e * the queue is full and contains no duplicate entries. In that case, we\u003c/span\u003e","displayNoNewLineWarning":false,"position":27,"left":1074,"right":1075},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1076,"text":"+ * let the backend know by returning false.","html":"+\u003cspan class=pl-c\u003e * let the backend know by returning false.\u003c/span\u003e","displayNoNewLineWarning":false,"position":28,"left":1074,"right":1076},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1077,"text":" */","html":" \u003cspan class=pl-c\u003e */\u003c/span\u003e","displayNoNewLineWarning":false,"position":29,"left":1075,"right":1077},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1078,"text":" bool","html":" \u003cspan class=pl-smi\u003ebool\u003c/span\u003e","displayNoNewLineWarning":false,"position":30,"left":1076,"right":1078},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1079,"text":" ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,","html":" \u003cspan class=pl-en\u003eForwardFsyncRequest\u003c/span\u003e(\u003cspan class=pl-smi\u003eRelFileNodeBackend\u003c/span\u003e \u003cspan class=pl-s1\u003ernode\u003c/span\u003e, \u003cspan class=pl-smi\u003eForkNumber\u003c/span\u003e \u003cspan class=pl-s1\u003eforknum\u003c/span\u003e,","displayNoNewLineWarning":false,"position":31,"left":1077,"right":1079},{"stylingDirective":null,"type":"HUNK","blobLineNumber":1091,"text":"@@ -1090,10 +1092,20 @@ ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,","html":"@@ -1090,10 +1092,20 @@ ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,","displayNoNewLineWarning":false,"position":32,"left":1089,"right":1091},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1092,"text":" \t/* Count all backend writes regardless of if they fit in the queue */","html":" \t\u003cspan class=pl-c\u003e/* Count all backend writes regardless of if they fit in the queue */\u003c/span\u003e","displayNoNewLineWarning":false,"position":33,"left":1090,"right":1092},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1093,"text":" \tBgWriterShmem-\u003enum_backend_writes++;","html":" \t\u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_backend_writes\u003c/span\u003e\u003cspan class=pl-c1\u003e++\u003c/span\u003e;","displayNoNewLineWarning":false,"position":34,"left":1091,"right":1093},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1094,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":35,"left":1092,"right":1094},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1095,"text":"+\t/*","html":"+\t\u003cspan class=pl-c\u003e/*\u003c/span\u003e","displayNoNewLineWarning":false,"position":36,"left":1092,"right":1095},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1096,"text":"+\t * If the background writer isn't running or the request queue is full,","html":"+\u003cspan class=pl-c\u003e\t * If the background writer isn\u0026#39;t running or the request queue is full,\u003c/span\u003e","displayNoNewLineWarning":false,"position":37,"left":1092,"right":1096},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1097,"text":"+\t * the backend will have to perform its own fsync request. But before","html":"+\u003cspan class=pl-c\u003e\t * the backend will have to perform its own fsync request. But before\u003c/span\u003e","displayNoNewLineWarning":false,"position":38,"left":1092,"right":1097},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1098,"text":"+\t * forcing that to happen, we can try to compact the background writer","html":"+\u003cspan class=pl-c\u003e\t * forcing that to happen, we can try to compact the background writer\u003c/span\u003e","displayNoNewLineWarning":false,"position":39,"left":1092,"right":1098},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1099,"text":"+\t * request queue.","html":"+\u003cspan class=pl-c\u003e\t * request queue.\u003c/span\u003e","displayNoNewLineWarning":false,"position":40,"left":1092,"right":1099},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1100,"text":"+\t */","html":"+\u003cspan class=pl-c\u003e\t */\u003c/span\u003e","displayNoNewLineWarning":false,"position":41,"left":1092,"right":1100},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1101,"text":" \tif (BgWriterShmem-\u003ebgwriter_pid == 0 ||","html":" \t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003ebgwriter_pid\u003c/span\u003e \u003cspan class=pl-c1\u003e==\u003c/span\u003e \u003cspan class=pl-c1\u003e0\u003c/span\u003e \u003cspan class=pl-c1\u003e||\u003c/span\u003e","displayNoNewLineWarning":false,"position":42,"left":1093,"right":1101},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1094,"text":"-\t\tBgWriterShmem-\u003enum_requests \u003e= BgWriterShmem-\u003emax_requests)","html":"-\t\t\u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_requests\u003c/span\u003e \u0026gt;= \u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003emax_requests\u003c/span\u003e)","displayNoNewLineWarning":false,"position":43,"left":1094,"right":1101},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1102,"text":"+\t\t(BgWriterShmem-\u003enum_requests \u003e= BgWriterShmem-\u003emax_requests","html":"+\t\t(\u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_requests\u003c/span\u003e \u0026gt;= \u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003emax_requests\u003c/span\u003e","displayNoNewLineWarning":false,"position":44,"left":1094,"right":1102},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1103,"text":"+\t\t\u0026\u0026 !CompactBgwriterRequestQueue()))","html":"+\t\t\u003cspan class=pl-c1\u003e\u0026amp;\u0026amp;\u003c/span\u003e !\u003cspan class=pl-en\u003eCompactBgwriterRequestQueue\u003c/span\u003e()))","displayNoNewLineWarning":false,"position":45,"left":1094,"right":1103},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1104,"text":" \t{","html":" \t{","displayNoNewLineWarning":false,"position":46,"left":1095,"right":1104},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1096,"text":"-\t\t/* Also count the subset where backends have to do their own fsync */","html":"-\t\t\u003cspan class=pl-c\u003e/* Also count the subset where backends have to do their own fsync */\u003c/span\u003e","displayNoNewLineWarning":false,"position":47,"left":1096,"right":1104},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1105,"text":"+\t\t/*","html":"+\t\t\u003cspan class=pl-c\u003e/*\u003c/span\u003e","displayNoNewLineWarning":false,"position":48,"left":1096,"right":1105},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1106,"text":"+\t\t * Count the subset of writes where backends have to do their own","html":"+\u003cspan class=pl-c\u003e\t\t * Count the subset of writes where backends have to do their own\u003c/span\u003e","displayNoNewLineWarning":false,"position":49,"left":1096,"right":1106},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1107,"text":"+\t\t * fsync","html":"+\u003cspan class=pl-c\u003e\t\t * fsync\u003c/span\u003e","displayNoNewLineWarning":false,"position":50,"left":1096,"right":1107},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1108,"text":"+\t\t */","html":"+\u003cspan class=pl-c\u003e\t\t */\u003c/span\u003e","displayNoNewLineWarning":false,"position":51,"left":1096,"right":1108},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1109,"text":" \t\tBgWriterShmem-\u003enum_backend_fsync++;","html":" \t\t\u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_backend_fsync\u003c/span\u003e\u003cspan class=pl-c1\u003e++\u003c/span\u003e;","displayNoNewLineWarning":false,"position":52,"left":1097,"right":1109},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1110,"text":" \t\tLWLockRelease(BgWriterCommLock);","html":" \t\t\u003cspan class=pl-en\u003eLWLockRelease\u003c/span\u003e(\u003cspan class=pl-s1\u003eBgWriterCommLock\u003c/span\u003e);","displayNoNewLineWarning":false,"position":53,"left":1098,"right":1110},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1111,"text":" \t\treturn false;","html":" \t\t\u003cspan class=pl-k\u003ereturn\u003c/span\u003e false;","displayNoNewLineWarning":false,"position":54,"left":1099,"right":1111},{"stylingDirective":null,"type":"HUNK","blobLineNumber":1117,"text":"@@ -1106,6 +1118,108 @@ ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,","html":"@@ -1106,6 +1118,108 @@ ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,","displayNoNewLineWarning":false,"position":55,"left":1105,"right":1117},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1118,"text":" \treturn true;","html":" \t\u003cspan class=pl-k\u003ereturn\u003c/span\u003e true;","displayNoNewLineWarning":false,"position":56,"left":1106,"right":1118},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1119,"text":" }","html":" }","displayNoNewLineWarning":false,"position":57,"left":1107,"right":1119},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1120,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":58,"left":1108,"right":1120},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1121,"text":"+/*","html":"+\u003cspan class=pl-c\u003e/*\u003c/span\u003e","displayNoNewLineWarning":false,"position":59,"left":1108,"right":1121},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1122,"text":"+ * CompactBgwriterRequestQueue","html":"+\u003cspan class=pl-c\u003e * CompactBgwriterRequestQueue\u003c/span\u003e","displayNoNewLineWarning":false,"position":60,"left":1108,"right":1122},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1123,"text":"+ * \t\tRemove duplicates from the request queue to avoid backend fsyncs.","html":"+\u003cspan class=pl-c\u003e * \t\tRemove duplicates from the request queue to avoid backend fsyncs.\u003c/span\u003e","displayNoNewLineWarning":false,"position":61,"left":1108,"right":1123},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1124,"text":"+ *","html":"+\u003cspan class=pl-c\u003e *\u003c/span\u003e","displayNoNewLineWarning":false,"position":62,"left":1108,"right":1124},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1125,"text":"+ * Although a full fsync request queue is not common, it can lead to severe","html":"+\u003cspan class=pl-c\u003e * Although a full fsync request queue is not common, it can lead to severe\u003c/span\u003e","displayNoNewLineWarning":false,"position":63,"left":1108,"right":1125},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1126,"text":"+ * performance problems when it does happen. So far, this situation has","html":"+\u003cspan class=pl-c\u003e * performance problems when it does happen. So far, this situation has\u003c/span\u003e","displayNoNewLineWarning":false,"position":64,"left":1108,"right":1126},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1127,"text":"+ * only been observed to occur when the system is under heavy write load,","html":"+\u003cspan class=pl-c\u003e * only been observed to occur when the system is under heavy write load,\u003c/span\u003e","displayNoNewLineWarning":false,"position":65,"left":1108,"right":1127},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1128,"text":"+ * and especially during the \"sync\" phase of a checkpoint. Without this","html":"+\u003cspan class=pl-c\u003e * and especially during the \u0026quot;sync\u0026quot; phase of a checkpoint. Without this\u003c/span\u003e","displayNoNewLineWarning":false,"position":66,"left":1108,"right":1128},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1129,"text":"+ * logic, each backend begins doing an fsync for every block written, which","html":"+\u003cspan class=pl-c\u003e * logic, each backend begins doing an fsync for every block written, which\u003c/span\u003e","displayNoNewLineWarning":false,"position":67,"left":1108,"right":1129},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1130,"text":"+ * gets very expensive and can slow down the whole system.","html":"+\u003cspan class=pl-c\u003e * gets very expensive and can slow down the whole system.\u003c/span\u003e","displayNoNewLineWarning":false,"position":68,"left":1108,"right":1130},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1131,"text":"+ *","html":"+\u003cspan class=pl-c\u003e *\u003c/span\u003e","displayNoNewLineWarning":false,"position":69,"left":1108,"right":1131},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1132,"text":"+ * Trying to do this every time the queue is full could lose if there","html":"+\u003cspan class=pl-c\u003e * Trying to do this every time the queue is full could lose if there\u003c/span\u003e","displayNoNewLineWarning":false,"position":70,"left":1108,"right":1132},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1133,"text":"+ * aren't any removable entries. But should be vanishingly rare in","html":"+\u003cspan class=pl-c\u003e * aren\u0026#39;t any removable entries. But should be vanishingly rare in\u003c/span\u003e","displayNoNewLineWarning":false,"position":71,"left":1108,"right":1133},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1134,"text":"+ * practice: there's one queue entry per shared buffer.","html":"+\u003cspan class=pl-c\u003e * practice: there\u0026#39;s one queue entry per shared buffer.\u003c/span\u003e","displayNoNewLineWarning":false,"position":72,"left":1108,"right":1134},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1135,"text":"+ */","html":"+\u003cspan class=pl-c\u003e */\u003c/span\u003e","displayNoNewLineWarning":false,"position":73,"left":1108,"right":1135},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1136,"text":"+static bool","html":"+\u003cspan class=pl-k\u003estatic\u003c/span\u003e \u003cspan class=pl-smi\u003ebool\u003c/span\u003e","displayNoNewLineWarning":false,"position":74,"left":1108,"right":1136},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1137,"text":"+CompactBgwriterRequestQueue()","html":"+\u003cspan class=pl-en\u003eCompactBgwriterRequestQueue\u003c/span\u003e()","displayNoNewLineWarning":false,"position":75,"left":1108,"right":1137},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1138,"text":"+{","html":"+{","displayNoNewLineWarning":false,"position":76,"left":1108,"right":1138},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1139,"text":"+\tstruct BgWriterSlotMapping {","html":"+\t\u003cspan class=pl-k\u003estruct\u003c/span\u003e \u003cspan class=pl-smi\u003eBgWriterSlotMapping\u003c/span\u003e {","displayNoNewLineWarning":false,"position":77,"left":1108,"right":1139},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1140,"text":"+\t\tBgWriterRequest\trequest;","html":"+\t\t\u003cspan class=pl-smi\u003eBgWriterRequest\u003c/span\u003e\t\u003cspan class=pl-c1\u003erequest\u003c/span\u003e;","displayNoNewLineWarning":false,"position":78,"left":1108,"right":1140},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1141,"text":"+\t\tint\t\tslot;","html":"+\t\t\u003cspan class=pl-smi\u003eint\u003c/span\u003e\t\t\u003cspan class=pl-c1\u003eslot\u003c/span\u003e;","displayNoNewLineWarning":false,"position":79,"left":1108,"right":1141},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1142,"text":"+\t};","html":"+\t};","displayNoNewLineWarning":false,"position":80,"left":1108,"right":1142},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1143,"text":"+","html":"+","displayNoNewLineWarning":false,"position":81,"left":1108,"right":1143},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1144,"text":"+\tint\t\t\tn,","html":"+\t\u003cspan class=pl-smi\u003eint\u003c/span\u003e\t\t\t\u003cspan class=pl-s1\u003en\u003c/span\u003e,","displayNoNewLineWarning":false,"position":82,"left":1108,"right":1144},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1145,"text":"+\t\t\t\tpreserve_count;","html":"+\t\t\t\t\u003cspan class=pl-s1\u003epreserve_count\u003c/span\u003e;","displayNoNewLineWarning":false,"position":83,"left":1108,"right":1145},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1146,"text":"+\tint\t\t\tnum_skipped = 0;","html":"+\t\u003cspan class=pl-smi\u003eint\u003c/span\u003e\t\t\t\u003cspan class=pl-s1\u003enum_skipped\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-c1\u003e0\u003c/span\u003e;","displayNoNewLineWarning":false,"position":84,"left":1108,"right":1146},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1147,"text":"+\tHASHCTL\t\tctl;","html":"+\t\u003cspan class=pl-smi\u003eHASHCTL\u003c/span\u003e\t\t\u003cspan class=pl-s1\u003ectl\u003c/span\u003e;","displayNoNewLineWarning":false,"position":85,"left":1108,"right":1147},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1148,"text":"+\tHTAB\t *htab;","html":"+\t\u003cspan class=pl-smi\u003eHTAB\u003c/span\u003e\t \u003cspan class=pl-c1\u003e*\u003c/span\u003e\u003cspan class=pl-s1\u003ehtab\u003c/span\u003e;","displayNoNewLineWarning":false,"position":86,"left":1108,"right":1148},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1149,"text":"+\tbool\t *skip_slot;","html":"+\t\u003cspan class=pl-smi\u003ebool\u003c/span\u003e\t \u003cspan class=pl-c1\u003e*\u003c/span\u003e\u003cspan class=pl-s1\u003eskip_slot\u003c/span\u003e;","displayNoNewLineWarning":false,"position":87,"left":1108,"right":1149},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1150,"text":"+","html":"+","displayNoNewLineWarning":false,"position":88,"left":1108,"right":1150},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1151,"text":"+\t/* must hold BgWriterCommLock in exclusive mode */","html":"+\t\u003cspan class=pl-c\u003e/* must hold BgWriterCommLock in exclusive mode */\u003c/span\u003e","displayNoNewLineWarning":false,"position":89,"left":1108,"right":1151},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1152,"text":"+\tAssert(LWLockHeldByMe(BgWriterCommLock));","html":"+\t\u003cspan class=pl-en\u003eAssert\u003c/span\u003e(\u003cspan class=pl-en\u003eLWLockHeldByMe\u003c/span\u003e(\u003cspan class=pl-s1\u003eBgWriterCommLock\u003c/span\u003e));","displayNoNewLineWarning":false,"position":90,"left":1108,"right":1152},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1153,"text":"+","html":"+","displayNoNewLineWarning":false,"position":91,"left":1108,"right":1153},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1154,"text":"+\t/* Initialize temporary hash table */","html":"+\t\u003cspan class=pl-c\u003e/* Initialize temporary hash table */\u003c/span\u003e","displayNoNewLineWarning":false,"position":92,"left":1108,"right":1154},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1155,"text":"+\tMemSet(\u0026ctl, 0, sizeof(ctl));","html":"+\t\u003cspan class=pl-en\u003eMemSet\u003c/span\u003e(\u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e\u003cspan class=pl-s1\u003ectl\u003c/span\u003e, \u003cspan class=pl-c1\u003e0\u003c/span\u003e, \u003cspan class=pl-k\u003esizeof\u003c/span\u003e(\u003cspan class=pl-s1\u003ectl\u003c/span\u003e));","displayNoNewLineWarning":false,"position":93,"left":1108,"right":1155},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1156,"text":"+\tctl.keysize = sizeof(BgWriterRequest);","html":"+\t\u003cspan class=pl-s1\u003ectl\u003c/span\u003e.\u003cspan class=pl-c1\u003ekeysize\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-k\u003esizeof\u003c/span\u003e(\u003cspan class=pl-s1\u003eBgWriterRequest\u003c/span\u003e);","displayNoNewLineWarning":false,"position":94,"left":1108,"right":1156},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1157,"text":"+\tctl.entrysize = sizeof(struct BgWriterSlotMapping);","html":"+\t\u003cspan class=pl-s1\u003ectl\u003c/span\u003e.\u003cspan class=pl-c1\u003eentrysize\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-k\u003esizeof\u003c/span\u003e(\u003cspan class=pl-k\u003estruct\u003c/span\u003e \u003cspan class=pl-smi\u003eBgWriterSlotMapping\u003c/span\u003e);","displayNoNewLineWarning":false,"position":95,"left":1108,"right":1157},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1158,"text":"+\tctl.hash = tag_hash;","html":"+\t\u003cspan class=pl-s1\u003ectl\u003c/span\u003e.\u003cspan class=pl-c1\u003ehash\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-s1\u003etag_hash\u003c/span\u003e;","displayNoNewLineWarning":false,"position":96,"left":1108,"right":1158},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1159,"text":"+\thtab = hash_create(\"CompactBgwriterRequestQueue\",","html":"+\t\u003cspan class=pl-s1\u003ehtab\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-en\u003ehash_create\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026quot;CompactBgwriterRequestQueue\u0026quot;\u003c/span\u003e,","displayNoNewLineWarning":false,"position":97,"left":1108,"right":1159},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1160,"text":"+\t\t\t\t\t BgWriterShmem-\u003enum_requests,","html":"+\t\t\t\t\t \u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_requests\u003c/span\u003e,","displayNoNewLineWarning":false,"position":98,"left":1108,"right":1160},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1161,"text":"+\t\t\t\t\t \u0026ctl,","html":"+\t\t\t\t\t \u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e\u003cspan class=pl-s1\u003ectl\u003c/span\u003e,","displayNoNewLineWarning":false,"position":99,"left":1108,"right":1161},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1162,"text":"+\t\t\t\t\t HASH_ELEM | HASH_FUNCTION);","html":"+\t\t\t\t\t \u003cspan class=pl-c1\u003eHASH_ELEM\u003c/span\u003e | \u003cspan class=pl-c1\u003eHASH_FUNCTION\u003c/span\u003e);","displayNoNewLineWarning":false,"position":100,"left":1108,"right":1162},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1163,"text":"+","html":"+","displayNoNewLineWarning":false,"position":101,"left":1108,"right":1163},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1164,"text":"+\t/* Initialize skip_slot array */","html":"+\t\u003cspan class=pl-c\u003e/* Initialize skip_slot array */\u003c/span\u003e","displayNoNewLineWarning":false,"position":102,"left":1108,"right":1164},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1165,"text":"+\tskip_slot = palloc0(sizeof(bool) * BgWriterShmem-\u003enum_requests);","html":"+\t\u003cspan class=pl-s1\u003eskip_slot\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-en\u003epalloc0\u003c/span\u003e(\u003cspan class=pl-k\u003esizeof\u003c/span\u003e(\u003cspan class=pl-smi\u003ebool\u003c/span\u003e) \u003cspan class=pl-c1\u003e*\u003c/span\u003e \u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_requests\u003c/span\u003e);","displayNoNewLineWarning":false,"position":103,"left":1108,"right":1165},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1166,"text":"+","html":"+","displayNoNewLineWarning":false,"position":104,"left":1108,"right":1166},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1167,"text":"+\t/* ","html":"+\t\u003cspan class=pl-c\u003e/* \u003c/span\u003e","displayNoNewLineWarning":false,"position":105,"left":1108,"right":1167},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1168,"text":"+\t * The basic idea here is that a request can be skipped if it's followed","html":"+\u003cspan class=pl-c\u003e\t * The basic idea here is that a request can be skipped if it\u0026#39;s followed\u003c/span\u003e","displayNoNewLineWarning":false,"position":106,"left":1108,"right":1168},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1169,"text":"+\t * by a later, identical request. It might seem more sensible to work","html":"+\u003cspan class=pl-c\u003e\t * by a later, identical request. It might seem more sensible to work\u003c/span\u003e","displayNoNewLineWarning":false,"position":107,"left":1108,"right":1169},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1170,"text":"+\t * backwards from the end of the queue and check whether a request is","html":"+\u003cspan class=pl-c\u003e\t * backwards from the end of the queue and check whether a request is\u003c/span\u003e","displayNoNewLineWarning":false,"position":108,"left":1108,"right":1170},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1171,"text":"+\t * *preceded* by an earlier, identical request, in the hopes of doing less","html":"+\u003cspan class=pl-c\u003e\t * *preceded* by an earlier, identical request, in the hopes of doing less\u003c/span\u003e","displayNoNewLineWarning":false,"position":109,"left":1108,"right":1171},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1172,"text":"+\t * copying. But that might change the semantics, if there's an","html":"+\u003cspan class=pl-c\u003e\t * copying. But that might change the semantics, if there\u0026#39;s an\u003c/span\u003e","displayNoNewLineWarning":false,"position":110,"left":1108,"right":1172},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1173,"text":"+\t * intervening FORGET_RELATION_FSYNC or FORGET_DATABASE_FSYNC request, so","html":"+\u003cspan class=pl-c\u003e\t * intervening FORGET_RELATION_FSYNC or FORGET_DATABASE_FSYNC request, so\u003c/span\u003e","displayNoNewLineWarning":false,"position":111,"left":1108,"right":1173},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1174,"text":"+\t * we do it this way. It would be possible to be even smarter if we made","html":"+\u003cspan class=pl-c\u003e\t * we do it this way. It would be possible to be even smarter if we made\u003c/span\u003e","displayNoNewLineWarning":false,"position":112,"left":1108,"right":1174},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1175,"text":"+\t * the code below understand the specific semantics of such requests (it","html":"+\u003cspan class=pl-c\u003e\t * the code below understand the specific semantics of such requests (it\u003c/span\u003e","displayNoNewLineWarning":false,"position":113,"left":1108,"right":1175},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1176,"text":"+\t * could blow away preceding entries that would end up being cancelled","html":"+\u003cspan class=pl-c\u003e\t * could blow away preceding entries that would end up being cancelled\u003c/span\u003e","displayNoNewLineWarning":false,"position":114,"left":1108,"right":1176},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1177,"text":"+\t * anyhow), but it's not clear that the extra complexity would buy us","html":"+\u003cspan class=pl-c\u003e\t * anyhow), but it\u0026#39;s not clear that the extra complexity would buy us\u003c/span\u003e","displayNoNewLineWarning":false,"position":115,"left":1108,"right":1177},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1178,"text":"+\t * anything.","html":"+\u003cspan class=pl-c\u003e\t * anything.\u003c/span\u003e","displayNoNewLineWarning":false,"position":116,"left":1108,"right":1178},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1179,"text":"+\t */","html":"+\u003cspan class=pl-c\u003e\t */\u003c/span\u003e","displayNoNewLineWarning":false,"position":117,"left":1108,"right":1179},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1180,"text":"+\tfor (n = 0; n \u003c BgWriterShmem-\u003enum_requests; ++n)","html":"+\t\u003cspan class=pl-k\u003efor\u003c/span\u003e (\u003cspan class=pl-s1\u003en\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-c1\u003e0\u003c/span\u003e; \u003cspan class=pl-s1\u003en\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026lt;\u003c/span\u003e \u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_requests\u003c/span\u003e; \u003cspan class=pl-c1\u003e++\u003c/span\u003e\u003cspan class=pl-s1\u003en\u003c/span\u003e)","displayNoNewLineWarning":false,"position":118,"left":1108,"right":1180},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1181,"text":"+\t{","html":"+\t{","displayNoNewLineWarning":false,"position":119,"left":1108,"right":1181},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1182,"text":"+\t\tBgWriterRequest *request;","html":"+\t\t\u003cspan class=pl-smi\u003eBgWriterRequest\u003c/span\u003e \u003cspan class=pl-c1\u003e*\u003c/span\u003e\u003cspan class=pl-s1\u003erequest\u003c/span\u003e;","displayNoNewLineWarning":false,"position":120,"left":1108,"right":1182},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1183,"text":"+\t\tstruct BgWriterSlotMapping *slotmap;","html":"+\t\t\u003cspan class=pl-k\u003estruct\u003c/span\u003e \u003cspan class=pl-smi\u003eBgWriterSlotMapping\u003c/span\u003e \u003cspan class=pl-c1\u003e*\u003c/span\u003e\u003cspan class=pl-s1\u003eslotmap\u003c/span\u003e;","displayNoNewLineWarning":false,"position":121,"left":1108,"right":1183},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1184,"text":"+\t\tbool\tfound;","html":"+\t\t\u003cspan class=pl-smi\u003ebool\u003c/span\u003e\t\u003cspan class=pl-s1\u003efound\u003c/span\u003e;","displayNoNewLineWarning":false,"position":122,"left":1108,"right":1184},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1185,"text":"+","html":"+","displayNoNewLineWarning":false,"position":123,"left":1108,"right":1185},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1186,"text":"+\t\trequest = \u0026BgWriterShmem-\u003erequests[n];","html":"+\t\t\u003cspan class=pl-s1\u003erequest\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e\u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003erequests\u003c/span\u003e[\u003cspan class=pl-s1\u003en\u003c/span\u003e];","displayNoNewLineWarning":false,"position":124,"left":1108,"right":1186},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1187,"text":"+\t\tslotmap = hash_search(htab, request, HASH_ENTER, \u0026found);","html":"+\t\t\u003cspan class=pl-s1\u003eslotmap\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-en\u003ehash_search\u003c/span\u003e(\u003cspan class=pl-s1\u003ehtab\u003c/span\u003e, \u003cspan class=pl-s1\u003erequest\u003c/span\u003e, \u003cspan class=pl-c1\u003eHASH_ENTER\u003c/span\u003e, \u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e\u003cspan class=pl-s1\u003efound\u003c/span\u003e);","displayNoNewLineWarning":false,"position":125,"left":1108,"right":1187},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1188,"text":"+\t\tif (found)","html":"+\t\t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-s1\u003efound\u003c/span\u003e)","displayNoNewLineWarning":false,"position":126,"left":1108,"right":1188},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1189,"text":"+\t\t{","html":"+\t\t{","displayNoNewLineWarning":false,"position":127,"left":1108,"right":1189},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1190,"text":"+\t\t\tskip_slot[slotmap-\u003eslot] = true;","html":"+\t\t\t\u003cspan class=pl-s1\u003eskip_slot\u003c/span\u003e[\u003cspan class=pl-s1\u003eslotmap\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003eslot\u003c/span\u003e] \u003cspan class=pl-c1\u003e=\u003c/span\u003e true;","displayNoNewLineWarning":false,"position":128,"left":1108,"right":1190},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1191,"text":"+\t\t\t++num_skipped;","html":"+\t\t\t\u003cspan class=pl-c1\u003e++\u003c/span\u003e\u003cspan class=pl-s1\u003enum_skipped\u003c/span\u003e;","displayNoNewLineWarning":false,"position":129,"left":1108,"right":1191},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1192,"text":"+\t\t}","html":"+\t\t}","displayNoNewLineWarning":false,"position":130,"left":1108,"right":1192},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1193,"text":"+\t\tslotmap-\u003eslot = n;","html":"+\t\t\u003cspan class=pl-s1\u003eslotmap\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003eslot\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-s1\u003en\u003c/span\u003e;","displayNoNewLineWarning":false,"position":131,"left":1108,"right":1193},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1194,"text":"+\t}","html":"+\t}","displayNoNewLineWarning":false,"position":132,"left":1108,"right":1194},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1195,"text":"+","html":"+","displayNoNewLineWarning":false,"position":133,"left":1108,"right":1195},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1196,"text":"+\t/* Done with the hash table. */","html":"+\t\u003cspan class=pl-c\u003e/* Done with the hash table. */\u003c/span\u003e","displayNoNewLineWarning":false,"position":134,"left":1108,"right":1196},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1197,"text":"+\thash_destroy(htab);","html":"+\t\u003cspan class=pl-en\u003ehash_destroy\u003c/span\u003e(\u003cspan class=pl-s1\u003ehtab\u003c/span\u003e);","displayNoNewLineWarning":false,"position":135,"left":1108,"right":1197},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1198,"text":"+","html":"+","displayNoNewLineWarning":false,"position":136,"left":1108,"right":1198},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1199,"text":"+\t/* If no duplicates, we're out of luck. */","html":"+\t\u003cspan class=pl-c\u003e/* If no duplicates, we\u0026#39;re out of luck. */\u003c/span\u003e","displayNoNewLineWarning":false,"position":137,"left":1108,"right":1199},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1200,"text":"+\tif (!num_skipped)","html":"+\t\u003cspan class=pl-k\u003eif\u003c/span\u003e (!\u003cspan class=pl-s1\u003enum_skipped\u003c/span\u003e)","displayNoNewLineWarning":false,"position":138,"left":1108,"right":1200},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1201,"text":"+\t{","html":"+\t{","displayNoNewLineWarning":false,"position":139,"left":1108,"right":1201},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1202,"text":"+\t\tpfree(skip_slot);","html":"+\t\t\u003cspan class=pl-en\u003epfree\u003c/span\u003e(\u003cspan class=pl-s1\u003eskip_slot\u003c/span\u003e);","displayNoNewLineWarning":false,"position":140,"left":1108,"right":1202},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1203,"text":"+\t\treturn false;","html":"+\t\t\u003cspan class=pl-k\u003ereturn\u003c/span\u003e false;","displayNoNewLineWarning":false,"position":141,"left":1108,"right":1203},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1204,"text":"+\t}","html":"+\t}","displayNoNewLineWarning":false,"position":142,"left":1108,"right":1204},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1205,"text":"+","html":"+","displayNoNewLineWarning":false,"position":143,"left":1108,"right":1205},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1206,"text":"+\t/* We found some duplicates; remove them. */","html":"+\t\u003cspan class=pl-c\u003e/* We found some duplicates; remove them. */\u003c/span\u003e","displayNoNewLineWarning":false,"position":144,"left":1108,"right":1206},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1207,"text":"+\tfor (n = 0, preserve_count = 0; n \u003c BgWriterShmem-\u003enum_requests; ++n)","html":"+\t\u003cspan class=pl-k\u003efor\u003c/span\u003e (\u003cspan class=pl-s1\u003en\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-c1\u003e0\u003c/span\u003e, \u003cspan class=pl-s1\u003epreserve_count\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-c1\u003e0\u003c/span\u003e; \u003cspan class=pl-s1\u003en\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026lt;\u003c/span\u003e \u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_requests\u003c/span\u003e; \u003cspan class=pl-c1\u003e++\u003c/span\u003e\u003cspan class=pl-s1\u003en\u003c/span\u003e)","displayNoNewLineWarning":false,"position":145,"left":1108,"right":1207},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1208,"text":"+\t{","html":"+\t{","displayNoNewLineWarning":false,"position":146,"left":1108,"right":1208},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1209,"text":"+\t\tif (skip_slot[n])","html":"+\t\t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-s1\u003eskip_slot\u003c/span\u003e[\u003cspan class=pl-s1\u003en\u003c/span\u003e])","displayNoNewLineWarning":false,"position":147,"left":1108,"right":1209},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1210,"text":"+\t\t\tcontinue;","html":"+\t\t\t\u003cspan class=pl-k\u003econtinue\u003c/span\u003e;","displayNoNewLineWarning":false,"position":148,"left":1108,"right":1210},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1211,"text":"+\t\tBgWriterShmem-\u003erequests[preserve_count++] = BgWriterShmem-\u003erequests[n];","html":"+\t\t\u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003erequests\u003c/span\u003e[\u003cspan class=pl-s1\u003epreserve_count\u003c/span\u003e\u003cspan class=pl-c1\u003e++\u003c/span\u003e] \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003erequests\u003c/span\u003e[\u003cspan class=pl-s1\u003en\u003c/span\u003e];","displayNoNewLineWarning":false,"position":149,"left":1108,"right":1211},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1212,"text":"+\t}","html":"+\t}","displayNoNewLineWarning":false,"position":150,"left":1108,"right":1212},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1213,"text":"+\tereport(DEBUG1,","html":"+\t\u003cspan class=pl-en\u003eereport\u003c/span\u003e(\u003cspan class=pl-c1\u003eDEBUG1\u003c/span\u003e,","displayNoNewLineWarning":false,"position":151,"left":1108,"right":1213},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1214,"text":"+\t\t\t(errmsg(\"compacted fsync request queue from %d entries to %d entries\",","html":"+\t\t\t(\u003cspan class=pl-en\u003eerrmsg\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026quot;compacted fsync request queue from %d entries to %d entries\u0026quot;\u003c/span\u003e,","displayNoNewLineWarning":false,"position":152,"left":1108,"right":1214},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1215,"text":"+\t\t\t\tBgWriterShmem-\u003enum_requests, preserve_count)));","html":"+\t\t\t\t\u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_requests\u003c/span\u003e, \u003cspan class=pl-s1\u003epreserve_count\u003c/span\u003e)));","displayNoNewLineWarning":false,"position":153,"left":1108,"right":1215},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1216,"text":"+\tBgWriterShmem-\u003enum_requests = preserve_count;","html":"+\t\u003cspan class=pl-s1\u003eBgWriterShmem\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003enum_requests\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-s1\u003epreserve_count\u003c/span\u003e;","displayNoNewLineWarning":false,"position":154,"left":1108,"right":1216},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1217,"text":"+","html":"+","displayNoNewLineWarning":false,"position":155,"left":1108,"right":1217},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1218,"text":"+\t/* Cleanup. */","html":"+\t\u003cspan class=pl-c\u003e/* Cleanup. */\u003c/span\u003e","displayNoNewLineWarning":false,"position":156,"left":1108,"right":1218},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1219,"text":"+\tpfree(skip_slot);","html":"+\t\u003cspan class=pl-en\u003epfree\u003c/span\u003e(\u003cspan class=pl-s1\u003eskip_slot\u003c/span\u003e);","displayNoNewLineWarning":false,"position":157,"left":1108,"right":1219},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1220,"text":"+\treturn true;","html":"+\t\u003cspan class=pl-k\u003ereturn\u003c/span\u003e true;","displayNoNewLineWarning":false,"position":158,"left":1108,"right":1220},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1221,"text":"+}","html":"+}","displayNoNewLineWarning":false,"position":159,"left":1108,"right":1221},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1222,"text":"+","html":"+","displayNoNewLineWarning":false,"position":160,"left":1108,"right":1222},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1223,"text":" /*","html":" \u003cspan class=pl-c\u003e/*\u003c/span\u003e","displayNoNewLineWarning":false,"position":161,"left":1109,"right":1223},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1224,"text":" * AbsorbFsyncRequests","html":" \u003cspan class=pl-c\u003e * AbsorbFsyncRequests\u003c/span\u003e","displayNoNewLineWarning":false,"position":162,"left":1110,"right":1224},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1225,"text":" *\t\tRetrieve queued fsync requests and pass them to local smgr.","html":" \u003cspan class=pl-c\u003e *\t\tRetrieve queued fsync requests and pass them to local smgr.\u003c/span\u003e","displayNoNewLineWarning":false,"position":163,"left":1111,"right":1225}],"diffNumber":0,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":1281,"linesChanged":134,"newTreeEntry":{"lineCount":1281,"path":"src/backend/postmaster/bgwriter.c","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"src/backend/postmaster/bgwriter.c","mode":100644},"linesAdded":124,"linesDeleted":10,"path":"src/backend/postmaster/bgwriter.c","pathDigest":"3cef80c6226c9e86fe593e87164e2b6e58a87845fb004192ebb407a59a586d4f","status":"MODIFIED","truncatedReason":null,"oldOid":"b2826ad52d72195317a13c2074a5cd002c98a338","newOid":"7f242d880b5b5d9642675517466d31373961cf98","copilotChatReference":null,"deletedSha":"b2826ad52d72195317a13c2074a5cd002c98a338","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null},{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":33,"text":"@@ -34,7 +34,13 @@","html":"@@ -34,7 +34,13 @@","displayNoNewLineWarning":false,"position":0,"left":33,"right":33},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":34,"text":" /* interval for calling AbsorbFsyncRequests in mdsync */","html":" \u003cspan class=pl-c\u003e/* interval for calling AbsorbFsyncRequests in mdsync */\u003c/span\u003e","displayNoNewLineWarning":false,"position":1,"left":34,"right":34},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":35,"text":" #define FSYNCS_PER_ABSORB\t\t10","html":" \u003cspan class=pl-k\u003e#define\u003c/span\u003e \u003cspan class=pl-c1\u003eFSYNCS_PER_ABSORB\u003c/span\u003e\t\t10","displayNoNewLineWarning":false,"position":2,"left":35,"right":35},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":36,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":3,"left":36,"right":36},{"stylingDirective":null,"type":"DELETION","blobLineNumber":37,"text":"-/* special values for the segno arg to RememberFsyncRequest */","html":"-\u003cspan class=pl-c\u003e/* special values for the segno arg to RememberFsyncRequest */\u003c/span\u003e","displayNoNewLineWarning":false,"position":4,"left":37,"right":36},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":37,"text":"+/*","html":"+\u003cspan class=pl-c\u003e/*\u003c/span\u003e","displayNoNewLineWarning":false,"position":5,"left":37,"right":37},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":38,"text":"+ * Special values for the segno arg to RememberFsyncRequest.","html":"+\u003cspan class=pl-c\u003e * Special values for the segno arg to RememberFsyncRequest.\u003c/span\u003e","displayNoNewLineWarning":false,"position":6,"left":37,"right":38},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":39,"text":"+ *","html":"+\u003cspan class=pl-c\u003e *\u003c/span\u003e","displayNoNewLineWarning":false,"position":7,"left":37,"right":39},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":40,"text":"+ * Note that CompactBgwriterRequestQueue assumes that it's OK to remove an","html":"+\u003cspan class=pl-c\u003e * Note that CompactBgwriterRequestQueue assumes that it\u0026#39;s OK to remove an\u003c/span\u003e","displayNoNewLineWarning":false,"position":8,"left":37,"right":40},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":41,"text":"+ * fsync request from the queue if an identical, subsequent request is found.","html":"+\u003cspan class=pl-c\u003e * fsync request from the queue if an identical, subsequent request is found.\u003c/span\u003e","displayNoNewLineWarning":false,"position":9,"left":37,"right":41},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":42,"text":"+ * See comments there before making changes here.","html":"+\u003cspan class=pl-c\u003e * See comments there before making changes here.\u003c/span\u003e","displayNoNewLineWarning":false,"position":10,"left":37,"right":42},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":43,"text":"+ */","html":"+\u003cspan class=pl-c\u003e */\u003c/span\u003e","displayNoNewLineWarning":false,"position":11,"left":37,"right":43},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":44,"text":" #define FORGET_RELATION_FSYNC\t(InvalidBlockNumber)","html":" \u003cspan class=pl-k\u003e#define\u003c/span\u003e \u003cspan class=pl-c1\u003eFORGET_RELATION_FSYNC\u003c/span\u003e\t(InvalidBlockNumber)","displayNoNewLineWarning":false,"position":12,"left":38,"right":44},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":45,"text":" #define FORGET_DATABASE_FSYNC\t(InvalidBlockNumber-1)","html":" \u003cspan class=pl-k\u003e#define\u003c/span\u003e \u003cspan class=pl-c1\u003eFORGET_DATABASE_FSYNC\u003c/span\u003e\t(InvalidBlockNumber-1)","displayNoNewLineWarning":false,"position":13,"left":39,"right":45},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":46,"text":" #define UNLINK_RELATION_REQUEST (InvalidBlockNumber-2)","html":" \u003cspan class=pl-k\u003e#define\u003c/span\u003e \u003cspan class=pl-c1\u003eUNLINK_RELATION_REQUEST\u003c/span\u003e (InvalidBlockNumber-2)","displayNoNewLineWarning":false,"position":14,"left":40,"right":46}],"diffNumber":1,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":1664,"linesChanged":8,"newTreeEntry":{"lineCount":1664,"path":"src/backend/storage/smgr/md.c","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"src/backend/storage/smgr/md.c","mode":100644},"linesAdded":7,"linesDeleted":1,"path":"src/backend/storage/smgr/md.c","pathDigest":"30ebbb2a1d78f03e00b9464c3234529da0eeb1828ce3877750ed7969383bd8a9","status":"MODIFIED","truncatedReason":null,"oldOid":"b2826ad52d72195317a13c2074a5cd002c98a338","newOid":"7f242d880b5b5d9642675517466d31373961cf98","copilotChatReference":null,"deletedSha":"b2826ad52d72195317a13c2074a5cd002c98a338","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null}],"splitViewPreference":"unified","ignoreWhitespace":false,"repoOwnerGlobalRelayId":"MDEyOk9yZ2FuaXphdGlvbjE3NzU0Mw==","commentsPreference":"visible","diffLineSpacingPreference":"relaxed","useMonospaceFont":false,"pasteUrlLinkAsPlainText":false,"userNotices":[],"path":"/postgres/postgres/commit/7f242d880b5b5d9642675517466d31373961cf98","fileTreeExpanded":true,"headerInfo":{"additions":131,"deletions":11,"filesChanged":2,"filesChangedString":"2"},"moreDiffsToLoad":false,"asyncDiffLoadInfo":{"startIndex":2,"truncated":false,"byteCount":6665,"lineShownCount":179},"commentInfo":{"canComment":false,"locked":false,"canLock":false,"repoArchived":false},"csrf_tokens":{"/users/diffview?diff=split":{"post":"-n-LHWHODV1hJE47_5HMRmIqDNAhQw3Q3Orx8MvcSqTx_8hcKlF67E_PylZW0KR97CkJN7njc1RuKJ-OtlHSMw"},"/users/diffview?diff=unified":{"post":"-jHn_YqUMasw3k-mVVcQc4-ARc4Tl2rxKyfr_Ckq-ynxsaS8wQtGGh41y8v8FnhIAYNAKYs3FHWZ5YWCVKdjvg"},"/notifications/thread":{"post":"PcxbF6YcgGX6ctENES85j-GRoTwXsww2q2YpS7S61J2YbKYLjD_sI6wVMHP7PzAbaIOgwQs_7iTNIt_Fpb9OFA"}}},"title":"Try to avoid running with a full fsync request queue. · postgres/postgres@7f242d8","appPayload":{"helpUrl":"https://docs.github.com","findInDiffWorkerPath":"/assets-cdn/worker/find-in-diff-worker-2bfe39677d14.js","enabled_features":{"diff_ux_refresh_beta":false,"diff_inline_comments":true,"diff_ux_refresh_ssr_five":false,"diff_ux_refresh_ssr_ten":false,"react_diff_line_type_character_correction":true}}}
Try to avoid running with a full fsync request queue.
When we need to insert a new entry and the queue is full, compact the
entire queue in the hopes of making room for the new entry. Doing this
on every insertion might worsen contention on BgWriterCommLock, but
when the queue it's full, it's far better than allowing the backend to
perform its own fsync, per testing by Greg Smith as reported in
http://archives.postgresql.org/pgsql-hackers/2011-01/msg02665.php
Original idea from Greg Smith. Patch by me. Review by Chris Browne
and Greg Smith
0 commit comments