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
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]
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
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
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 #define UsefulPagesPerIO nz((MAXBSIZE/PAGESIZE)/2)
61 /* Average new into old with aging factor time */
62 #define ave(smooth, cnt, time) \
63 smooth = ((time - 1) * (smooth) + (cnt)) / (time)
66 * pagein and pageout rates for use by swapper.
68 ulong_t pginrate
; /* 5 second average */
69 ulong_t pgoutrate
; /* 5 second average */
71 static ulong_t ogpagein
; /* pagein rate a sec ago */
72 static ulong_t ogpageout
; /* pageout rate a sec ago */
75 * Called once a second to gather statistics.
81 ulong_t gpagein
, gpageout
;
84 * Compute 5 sec and 30 sec average free memory values.
86 ave(avefree
, freemem
, 5);
87 ave(avefree30
, freemem
, 30);
90 * Compute the 5 secs average of pageins and pageouts.
92 gpagein
= gpageout
= 0;
96 gpagein
+= (ulong_t
)CPU_STATS(cp
, vm
.pgin
);
97 gpageout
+= (ulong_t
)CPU_STATS(cp
, vm
.pgout
);
98 } while ((cp
= cp
->cpu_next
) != cpu_list
);
100 if ((gpagein
>= ogpagein
) && (gpageout
>= ogpageout
)) {
101 ave(pginrate
, gpagein
- ogpagein
, 5);
102 ave(pgoutrate
, gpageout
- ogpageout
, 5);
106 * Save the current pagein/pageout values.
109 ogpageout
= gpageout
;
111 if (!lotsfree
|| !dopageout
)
115 * Decay deficit by the expected number of pages brought in since
116 * the last call (i.e., in the last second). The calculation
117 * assumes that one half of the pages brought in are actually
118 * useful (see comment above), and that half of the overall
119 * paging i/o activity is pageins as opposed to pageouts (the
120 * trailing factor of 2) It also assumes that paging i/o is done
121 * in units of MAXBSIZE bytes, which is a dubious assumption to
122 * apply to all file system types.
124 deficit
-= MIN(deficit
,
125 MAX(deficit
/ 10, UsefulPagesPerIO
* maxpgio
/ 2));