4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 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 */
30 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <sys/sysmacros.h>
33 #include <sys/systm.h>
35 #include <sys/cpuvar.h>
37 #include <sys/tuneable.h>
38 #include <sys/cmn_err.h>
41 #include <sys/vmsystm.h>
42 #include <sys/vmparam.h>
43 #include <sys/class.h>
44 #include <sys/vtrace.h>
45 #include <sys/modctl.h>
46 #include <sys/debug.h>
47 #include <sys/tnf_probe.h>
48 #include <sys/procfs.h>
51 #include <vm/seg_kp.h>
54 #include <vm/seg_kmem.h>
55 #include <sys/callb.h>
57 pgcnt_t avefree
; /* 5 sec moving average of free memory */
58 pgcnt_t avefree30
; /* 30 sec moving average of free memory */
68 kmutex_t swap_cpr_lock
;
70 mutex_init(&swap_cpr_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
71 CALLB_CPR_INIT(&cprinfo
, &swap_cpr_lock
, callb_generic_cpr
, "sched");
74 if (avenrun
[0] >= 2 * FSCALE
&&
75 (MAX(avefree
, avefree30
) < desfree
) &&
76 (pginrate
+ pgoutrate
> maxpgio
|| avefree
< minfree
)) {
78 * Unload all unloadable modules, free all other memory
79 * resources we can find, then look for a thread to
88 t
->t_schedflag
|= (TS_ALLSTART
& ~TS_CSTART
);
89 t
->t_whystop
= PR_SUSPENDED
;
90 t
->t_whatstop
= SUSPEND_NORMAL
;
91 (void) new_mstate(t
, LMS_SLEEP
);
92 mutex_enter(&swap_cpr_lock
);
93 CALLB_CPR_SAFE_BEGIN(&cprinfo
);
94 mutex_exit(&swap_cpr_lock
);
95 thread_stop(t
); /* change to stop state and drop lock */
97 mutex_enter(&swap_cpr_lock
);
98 CALLB_CPR_SAFE_END(&cprinfo
, &swap_cpr_lock
);
99 mutex_exit(&swap_cpr_lock
);