]> git.proxmox.com Git - mirror_zfs.git/blob - include/sys/vmsystm.h
Merge branch 'kallsyms'
[mirror_zfs.git] / include / sys / vmsystm.h
1 /*
2 * This file is part of the SPL: Solaris Porting Layer.
3 *
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
6 * Written by:
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
10 * UCRL-CODE-235197
11 *
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
27 #ifndef _SPL_VMSYSTM_H
28 #define _SPL_VMSYSTM_H
29
30 #include <linux/mmzone.h>
31 #include <linux/mm.h>
32 #include <linux/swap.h>
33 #include <sys/types.h>
34 #include <asm/uaccess.h>
35
36 /* These values are loosely coupled with the the VM page reclaim.
37 * Linux uses its own heuristics to trigger page reclamation, and
38 * because those interface are difficult to interface with. These
39 * values should only be considered as a rough guide to the system
40 * memory state and not as direct evidence that page reclaimation
41 * is or is not currently in progress.
42 */
43 #define membar_producer() smp_wmb()
44
45 #define physmem num_physpages
46 #define freemem nr_free_pages()
47 #define availrmem spl_kmem_availrmem()
48
49 extern pgcnt_t minfree; /* Sum of zone->pages_min */
50 extern pgcnt_t desfree; /* Sum of zone->pages_low */
51 extern pgcnt_t lotsfree; /* Sum of zone->pages_high */
52 extern pgcnt_t needfree; /* Always 0 unused in new Solaris */
53 extern pgcnt_t swapfs_minfree; /* Solaris default value */
54 extern pgcnt_t swapfs_reserve; /* Solaris default value */
55
56 extern vmem_t *heap_arena; /* primary kernel heap arena */
57 extern vmem_t *zio_alloc_arena; /* arena for zio caches */
58 extern vmem_t *zio_arena; /* arena for allocating zio memory */
59
60 extern pgcnt_t spl_kmem_availrmem(void);
61 extern size_t vmem_size(vmem_t *vmp, int typemask);
62
63 /*
64 * The following symbols are available for use within the kernel
65 * itself, and they used to be available in older kernels. But it
66 * looks like they have been removed perhaps due to lack of use.
67 * For our purposes we need them to access the global memory state
68 * of the system, which is even available to user space process
69 * in /proc/meminfo. It's odd to me that there is no kernel API
70 * to get the same information, minimally the proc handler for
71 * the above mentioned /proc/meminfo file would make use of it.
72 */
73
74 /* Source linux/fs/proc/mmu.c */
75 #ifndef HAVE_GET_VMALLOC_INFO
76 #ifdef CONFIG_MMU
77
78 struct vmalloc_info {
79 unsigned long used;
80 unsigned long largest_chunk;
81 };
82
83 typedef void (*get_vmalloc_info_t)(struct vmalloc_info *);
84 extern get_vmalloc_info_t get_vmalloc_info_fn;
85
86 # define VMEM_ALLOC 0x01
87 # define VMEM_FREE 0x02
88 # define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
89 # define get_vmalloc_info(vmi) get_vmalloc_info_fn(vmi)
90 #else
91 # error "CONFIG_MMU must be defined"
92 #endif /* CONFIG_MMU */
93 #endif /* HAVE_GET_VMALLOC_INFO */
94
95 /* Source linux/mm/mmzone.c */
96 #ifndef HAVE_FIRST_ONLINE_PGDAT
97 typedef struct pglist_data *(*first_online_pgdat_t)(void);
98 extern first_online_pgdat_t first_online_pgdat_fn;
99 #define first_online_pgdat() first_online_pgdat_fn()
100 #endif /* HAVE_FIRST_ONLINE_PGDAT */
101
102 /* Source linux/mm/mmzone.c */
103 #ifndef HAVE_NEXT_ONLINE_PGDAT
104 typedef struct pglist_data *(*next_online_pgdat_t)(struct pglist_data *);
105 extern next_online_pgdat_t next_online_pgdat_fn;
106 #define next_online_pgdat(pgd) next_online_pgdat_fn(pgd)
107 #endif /* HAVE_NEXT_ONLINE_PGDAT */
108
109 /* Source linux/mm/mmzone.c */
110 #ifndef HAVE_NEXT_ZONE
111 typedef struct zone *(*next_zone_t)(struct zone *);
112 extern next_zone_t next_zone_fn;
113 #define next_zone(zone) next_zone_fn(zone)
114 #endif /* HAVE_NEXT_ZONE */
115
116 /* Source linux/mm/vmstat.c */
117 #ifndef HAVE_GET_ZONE_COUNTS
118 typedef void (*get_zone_counts_t)(unsigned long *, unsigned long *,
119 unsigned long *);
120 extern get_zone_counts_t get_zone_counts_fn;
121 #define get_zone_counts(a,i,f) get_zone_counts_fn(a,i,f)
122 #endif /* HAVE_GET_ZONE_COUNTS */
123
124
125 #define xcopyin(from, to, size) copy_from_user(to, from, size)
126 #define xcopyout(from, to, size) copy_to_user(to, from, size)
127
128 static __inline__ int
129 copyin(const void *from, void *to, size_t len)
130 {
131 /* On error copyin routine returns -1 */
132 if (xcopyin(from, to, len))
133 return -1;
134
135 return 0;
136 }
137
138 static __inline__ int
139 copyout(const void *from, void *to, size_t len)
140 {
141 /* On error copyout routine returns -1 */
142 if (xcopyout(from, to, len))
143 return -1;
144
145 return 0;
146 }
147
148 static __inline__ int
149 copyinstr(const void *from, void *to, size_t len, size_t *done)
150 {
151 size_t rc;
152
153 if (len == 0)
154 return -ENAMETOOLONG;
155
156 /* XXX: Should return ENAMETOOLONG if 'strlen(from) > len' */
157
158 memset(to, 0, len);
159 rc = copyin(from, to, len - 1);
160 if (done != NULL)
161 *done = rc;
162
163 return 0;
164 }
165
166 #endif /* SPL_VMSYSTM_H */