Source-Changes-HG archive

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

[src/trunk]: src add UBC memory-usage balancing. we track the number of page...



details:   https://anonhg.NetBSD.org/src/rev/0a1181ccab52
branches:  trunk
changeset: 506936:0a1181ccab52
user:      chs <chs%NetBSD.org@localhost>
date:      Fri Mar 09 01:02:10 2001 +0000

description:
add UBC memory-usage balancing.  we track the number of pages in use for
each of the basic types (anonymous data, executable image, cached files)
and prevent the pagedaemon from reusing a given page if that would reduce
the count of that type of page below a sysctl-setable minimum threshold.
the thresholds are controlled via three new sysctl tunables:
vm.anonmin, vm.vnodemin, and vm.vtextmin.  these tunables are the
percentages of pageable memory reserved for each usage, and we do not allow
the sum of the minimums to be more than 95% so that there's always some
memory that can be reused.

diffstat:

 sbin/sysctl/sysctl.8  |   11 +++-
 sbin/sysctl/sysctl.c  |   43 +++++++-----------
 sys/kern/vfs_subr.c   |   14 +++++-
 sys/kern/vfs_vnops.c  |    6 ++-
 sys/uvm/uvm_extern.h  |   18 ++++++-
 sys/uvm/uvm_meter.c   |   42 ++++++++++++++++++-
 sys/uvm/uvm_object.h  |    7 ++-
 sys/uvm/uvm_page.c    |   44 +++++++++++-------
 sys/uvm/uvm_param.h   |   12 +++-
 sys/uvm/uvm_pdaemon.c |  113 ++++++++++++++++++++++++++-----------------------
 sys/uvm/uvm_stat.c    |    7 ++-
 sys/uvm/uvm_vnode.c   |   18 +++----
 12 files changed, 214 insertions(+), 121 deletions(-)

diffs (truncated from 782 to 300 lines):

diff -r 8bea1ef56d4e -r 0a1181ccab52 sbin/sysctl/sysctl.8
--- a/sbin/sysctl/sysctl.8      Thu Mar 08 22:27:52 2001 +0000
+++ b/sbin/sysctl/sysctl.8      Fri Mar 09 01:02:10 2001 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sysctl.8,v 1.64 2001/02/07 08:59:49 itojun Exp $
+.\"    $NetBSD: sysctl.8,v 1.65 2001/03/09 01:02:10 chs Exp $
 .\"
 .\" Copyright (c) 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -346,9 +346,16 @@
 .It user.posix2_upe    integer no
 .It user.posix2_version        integer no
 .It user.re_dup_max    integer no
+.It vendor.<vendor>.*  ?       vendor specific
 .It vfs.generic.usermount      integer yes
-.It vendor.<vendor>.*  ?       vendor specific
+.It vm.anonmin integer yes
 .It vm.loadavg struct  no
+.It vm.nkmempages      integer no
+.It vm.uvmexp  struct  no
+.It vm.uvmexp2 struct  no
+.It vm.vmmeter struct  no
+.It vm.vnodemin        integer yes
+.It vm.vtextmin        integer yes
 .El
 .Pp
 Entries found under
diff -r 8bea1ef56d4e -r 0a1181ccab52 sbin/sysctl/sysctl.c
--- a/sbin/sysctl/sysctl.c      Thu Mar 08 22:27:52 2001 +0000
+++ b/sbin/sysctl/sysctl.c      Fri Mar 09 01:02:10 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysctl.c,v 1.45 2001/02/19 22:56:23 cgd Exp $  */
+/*     $NetBSD: sysctl.c,v 1.46 2001/03/09 01:02:11 chs Exp $  */
 
 /*
  * Copyright (c) 1993
@@ -44,7 +44,7 @@
 #if 0
 static char sccsid[] = "@(#)sysctl.c   8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: sysctl.c,v 1.45 2001/02/19 22:56:23 cgd Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.46 2001/03/09 01:02:11 chs Exp $");
 #endif
 #endif /* not lint */
 
@@ -298,6 +298,7 @@
        struct list *lp;
        int mib[CTL_MAXNAME];
        char *cp, *bufp, buf[BUFSIZ];
+       double loads[3];
 
        bufp = buf;
        snprintf(buf, BUFSIZ, "%s", string);
@@ -377,7 +378,7 @@
                case KERN_NTPTIME:
                        if (flags == 0)
                                return;
-                       warnx("Use xntpdc -c kerninfo to view %s information",
+                       warnx("Use ntpdc -c kerninfo to view %s information",
                            string);
                        return;
                case KERN_MBUF:
@@ -403,35 +404,25 @@
                break;
 
        case CTL_VM:
-               if (mib[1] == VM_LOADAVG) {
-                       double loads[3];
-
+               switch (mib[1]) {
+               case VM_LOADAVG:
                        getloadavg(loads, 3);
                        if (!nflag)
                                printf("%s: ", string);
                        printf("%.2f %.2f %.2f\n", loads[0], loads[1],
                            loads[2]);
                        return;
+
+               case VM_METER:
+               case VM_UVMEXP:
+               case VM_UVMEXP2:
+                       if (flags) {
+                               warnx("Use vmstat or systat to view %s"
+                                   "information", string);
+                       }
+                       return;
                }
-               if (mib[1] == VM_NKMEMPAGES) {
-                       size_t nkmempages_len;
-                       int nkmempages;
-
-                       nkmempages_len = sizeof(nkmempages);
-
-                       if (sysctl(mib, 2, &nkmempages, &nkmempages_len,
-                           NULL, 0)) {
-                               warn("unable to get %s", string);
-                               return;
-                       }
-                       if (!nflag)
-                               printf("%s: ", string);
-                       printf("%d\n", nkmempages);
-               }
-               if (flags == 0)
-                       return;
-               warnx("Use vmstat or systat to view %s information", string);
-               return;
+               break;
 
        case CTL_NET:
                if (mib[1] == PF_INET) {
@@ -1051,7 +1042,7 @@
                cp = &name[strlen(name)];
                *cp++ = '.';
                strcpy(cp, "curproc");
-               parse (name, Aflag);
+               parse(name, Aflag);
                return (-1);
        }
        cp = strsep(bufpp, ".");
diff -r 8bea1ef56d4e -r 0a1181ccab52 sys/kern/vfs_subr.c
--- a/sys/kern/vfs_subr.c       Thu Mar 08 22:27:52 2001 +0000
+++ b/sys/kern/vfs_subr.c       Fri Mar 09 01:02:10 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_subr.c,v 1.146 2001/02/21 21:40:00 jdolecek Exp $  */
+/*     $NetBSD: vfs_subr.c,v 1.147 2001/03/09 01:02:11 chs Exp $       */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -1217,6 +1217,10 @@
        else
                TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
        simple_unlock(&vnode_free_list_slock);
+       if (vp->v_flag & VTEXT) {
+               uvmexp.vtextpages -= vp->v_uvm.u_obj.uo_npages;
+               uvmexp.vnodepages += vp->v_uvm.u_obj.uo_npages;
+       }
        vp->v_flag &= ~VTEXT;
        simple_unlock(&vp->v_interlock);
        VOP_INACTIVE(vp, p);
@@ -1257,6 +1261,10 @@
        else
                TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
        simple_unlock(&vnode_free_list_slock);
+       if (vp->v_flag & VTEXT) {
+               uvmexp.vtextpages -= vp->v_uvm.u_obj.uo_npages;
+               uvmexp.vnodepages += vp->v_uvm.u_obj.uo_npages;
+       }
        vp->v_flag &= ~VTEXT;
        if (vn_lock(vp, LK_EXCLUSIVE | LK_INTERLOCK) == 0)
                VOP_INACTIVE(vp, p);
@@ -1481,6 +1489,10 @@
        if (vp->v_flag & VXLOCK)
                panic("vclean: deadlock, vp %p", vp);
        vp->v_flag |= VXLOCK;
+       if (vp->v_flag & VTEXT) {
+               uvmexp.vtextpages -= vp->v_uvm.u_obj.uo_npages;
+               uvmexp.vnodepages += vp->v_uvm.u_obj.uo_npages;
+       }
        vp->v_flag &= ~VTEXT;
 
        /*
diff -r 8bea1ef56d4e -r 0a1181ccab52 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c      Thu Mar 08 22:27:52 2001 +0000
+++ b/sys/kern/vfs_vnops.c      Fri Mar 09 01:02:10 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnops.c,v 1.45 2000/11/27 08:39:44 chs Exp $       */
+/*     $NetBSD: vfs_vnops.c,v 1.46 2001/03/09 01:02:11 chs Exp $       */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -195,6 +195,10 @@
 vn_marktext(vp)
        struct vnode *vp;
 {
+       if ((vp->v_flag & VTEXT) == 0) {
+               uvmexp.vnodepages -= vp->v_uvm.u_obj.uo_npages;
+               uvmexp.vtextpages += vp->v_uvm.u_obj.uo_npages;
+       }
        vp->v_flag |= VTEXT;
 }
 
diff -r 8bea1ef56d4e -r 0a1181ccab52 sys/uvm/uvm_extern.h
--- a/sys/uvm/uvm_extern.h      Thu Mar 08 22:27:52 2001 +0000
+++ b/sys/uvm/uvm_extern.h      Fri Mar 09 01:02:10 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_extern.h,v 1.56 2001/02/06 17:01:52 eeh Exp $      */
+/*     $NetBSD: uvm_extern.h,v 1.57 2001/03/09 01:02:12 chs Exp $      */
 
 /*
  *
@@ -251,9 +251,12 @@
        int inactive;   /* number of pages that we free'd but may want back */
        int paging;     /* number of pages in the process of being paged out */
        int wired;      /* number of wired pages */
-       /* XXX: Adding anything before this line will break binary
-        *      compatibility with top(1) on NetBSD 1.5.
+
+       /* 
+        * Adding anything before this line will break binary compatibility
+        * with top(1) on NetBSD 1.5.
         */
+
        int zeropages;          /* number of zero'd pages */
        int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
        int reserve_kernel;     /* number of pages reserved for kernel */
@@ -266,6 +269,12 @@
        int freetarg;   /* target number of free pages */
        int inactarg;   /* target number of inactive pages */
        int wiredmax;   /* max number of wired pages */
+       int anonmin;    /* min threshold for anon pages */
+       int vtextmin;   /* min threshold for vtext pages */
+       int vnodemin;   /* min threshold for vnode pages */
+       int anonminpct; /* min percent anon pages */
+       int vtextminpct;/* min percent vtext pages */
+       int vnodeminpct;/* min percent vnode pages */
 
        /* swap */
        int nswapdev;   /* number of configured swap devices in system */
@@ -333,6 +342,9 @@
        int pdpageouts; /* number of times daemon started a pageout */
        int pdpending;  /* number of times daemon got a pending pagout */
        int pddeact;    /* number of pages daemon deactivates */
+       int pdreanon;   /* anon pages reactivated due to min threshold */
+       int pdrevnode;  /* vnode pages reactivated due to min threshold */
+       int pdrevtext;  /* vtext pages reactivated due to min threshold */
 
        /* kernel memory objects: managed by uvm_km_kmemalloc() only! */
        struct uvm_object *kmem_object;
diff -r 8bea1ef56d4e -r 0a1181ccab52 sys/uvm/uvm_meter.c
--- a/sys/uvm/uvm_meter.c       Thu Mar 08 22:27:52 2001 +0000
+++ b/sys/uvm/uvm_meter.c       Fri Mar 09 01:02:10 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_meter.c,v 1.16 2000/11/30 11:04:44 simonb Exp $    */
+/*     $NetBSD: uvm_meter.c,v 1.17 2001/03/09 01:02:12 chs Exp $       */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -130,6 +130,7 @@
        struct proc *p;
 {
        struct vmtotal vmtotals;
+       int rv, t;
 
        /* all sysctl names at this level are terminal */
        if (namelen != 1)
@@ -156,6 +157,45 @@
        case VM_NKMEMPAGES:
                return (sysctl_rdint(oldp, oldlenp, newp, nkmempages));
 
+       case VM_ANONMIN:
+               t = uvmexp.anonminpct;
+               rv = sysctl_int(oldp, oldlenp, newp, newlen, &t);
+               if (rv) {
+                       return rv;
+               }
+               if (t + uvmexp.vtextminpct + uvmexp.vnodeminpct > 95 || t < 0) {
+                       return EINVAL;
+               }
+               uvmexp.anonminpct = t;
+               uvmexp.anonmin = t * 256 / 100;
+               return rv;
+
+       case VM_VTEXTMIN:
+               t = uvmexp.vtextminpct;
+               rv = sysctl_int(oldp, oldlenp, newp, newlen, &t);
+               if (rv) {
+                       return rv;
+               }
+               if (uvmexp.anonminpct + t + uvmexp.vnodeminpct > 95 || t < 0) {
+                       return EINVAL;
+               }
+               uvmexp.vtextminpct = t;
+               uvmexp.vtextmin = t * 256 / 100;
+               return rv;
+
+       case VM_VNODEMIN:
+               t = uvmexp.vnodeminpct;
+               rv = sysctl_int(oldp, oldlenp, newp, newlen, &t);
+               if (rv) {
+                       return rv;
+               }
+               if (uvmexp.anonminpct + uvmexp.vtextminpct + t > 95 || t < 0) {
+                       return EINVAL;
+               }
+               uvmexp.vnodeminpct = t;
+               uvmexp.vnodemin = t * 256 / 100;
+               return rv;
+
        default:
                return (EOPNOTSUPP);
        }
diff -r 8bea1ef56d4e -r 0a1181ccab52 sys/uvm/uvm_object.h
--- a/sys/uvm/uvm_object.h      Thu Mar 08 22:27:52 2001 +0000
+++ b/sys/uvm/uvm_object.h      Fri Mar 09 01:02:10 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_object.h,v 1.10 2001/01/28 22:23:06 thorpej Exp $  */
+/*     $NetBSD: uvm_object.h,v 1.11 2001/03/09 01:02:12 chs Exp $      */
 
 /*
  *



Home | Main Index | Thread Index | Old Index