This is a major revamping of the pageout and low-memory handling code.
[dragonfly.git] / sys / vm / vm_page2.h
CommitLineData
12e4aaff
MD
1/*-
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)vmmeter.h 8.2 (Berkeley) 7/10/94
34 * $FreeBSD: src/sys/sys/vmmeter.h,v 1.21.2.2 2002/10/10 19:28:21 dillon Exp $
10192bae 35 * $DragonFly: src/sys/vm/vm_page2.h,v 1.3 2008/04/14 20:00:29 dillon Exp $
12e4aaff
MD
36 */
37
1bd40720
MD
38#ifndef _VM_VM_PAGE2_H_
39#define _VM_VM_PAGE2_H_
12e4aaff
MD
40
41#ifndef _SYS_VMMETER_H_
42#include <sys/vmmeter.h>
43#endif
10192bae
MD
44#ifndef _SYS_QUEUE_H_
45#include <sys/queue.h>
46#endif
47#ifndef _VM_PAGE_H_
48#include <vm/vm_page.h>
49#endif
12e4aaff
MD
50
51#ifdef _KERNEL
52
53/*
12e4aaff
MD
54 * Return TRUE if we are under our severe low-free-pages threshold
55 *
20479584
MD
56 * This causes user processes to stall to avoid exhausting memory that
57 * the kernel might need.
58 *
59 * reserved < severe < minimum < target < paging_target
12e4aaff 60 */
12e4aaff
MD
61static __inline
62int
63vm_page_count_severe(void)
64{
65 return (vmstats.v_free_severe >
20479584 66 vmstats.v_free_count + vmstats.v_cache_count);
12e4aaff
MD
67}
68
69/*
70 * Return TRUE if we are under our minimum low-free-pages threshold.
20479584
MD
71 * This activates the pageout demon. The pageout demon tries to
72 * reach the target but may stop once it satisfies the minimum.
12e4aaff 73 *
20479584 74 * reserved < severe < minimum < target < paging_target
12e4aaff 75 */
12e4aaff
MD
76static __inline
77int
20479584 78vm_page_count_min(int donotcount)
12e4aaff 79{
20479584
MD
80 return (vmstats.v_free_min + donotcount >
81 (vmstats.v_free_count + vmstats.v_cache_count) ||
82 vmstats.v_free_reserved > vmstats.v_free_count);
12e4aaff
MD
83}
84
85/*
20479584
MD
86 * Return TRUE if we are under our free page target. The pageout demon
87 * tries to reach the target but may stop once it gets past the min.
12e4aaff 88 */
12e4aaff
MD
89static __inline
90int
91vm_page_count_target(void)
92{
93 return (vmstats.v_free_target >
20479584 94 (vmstats.v_free_count + vmstats.v_cache_count));
12e4aaff
MD
95}
96
97/*
20479584
MD
98 * Return the number of pages the pageout daemon needs to move into the
99 * cache or free lists. A negative number means we have sufficient free
100 * pages.
12e4aaff 101 */
12e4aaff
MD
102static __inline
103int
104vm_paging_target(void)
105{
106 return (
107 (vmstats.v_free_target + vmstats.v_cache_min) -
108 (vmstats.v_free_count + vmstats.v_cache_count)
109 );
110}
111
112/*
20479584
MD
113 * Return TRUE if we need to start paging. This routine should not be
114 * used to determine when to block on the VM system. It supplies hysteresis
115 * to the pageout code.
116 *
117 * XXX this triggers a wakeup of the pagedaemon. As part of its work
118 * the pagedaemon tries to maintain v_free_reserved worth of truely
119 * free pages. Set the trigger point a bit lower so we have some hystereis.
12e4aaff 120 */
12e4aaff
MD
121static __inline
122int
123vm_paging_needed(void)
124{
20479584
MD
125 int trigger;
126
127 trigger = vmstats.v_interrupt_free_min +
128 (vmstats.v_free_reserved - vmstats.v_interrupt_free_min) / 2;
129 if (trigger < 10) /* safety */
130 trigger = 10;
131
12e4aaff 132 return (
20479584
MD
133 (vmstats.v_free_min + vmstats.v_cache_min) >
134 (vmstats.v_free_count + vmstats.v_cache_count) ||
135 trigger > vmstats.v_free_count
12e4aaff
MD
136 );
137}
138
10192bae
MD
139static __inline
140void
141vm_page_event(vm_page_t m, vm_page_event_t event)
142{
143 if (LIST_FIRST(&m->action_list))
144 vm_page_event_internal(m, event);
145}
146
147static __inline
148void
149vm_page_init_action(vm_page_action_t action,
150 void (*func)(vm_page_t, vm_page_action_t), void *data)
151{
152 action->func = func;
153 action->data = data;
154}
155
156static __inline
157void
158vm_page_register_action(vm_page_t m, vm_page_action_t action,
159 vm_page_event_t event)
160{
161 action->event = event;
162 LIST_INSERT_HEAD(&m->action_list, action, entry);
163}
164
165static __inline
166void
167vm_page_unregister_action(vm_page_t m, vm_page_action_t action)
168{
169 if (action->event != VMEVENT_NONE) {
170 action->event = VMEVENT_NONE;
171 LIST_REMOVE(action, entry);
172 }
173}
174
12e4aaff 175#endif /* _KERNEL */
1bd40720 176#endif /* _VM_VM_PAGE2_H_ */
12e4aaff 177