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