Merge branch 'black_magic'
[unleashed.git] / kernel / os / vm_meter.c
blobb0dbbe3d28d8774166cfd9e88443fe30ee92f384
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/sysmacros.h>
45 #include <sys/systm.h>
46 #include <sys/vmsystm.h>
47 #include <sys/cpuvar.h>
48 #include <sys/sysinfo.h>
51 * This define represents the number of
52 * useful pages transferred per paging i/o operation, under the assumption
53 * that half of the total number is actually useful. However, if there's
54 * only one page transferred per operation, we assume that it's useful.
57 #ifdef lint
58 #define UsefulPagesPerIO 1
59 #else /* lint */
60 #define UsefulPagesPerIO nz((MAXBSIZE/PAGESIZE)/2)
61 #endif /* lint */
63 extern int dopageout;
65 /* Average new into old with aging factor time */
66 #define ave(smooth, cnt, time) \
67 smooth = ((time - 1) * (smooth) + (cnt)) / (time)
70 * pagein and pageout rates for use by swapper.
72 ulong_t pginrate; /* 5 second average */
73 ulong_t pgoutrate; /* 5 second average */
75 static ulong_t ogpagein; /* pagein rate a sec ago */
76 static ulong_t ogpageout; /* pageout rate a sec ago */
79 * Called once a second to gather statistics.
81 void
82 vmmeter(void)
84 cpu_t *cp;
85 ulong_t gpagein, gpageout;
88 * Compute 5 sec and 30 sec average free memory values.
90 ave(avefree, freemem, 5);
91 ave(avefree30, freemem, 30);
94 * Compute the 5 secs average of pageins and pageouts.
96 gpagein = gpageout = 0;
98 cp = cpu_list;
99 do {
100 gpagein += (ulong_t)CPU_STATS(cp, vm.pgin);
101 gpageout += (ulong_t)CPU_STATS(cp, vm.pgout);
102 } while ((cp = cp->cpu_next) != cpu_list);
104 if ((gpagein >= ogpagein) && (gpageout >= ogpageout)) {
105 ave(pginrate, gpagein - ogpagein, 5);
106 ave(pgoutrate, gpageout - ogpageout, 5);
110 * Save the current pagein/pageout values.
112 ogpagein = gpagein;
113 ogpageout = gpageout;
115 if (!lotsfree || !dopageout)
116 return;
119 * Decay deficit by the expected number of pages brought in since
120 * the last call (i.e., in the last second). The calculation
121 * assumes that one half of the pages brought in are actually
122 * useful (see comment above), and that half of the overall
123 * paging i/o activity is pageins as opposed to pageouts (the
124 * trailing factor of 2) It also assumes that paging i/o is done
125 * in units of MAXBSIZE bytes, which is a dubious assumption to
126 * apply to all file system types.
128 deficit -= MIN(deficit,
129 MAX(deficit / 10, UsefulPagesPerIO * maxpgio / 2));