]> git.proxmox.com Git - mirror_spl-debian.git/blame - include/sys/vmsystm.h
SLES10 Fixes (part 6)
[mirror_spl-debian.git] / include / sys / vmsystm.h
CommitLineData
715f6251 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
a713518f 27#ifndef _SPL_VMSYSTM_H
28#define _SPL_VMSYSTM_H
29
36b313da 30#include <linux/mmzone.h>
a713518f 31#include <linux/mm.h>
6ab69573 32#include <linux/swap.h>
c5f70460 33#include <linux/highmem.h>
af828292 34#include <sys/types.h>
2bdb28fb 35#include <asm/uaccess.h>
af828292 36
c5f70460 37/* These values are loosely coupled with the VM page reclaim.
36b313da
BB
38 * Linux uses its own heuristics to trigger page reclamation, and
39 * because those interface are difficult to interface with. These
40 * values should only be considered as a rough guide to the system
c5f70460 41 * memory state and not as direct evidence that page reclamation.
36b313da
BB
42 * is or is not currently in progress.
43 */
36b313da 44#define membar_producer() smp_wmb()
a713518f 45
46#define physmem num_physpages
ea3e6ca9 47#define freemem nr_free_pages()
4ab13d3b 48#define availrmem spl_kmem_availrmem()
36b313da
BB
49
50extern pgcnt_t minfree; /* Sum of zone->pages_min */
51extern pgcnt_t desfree; /* Sum of zone->pages_low */
52extern pgcnt_t lotsfree; /* Sum of zone->pages_high */
4ab13d3b
BB
53extern pgcnt_t needfree; /* Always 0 unused in new Solaris */
54extern pgcnt_t swapfs_minfree; /* Solaris default value */
55extern pgcnt_t swapfs_reserve; /* Solaris default value */
36b313da
BB
56
57extern vmem_t *heap_arena; /* primary kernel heap arena */
58extern vmem_t *zio_alloc_arena; /* arena for zio caches */
59extern vmem_t *zio_arena; /* arena for allocating zio memory */
60
4ab13d3b
BB
61extern pgcnt_t spl_kmem_availrmem(void);
62extern size_t vmem_size(vmem_t *vmp, int typemask);
77b1fe8f 63
d1ff2312
BB
64/*
65 * The following symbols are available for use within the kernel
66 * itself, and they used to be available in older kernels. But it
67 * looks like they have been removed perhaps due to lack of use.
68 * For our purposes we need them to access the global memory state
69 * of the system, which is even available to user space process
70 * in /proc/meminfo. It's odd to me that there is no kernel API
71 * to get the same information, minimally the proc handler for
72 * the above mentioned /proc/meminfo file would make use of it.
73 */
74
75/* Source linux/fs/proc/mmu.c */
76#ifndef HAVE_GET_VMALLOC_INFO
77#ifdef CONFIG_MMU
78
79struct vmalloc_info {
80 unsigned long used;
81 unsigned long largest_chunk;
82};
83
84typedef void (*get_vmalloc_info_t)(struct vmalloc_info *);
85extern 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
5232d256 96#ifdef HAVE_PGDAT_HELPERS
d1ff2312 97/* Source linux/mm/mmzone.c */
5232d256 98# ifndef HAVE_FIRST_ONLINE_PGDAT
d1ff2312
BB
99typedef struct pglist_data *(*first_online_pgdat_t)(void);
100extern first_online_pgdat_t first_online_pgdat_fn;
5232d256
BB
101# define first_online_pgdat() first_online_pgdat_fn()
102# endif /* HAVE_FIRST_ONLINE_PGDAT */
d1ff2312 103
5232d256 104# ifndef HAVE_NEXT_ONLINE_PGDAT
d1ff2312
BB
105typedef struct pglist_data *(*next_online_pgdat_t)(struct pglist_data *);
106extern next_online_pgdat_t next_online_pgdat_fn;
5232d256
BB
107# define next_online_pgdat(pgd) next_online_pgdat_fn(pgd)
108# endif /* HAVE_NEXT_ONLINE_PGDAT */
d1ff2312 109
5232d256 110# ifndef HAVE_NEXT_ZONE
d1ff2312
BB
111typedef struct zone *(*next_zone_t)(struct zone *);
112extern next_zone_t next_zone_fn;
5232d256
BB
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
119extern struct pglist_data *pgdat_list_addr;
120# define pgdat_list pgdat_list_addr
121# endif /* HAVE_PGDAT_LIST */
122
123#endif /* HAVE_PGDAT_HELPERS */
d1ff2312
BB
124
125/* Source linux/mm/vmstat.c */
e11d6c5f
BB
126#ifndef HAVE_ZONE_STAT_ITEM_FIA
127# ifndef HAVE_GET_ZONE_COUNTS
d1ff2312
BB
128typedef void (*get_zone_counts_t)(unsigned long *, unsigned long *,
129 unsigned long *);
130extern get_zone_counts_t get_zone_counts_fn;
e11d6c5f 131# define get_zone_counts(a,i,f) get_zone_counts_fn(a,i,f)
96dded38 132# endif /* HAVE_GET_ZONE_COUNTS */
e11d6c5f
BB
133
134extern unsigned long spl_global_page_state(int);
135/* Defines designed to simulate enum but large enough to ensure no overlap */
136# define NR_FREE_PAGES 0x8001
137# define NR_INACTIVE 0x8002
138# define NR_ACTIVE 0x8003
e11d6c5f
BB
139#else
140#define spl_global_page_state(item) global_page_state(item)
141#endif /* HAVE_ZONE_STAT_ITEM_FIA */
d1ff2312 142
2bdb28fb 143#define xcopyin(from, to, size) copy_from_user(to, from, size)
144#define xcopyout(from, to, size) copy_to_user(to, from, size)
145
146static __inline__ int
147copyin(const void *from, void *to, size_t len)
148{
149 /* On error copyin routine returns -1 */
150 if (xcopyin(from, to, len))
151 return -1;
152
153 return 0;
154}
155
156static __inline__ int
157copyout(const void *from, void *to, size_t len)
158{
159 /* On error copyout routine returns -1 */
160 if (xcopyout(from, to, len))
161 return -1;
162
163 return 0;
164}
165
166static __inline__ int
167copyinstr(const void *from, void *to, size_t len, size_t *done)
168{
0998fdd6 169 size_t rc;
170
2bdb28fb 171 if (len == 0)
172 return -ENAMETOOLONG;
173
2bdb28fb 174 /* XXX: Should return ENAMETOOLONG if 'strlen(from) > len' */
175
176 memset(to, 0, len);
0998fdd6 177 rc = copyin(from, to, len - 1);
178 if (done != NULL)
179 *done = rc;
2bdb28fb 180
181 return 0;
182}
2f5d55aa 183
a713518f 184#endif /* SPL_VMSYSTM_H */