Skip to content

Commit 7a315a0

Browse files
committed
Dept. of second thoughts: fix loop in BgBufferSync so that the exit when
bgwriter_lru_maxpages is exceeded leaves the loop variables in the expected state. In the original coding, we'd fail to advance next_to_clean, causing that buffer to be probably-uselessly rechecked next time, and also have an off-by-one idea of the number of buffers scanned.
1 parent 6f5c38d commit 7a315a0

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.225 2007/09/25 20:03:37 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.226 2007/09/25 22:11:48 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1324,10 +1324,17 @@ BgBufferSync(void)
13241324
reusable_buffers = reusable_buffers_est;
13251325

13261326
/* Execute the LRU scan */
1327-
while (num_to_scan-- > 0 && reusable_buffers < upcoming_alloc_est)
1327+
while (num_to_scan > 0 && reusable_buffers < upcoming_alloc_est)
13281328
{
13291329
int buffer_state = SyncOneBuffer(next_to_clean, true);
13301330

1331+
if (++next_to_clean >= NBuffers)
1332+
{
1333+
next_to_clean = 0;
1334+
next_passes++;
1335+
}
1336+
num_to_scan--;
1337+
13311338
if (buffer_state & BUF_WRITTEN)
13321339
{
13331340
reusable_buffers++;
@@ -1339,12 +1346,6 @@ BgBufferSync(void)
13391346
}
13401347
else if (buffer_state & BUF_REUSABLE)
13411348
reusable_buffers++;
1342-
1343-
if (++next_to_clean >= NBuffers)
1344-
{
1345-
next_to_clean = 0;
1346-
next_passes++;
1347-
}
13481349
}
13491350

13501351
BgWriterStats.m_buf_written_clean += num_written;
@@ -1353,7 +1354,7 @@ BgBufferSync(void)
13531354
elog(DEBUG1, "bgwriter: recent_alloc=%u smoothed=%.2f delta=%ld ahead=%d density=%.2f reusable_est=%d upcoming_est=%d scanned=%d wrote=%d reusable=%d",
13541355
recent_alloc, smoothed_alloc, strategy_delta, bufs_ahead,
13551356
smoothed_density, reusable_buffers_est, upcoming_alloc_est,
1356-
bufs_to_lap - num_to_scan - 1,
1357+
bufs_to_lap - num_to_scan,
13571358
num_written,
13581359
reusable_buffers - reusable_buffers_est);
13591360
#endif
@@ -1366,7 +1367,7 @@ BgBufferSync(void)
13661367
* scanning, which is helpful because a long memory isn't as desirable
13671368
* on the density estimates.
13681369
*/
1369-
strategy_delta = bufs_to_lap - num_to_scan - 1;
1370+
strategy_delta = bufs_to_lap - num_to_scan;
13701371
recent_alloc = reusable_buffers - reusable_buffers_est;
13711372
if (strategy_delta > 0 && recent_alloc > 0)
13721373
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy