Source-Changes-HG archive

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

[src/netbsd-2-0]: src/sys/kern Pullup rev 1.133-1.136 (requested by simonb in...



details:   https://anonhg.NetBSD.org/src/rev/d62ea2b9a4ba
branches:  netbsd-2-0
changeset: 562779:d62ea2b9a4ba
user:      jmc <jmc%NetBSD.org@localhost>
date:      Fri Oct 08 03:25:15 2004 +0000

description:
Pullup rev 1.133-1.136 (requested by simonb in ticket #908)

- Dont let pagedaemon sleep while draining buf.
- Estimate amount of memory to free at a time.
- Factor out code to set watermark and ensure high > low.
- Make the step of allocation possibility a bit seamless by moving the origin
  of curve from 0 to lowater mark.
Improves interactive performance when there is heavy disk activity.
PR#27057

diffstat:

 sys/kern/vfs_bio.c |  70 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 42 insertions(+), 28 deletions(-)

diffs (142 lines):

diff -r 355ef3f61af9 -r d62ea2b9a4ba sys/kern/vfs_bio.c
--- a/sys/kern/vfs_bio.c        Fri Oct 08 03:21:40 2004 +0000
+++ b/sys/kern/vfs_bio.c        Fri Oct 08 03:25:15 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_bio.c,v 1.122.2.3 2004/06/22 09:01:03 tron Exp $   */
+/*     $NetBSD: vfs_bio.c,v 1.122.2.4 2004/10/08 03:25:15 jmc Exp $    */
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -81,7 +81,7 @@
 #include "opt_softdep.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.122.2.3 2004/06/22 09:01:03 tron Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.122.2.4 2004/10/08 03:25:15 jmc Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -226,6 +226,7 @@
        return 0;
 }
 
+static void buf_setwm(void);
 static int buf_trim(void);
 
 /*
@@ -242,6 +243,20 @@
 #define        binsheadfree(bp, dp)    TAILQ_INSERT_HEAD(dp, bp, b_freelist)
 #define        binstailfree(bp, dp)    TAILQ_INSERT_TAIL(dp, bp, b_freelist)
 
+static void
+buf_setwm(void)
+{
+
+       bufmem_hiwater = buf_memcalc();
+       /* lowater is approx. 2% of memory (with bufcache = 15) */
+#define        BUFMEM_WMSHIFT  3
+#define        BUFMEM_HIWMMIN  (64 * 1024 << BUFMEM_WMSHIFT)
+       if (bufmem_hiwater < BUFMEM_HIWMMIN)
+               /* Ensure a reasonable minimum value */
+               bufmem_hiwater = BUFMEM_HIWMMIN;
+       bufmem_lowater = bufmem_hiwater >> BUFMEM_WMSHIFT;
+}
+
 #ifdef DEBUG
 int debug_verify_freelist = 0;
 static int checkfreelist(struct buf *bp, struct bqueues *dp)
@@ -337,12 +352,7 @@
         * Initialize buffer cache memory parameters.
         */
        bufmem = 0;
-       bufmem_hiwater = buf_memcalc();
-       /* lowater is approx. 2% of memory (with bufcache=15) */
-       bufmem_lowater = (bufmem_hiwater >> 3);
-       if (bufmem_lowater < 64 * 1024)
-               /* Ensure a reasonable minimum value */
-               bufmem_lowater = 64 * 1024;
+       buf_setwm();
 
        if (bufmem_valimit != 0) {
                vaddr_t minaddr = 0, maxaddr;
@@ -424,11 +434,11 @@
        try = random() & 0x0000000fL;
 
        /* Don't use "16 * bufmem" here to avoid a 32-bit overflow. */
-       thresh = bufmem / (bufmem_hiwater / 16);
+       thresh = (bufmem - bufmem_lowater) /
+           ((bufmem_hiwater - bufmem_lowater) / 16);
 
-       if ((try > thresh) && (uvmexp.free > (2 * uvmexp.freetarg))) {
+       if (try >= thresh)
                return 1;
-       }
 
        /* Otherwise don't allocate. */
        return 0;
@@ -1155,10 +1165,15 @@
                simple_lock(&bp->b_interlock);
                bremfree(bp);
        } else {
-               /* wait for a free buffer of any kind */
-               needbuffer = 1;
-               ltsleep(&needbuffer, slpflag|(PRIBIO + 1),
-                       "getnewbuf", slptimeo, &bqueue_slock);
+               /*
+                * XXX: !from_bufq should be removed.
+                */
+               if (!from_bufq || curproc != uvm.pagedaemon_proc) {
+                       /* wait for a free buffer of any kind */
+                       needbuffer = 1;
+                       ltsleep(&needbuffer, slpflag|(PRIBIO + 1),
+                           "getnewbuf", slptimeo, &bqueue_slock);
+               }
                return (NULL);
        }
 
@@ -1262,17 +1277,17 @@
 int
 buf_drain(int n)
 {
-       int s, size = 0;
+       int s, size = 0, sz;
 
        s = splbio();
        simple_lock(&bqueue_slock);
 
-       /* If not asked for a specific amount, make our own estimate */
-       if (n == 0)
-               n = buf_canrelease();
-
-       while (size < n && bufmem > bufmem_lowater)
-               size += buf_trim();
+       while (size < n && bufmem > bufmem_lowater) {
+               sz = buf_trim();
+               if (sz <= 0)
+                       break;
+               size += sz;
+       }
 
        simple_unlock(&bqueue_slock);
        splx(s);
@@ -1560,15 +1575,14 @@
                if (t < 0 || t > 100)
                        return (EINVAL);
                bufcache = t;
-               bufmem_hiwater = buf_memcalc();
-               bufmem_lowater = (bufmem_hiwater >> 3);
-               if (bufmem_lowater < 64 * 1024) 
-                       /* Ensure a reasonable minimum value */
-                       bufmem_lowater = 64 * 1024;
-
+               buf_setwm();
        } else if (rnode->sysctl_data == &bufmem_lowater) {
+               if (bufmem_hiwater - bufmem_lowater < 16)
+                       return (EINVAL);
                bufmem_lowater = t;
        } else if (rnode->sysctl_data == &bufmem_hiwater) {
+               if (bufmem_hiwater - bufmem_lowater < 16)
+                       return (EINVAL);
                bufmem_hiwater = t;
        } else
                return (EINVAL);



Home | Main Index | Thread Index | Old Index