]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/vmsystm.h
75ae8a9914d788704864d5a83ab9a64c5fc03d29
[mirror_spl-debian.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 ptob(pages) (pages * PAGE_SIZE)
44 #define membar_producer() smp_wmb()
45
46 #define physmem num_physpages
47 #define freemem nr_free_pages()
48 #define availrmem spl_kmem_availrmem()
49
50 extern pgcnt_t minfree; /* Sum of zone->pages_min */
51 extern pgcnt_t desfree; /* Sum of zone->pages_low */
52 extern pgcnt_t lotsfree; /* Sum of zone->pages_high */
53 extern pgcnt_t needfree; /* Always 0 unused in new Solaris */
54 extern pgcnt_t swapfs_minfree; /* Solaris default value */
55 extern pgcnt_t swapfs_reserve; /* Solaris default value */
56
57 extern vmem_t *heap_arena; /* primary kernel heap arena */
58 extern vmem_t *zio_alloc_arena; /* arena for zio caches */
59 extern vmem_t *zio_arena; /* arena for allocating zio memory */
60
61 #define VMEM_ALLOC 0x01
62 #define VMEM_FREE 0x02
63
64 extern pgcnt_t spl_kmem_availrmem(void);
65 extern size_t vmem_size(vmem_t *vmp, int typemask);
66
67 #define xcopyin(from, to, size) copy_from_user(to, from, size)
68 #define xcopyout(from, to, size) copy_to_user(to, from, size)
69
70 static __inline__ int
71 copyin(const void *from, void *to, size_t len)
72 {
73 /* On error copyin routine returns -1 */
74 if (xcopyin(from, to, len))
75 return -1;
76
77 return 0;
78 }
79
80 static __inline__ int
81 copyout(const void *from, void *to, size_t len)
82 {
83 /* On error copyout routine returns -1 */
84 if (xcopyout(from, to, len))
85 return -1;
86
87 return 0;
88 }
89
90 static __inline__ int
91 copyinstr(const void *from, void *to, size_t len, size_t *done)
92 {
93 size_t rc;
94
95 if (len == 0)
96 return -ENAMETOOLONG;
97
98 /* XXX: Should return ENAMETOOLONG if 'strlen(from) > len' */
99
100 memset(to, 0, len);
101 rc = copyin(from, to, len - 1);
102 if (done != NULL)
103 *done = rc;
104
105 return 0;
106 }
107
108 #endif /* SPL_VMSYSTM_H */