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 $ 35 * $DragonFly: src/sys/vm/vm_page2.h,v 1.1 2003/07/03 17:24:04 dillon Exp $ 36 */ 37 38 #ifndef _VM_VMPAGE2_H_ 39 #define _VM_VMPAGE2_H_ 40 41 #ifndef _SYS_VMMETER_H_ 42 #include <sys/vmmeter.h> 43 #endif 44 45 #ifdef _KERNEL 46 47 /* 48 * Return TRUE if we are under our reserved low-free-pages threshold 49 */ 50 51 static __inline 52 int 53 vm_page_count_reserved(void) 54 { 55 return (vmstats.v_free_reserved > 56 (vmstats.v_free_count + vmstats.v_cache_count)); 57 } 58 59 /* 60 * Return TRUE if we are under our severe low-free-pages threshold 61 * 62 * This routine is typically used at the user<->system interface to determine 63 * whether we need to block in order to avoid a low memory deadlock. 64 */ 65 66 static __inline 67 int 68 vm_page_count_severe(void) 69 { 70 return (vmstats.v_free_severe > 71 (vmstats.v_free_count + vmstats.v_cache_count)); 72 } 73 74 /* 75 * Return TRUE if we are under our minimum low-free-pages threshold. 76 * 77 * This routine is typically used within the system to determine whether 78 * we can execute potentially very expensive code in terms of memory. It 79 * is also used by the pageout daemon to calculate when to sleep, when 80 * to wake waiters up, and when (after making a pass) to become more 81 * desparate. 82 */ 83 84 static __inline 85 int 86 vm_page_count_min(void) 87 { 88 return (vmstats.v_free_min > 89 (vmstats.v_free_count + vmstats.v_cache_count)); 90 } 91 92 /* 93 * Return TRUE if we have not reached our free page target during 94 * free page recovery operations. 95 */ 96 97 static __inline 98 int 99 vm_page_count_target(void) 100 { 101 return (vmstats.v_free_target > 102 (vmstats.v_free_count + vmstats.v_cache_count)); 103 } 104 105 /* 106 * Return the number of pages we need to free-up or cache 107 * A positive number indicates that we do not have enough free pages. 108 */ 109 110 static __inline 111 int 112 vm_paging_target(void) 113 { 114 return ( 115 (vmstats.v_free_target + vmstats.v_cache_min) - 116 (vmstats.v_free_count + vmstats.v_cache_count) 117 ); 118 } 119 120 /* 121 * Return a positive number if the pagedaemon needs to be woken up. 122 */ 123 124 static __inline 125 int 126 vm_paging_needed(void) 127 { 128 return ( 129 (vmstats.v_free_reserved + vmstats.v_cache_min) > 130 (vmstats.v_free_count + vmstats.v_cache_count) 131 ); 132 } 133 134 #endif /* _KERNEL */ 135 #endif 136 137