Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/fsck_lfs Buffer cache fixes: make sure we initialize al...



details:   https://anonhg.NetBSD.org/src/rev/b0a687e79461
branches:  trunk
changeset: 579597:b0a687e79461
user:      perseant <perseant%NetBSD.org@localhost>
date:      Sat Mar 19 00:43:17 2005 +0000

description:
Buffer cache fixes: make sure we initialize all the hash lists, and allow
the cache to grow in size irrespective of how many buffers may be in the
locked queue, since we can't write those in any case.  Prevents fsck_lfs
from spinning when it has too much to write.

diffstat:

 sbin/fsck_lfs/bufcache.c |  14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diffs (65 lines):

diff -r aac08033ca47 -r b0a687e79461 sbin/fsck_lfs/bufcache.c
--- a/sbin/fsck_lfs/bufcache.c  Fri Mar 18 23:53:57 2005 +0000
+++ b/sbin/fsck_lfs/bufcache.c  Sat Mar 19 00:43:17 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bufcache.c,v 1.3 2005/02/26 05:45:54 perseant Exp $ */
+/* $NetBSD: bufcache.c,v 1.4 2005/03/19 00:43:17 perseant Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -73,6 +73,7 @@
 int cachemisses = 0;
 int hashmax = 0;
 off_t locked_queue_bytes = 0;
+int locked_queue_count = 0;
 
 /* Simple buffer hash function */
 static int
@@ -91,7 +92,7 @@
                TAILQ_INIT(&bufqueues[i]);
        }
        for (i = 0; i < HASH_MAX; i++)
-               LIST_INIT(&bufhash[HASH_MAX]);
+               LIST_INIT(&bufhash[i]);
 }
 
 /* Print statistics of buffer cache usage */
@@ -134,6 +135,7 @@
         */
        if (bp->b_flags & B_LOCKED) {
                locked_queue_bytes -= bp->b_bcount;
+               --locked_queue_count;
        }
        if (TAILQ_NEXT(bp, b_freelist) == NULL) {
                for (dp = bufqueues; dp < &bufqueues[BQUEUES]; dp++)
@@ -195,7 +197,7 @@
         * If not enough space, free blocks from the AGE and LRU lists
         * to make room.
         */
-       while (nbufs >= maxbufs) {
+       while (nbufs >= maxbufs + locked_queue_count) {
                bp = TAILQ_FIRST(&bufqueues[BQ_AGE]);
                if (bp)
                        TAILQ_REMOVE(&bufqueues[BQ_AGE], bp, b_freelist);
@@ -212,10 +214,11 @@
                }
 #ifdef DEBUG
                else {
-                       if (!warned)
+                       if (!warned) {
                                warnx("allocating more than %d buffers",
                                        maxbufs);
-                       ++warned;
+                               ++warned;
+                       }
                        break;
                }
 #endif
@@ -264,6 +267,7 @@
        }
        if (bp->b_flags & B_LOCKED) {
                locked_queue_bytes += bp->b_bcount;
+               ++locked_queue_count;
                TAILQ_INSERT_TAIL(&bufqueues[BQ_LOCKED], bp, b_freelist);
        } else if (age) {
                TAILQ_INSERT_TAIL(&bufqueues[BQ_AGE], bp, b_freelist);



Home | Main Index | Thread Index | Old Index