xref: /illumos-gate/usr/src/uts/common/sys/mem_cage.h (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_MEM_CAGE_H
27 #define	_SYS_MEM_CAGE_H
28 
29 #include <sys/types.h>
30 #include <sys/memlist.h>
31 
32 /*
33  * Memory caging interfaces.
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _KERNEL
41 
42 #define	KCT_FAILURE	0
43 #define	KCT_CRIT	1
44 #define	KCT_NONCRIT	2
45 
46 extern int kernel_cage_enable;
47 extern int kcage_on;
48 extern kthread_id_t kcage_cageout_thread;
49 extern pgcnt_t kcage_freemem;
50 extern pgcnt_t kcage_needfree;
51 extern pgcnt_t kcage_lotsfree;
52 extern pgcnt_t kcage_desfree;
53 extern pgcnt_t kcage_minfree;
54 extern pgcnt_t kcage_throttlefree;
55 
56 extern void kcage_freemem_add(pgcnt_t);
57 extern void kcage_freemem_sub(pgcnt_t);
58 extern int kcage_create_throttle(pgcnt_t, int);
59 
60 /*
61  * Control direction of growth: 0: increasing pfns, 1: decreasing.
62  */
63 typedef enum {KCAGE_UP, KCAGE_DOWN} kcage_dir_t;
64 extern void kcage_range_init(struct memlist *, kcage_dir_t, pgcnt_t);
65 extern int kcage_range_add(pfn_t, pgcnt_t, kcage_dir_t);
66 
67 extern int kcage_current_pfn(pfn_t *);
68 extern int kcage_range_delete(pfn_t, pgcnt_t);
69 extern int kcage_range_delete_post_mem_del(pfn_t, pgcnt_t);
70 
71 extern void kcage_recalc_thresholds(void);
72 
73 /* Called from vm_pageout.c */
74 extern void kcage_cageout_init(void);
75 extern void kcage_cageout_wakeup(void);
76 
77 /* Called from clock thread in clock.c */
78 extern void kcage_tick(void);
79 
80 /* Called from vm_pagelist.c */
81 extern int kcage_next_range(int incage,
82     pfn_t lo, pfn_t hi, pfn_t *nlo, pfn_t *nhi);
83 
84 extern kcage_dir_t kcage_startup_dir;
85 
86 #endif /* _KERNEL */
87 
88 #ifdef	__cplusplus
89 }
90 #endif
91 
92 #endif	/* _SYS_MEM_CAGE_H */
93