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 (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 #ifndef _SYS_MEM_CAGE_H 26 #define _SYS_MEM_CAGE_H 27 28 #include <sys/types.h> 29 #include <sys/memlist.h> 30 31 /* 32 * Memory caging interfaces. 33 */ 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #ifdef _KERNEL 40 41 #define KCT_FAILURE 0 42 #define KCT_CRIT 1 43 #define KCT_NONCRIT 2 44 45 extern int kernel_cage_enable; 46 extern int kcage_on; 47 extern kthread_id_t kcage_cageout_thread; 48 extern pgcnt_t kcage_freemem; 49 extern pgcnt_t kcage_needfree; 50 extern pgcnt_t kcage_lotsfree; 51 extern pgcnt_t kcage_desfree; 52 extern pgcnt_t kcage_minfree; 53 extern pgcnt_t kcage_throttlefree; 54 55 extern void kcage_freemem_add(pgcnt_t); 56 extern void kcage_freemem_sub(pgcnt_t); 57 extern int kcage_create_throttle(pgcnt_t, int); 58 59 /* 60 * Control direction of growth: 0: increasing pfns, 1: decreasing. 61 */ 62 typedef enum {KCAGE_UP, KCAGE_DOWN} kcage_dir_t; 63 extern void kcage_range_init(struct memlist *, kcage_dir_t, pgcnt_t); 64 extern int kcage_range_add(pfn_t, pgcnt_t, kcage_dir_t); 65 66 extern int kcage_current_pfn(pfn_t *); 67 extern int kcage_range_delete(pfn_t, pgcnt_t); 68 extern int kcage_range_delete_post_mem_del(pfn_t, pgcnt_t); 69 70 extern void kcage_recalc_thresholds(void); 71 72 /* Called from vm_pageout.c */ 73 extern void kcage_cageout_init(void); 74 extern void kcage_cageout_wakeup(void); 75 76 /* Called from clock thread in clock.c */ 77 extern void kcage_tick(void); 78 79 /* Called from vm_pagelist.c */ 80 extern int kcage_next_range(int incage, 81 pfn_t lo, pfn_t hi, pfn_t *nlo, pfn_t *nhi); 82 83 extern kcage_dir_t kcage_startup_dir; 84 85 #if defined(__sparc) 86 /* Macros to throttle memory allocations from the kernel cage. */ 87 88 #define KERNEL_THROTTLE_NONCRIT(npages, flags) \ 89 (kcage_create_throttle(1, flags) == KCT_NONCRIT) 90 91 #define KERNEL_THROTTLE(npages, flags) \ 92 if (((flags) & PG_NORELOC) && \ 93 (kcage_freemem < (kcage_throttlefree + (npages)))) { \ 94 (void) kcage_create_throttle(npages, flags); \ 95 } 96 97 98 #define KERNEL_THROTTLE_PGCREATE(npages, flags, cond) \ 99 ((((flags) & (PG_NORELOC|(cond)) == (PG_NORELOC|(cond))) && \ 100 (kcage_freemem < (kcage_throttlefree + (npages))) && \ 101 (kcage_create_throttle(npages, flags) == KCT_FAILURE)) ? \ 102 1 : 0) 103 104 #define KERNEL_NOT_THROTTLED(flags) (!kcage_on || !((flags) & PG_NORELOC)) 105 #endif /* __sparc */ 106 107 #endif /* _KERNEL */ 108 109 #ifdef __cplusplus 110 } 111 #endif 112 113 #endif /* _SYS_MEM_CAGE_H */ 114