This source file includes following definitions.
- get_free_page
- in_swap_cache
- find_in_swap_cache
- delete_from_swap_cache
1 #ifndef _LINUX_MM_H
2 #define _LINUX_MM_H
3
4 #include <linux/page.h>
5 #include <linux/sched.h>
6 #include <linux/errno.h>
7 #include <linux/kernel.h>
8
9 #define VERIFY_READ 0
10 #define VERIFY_WRITE 1
11
12 extern int verify_area(int, const void *, unsigned long);
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 struct vm_area_struct {
30 struct task_struct * vm_task;
31 unsigned long vm_start;
32 unsigned long vm_end;
33 unsigned short vm_page_prot;
34 unsigned short vm_flags;
35 struct vm_area_struct * vm_next;
36 struct vm_area_struct * vm_share;
37 struct vm_operations_struct * vm_ops;
38 unsigned long vm_offset;
39 struct inode * vm_inode;
40 unsigned long vm_pte;
41 };
42
43
44
45
46 #define VM_READ 0x0001
47 #define VM_WRITE 0x0002
48 #define VM_EXEC 0x0004
49 #define VM_SHARED 0x0008
50
51 #define VM_MAYREAD 0x0010
52 #define VM_MAYWRITE 0x0020
53 #define VM_MAYEXEC 0x0040
54 #define VM_MAYSHARE 0x0080
55
56 #define VM_GROWSDOWN 0x0100
57 #define VM_GROWSUP 0x0200
58 #define VM_SHM 0x0400
59 #define VM_DENYWRITE 0x0800
60
61 #define VM_STACK_FLAGS 0x0177
62
63
64
65
66
67
68
69 struct vm_operations_struct {
70 void (*open)(struct vm_area_struct * area);
71 void (*close)(struct vm_area_struct * area);
72 unsigned long (*nopage)(struct vm_area_struct * area, unsigned long address,
73 unsigned long page, int error_code);
74 unsigned long (*wppage)(struct vm_area_struct * area, unsigned long address,
75 unsigned long page);
76 int (*share)(struct vm_area_struct * from, struct vm_area_struct * to, unsigned long address);
77 int (*unmap)(struct vm_area_struct *area, unsigned long, size_t);
78 void (*swapout)(struct vm_area_struct *, unsigned long *);
79 unsigned long (*swapin)(struct vm_area_struct *, unsigned long);
80 };
81
82 extern unsigned long __bad_page(void);
83 extern unsigned long __bad_pagetable(void);
84 extern unsigned long __zero_page(void);
85
86 #define BAD_PAGETABLE __bad_pagetable()
87 #define BAD_PAGE __bad_page()
88 #define ZERO_PAGE __zero_page()
89
90
91 #define P_DIRTY 0x0001
92 #define P_LOCKED 0x0002
93 #define P_UPTODATE 0x0004
94 #define P_RESERVED 0x8000
95
96 struct page_info {
97 unsigned short flags;
98 unsigned short count;
99 struct inode * inode;
100 unsigned long offset;
101 struct page_info * next_same_inode;
102 struct page_info * prev_same_inode;
103 struct page_info * next_hash;
104 struct page_info * prev_hash;
105 struct wait_queue *wait;
106 };
107
108
109 #ifdef __KERNEL__
110
111
112
113
114
115 extern int nr_swap_pages;
116 extern int nr_free_pages;
117
118 #define MAX_SECONDARY_PAGES 20
119 #define NR_MEM_LISTS 6
120
121 struct mem_list {
122 struct mem_list * next;
123 struct mem_list * prev;
124 };
125
126 extern struct mem_list free_area_list[NR_MEM_LISTS];
127 extern unsigned char * free_area_map[NR_MEM_LISTS];
128
129
130
131
132
133
134 #define __get_free_page(priority) __get_free_pages((priority),0)
135 extern unsigned long __get_free_pages(int priority, unsigned long gfporder);
136 extern inline unsigned long get_free_page(int priority)
137 {
138 unsigned long page;
139
140 page = __get_free_page(priority);
141 if (page)
142 __asm__ __volatile__("rep ; stosl"
143 : \
144 :"a" (0),"c" (1024),"D" (page)
145 :"di","cx");
146 return page;
147 }
148
149
150
151 #define free_page(addr) free_pages((addr),0)
152 extern void free_pages(unsigned long addr, unsigned long order);
153
154 extern void show_free_areas(void);
155 extern unsigned long put_dirty_page(struct task_struct * tsk,unsigned long page,
156 unsigned long address);
157
158 extern void free_page_tables(struct task_struct * tsk);
159 extern void clear_page_tables(struct task_struct * tsk);
160 extern int copy_page_tables(struct task_struct * to);
161 extern int clone_page_tables(struct task_struct * to);
162 extern int unmap_page_range(unsigned long from, unsigned long size);
163 extern int remap_page_range(unsigned long from, unsigned long to, unsigned long size, int mask);
164 extern int zeromap_page_range(unsigned long from, unsigned long size, int mask);
165
166 extern void do_wp_page(struct vm_area_struct * vma, unsigned long address,
167 unsigned long error_code);
168 extern void do_no_page(struct vm_area_struct * vma, unsigned long address,
169 unsigned long error_code);
170
171 extern unsigned long paging_init(unsigned long start_mem, unsigned long end_mem);
172 extern void mem_init(unsigned long low_start_mem,
173 unsigned long start_mem, unsigned long end_mem);
174 extern void show_mem(void);
175 extern void oom(struct task_struct * task);
176 extern void si_meminfo(struct sysinfo * val);
177
178
179
180 extern void * vmalloc(unsigned long size);
181 extern void vfree(void * addr);
182 extern int vread(char *buf, char *addr, int count);
183
184
185
186 extern void swap_free(unsigned long page_nr);
187 extern unsigned long swap_duplicate(unsigned long page_nr);
188 extern unsigned long swap_in(unsigned long entry);
189 extern void si_swapinfo(struct sysinfo * val);
190 extern void rw_swap_page(int rw, unsigned long nr, char * buf);
191
192
193 extern int do_mmap(struct file * file, unsigned long addr, unsigned long len,
194 unsigned long prot, unsigned long flags, unsigned long off);
195 extern void merge_segments(struct vm_area_struct *);
196 extern void insert_vm_struct(struct task_struct *, struct vm_area_struct *);
197 extern int do_munmap(unsigned long, size_t);
198
199 #define read_swap_page(nr,buf) \
200 rw_swap_page(READ,(nr),(buf))
201 #define write_swap_page(nr,buf) \
202 rw_swap_page(WRITE,(nr),(buf))
203
204 #define invalidate() \
205 __asm__ __volatile__("movl %%cr3,%%eax\n\tmovl %%eax,%%cr3": : :"ax")
206
207 extern unsigned long high_memory;
208
209 #define MAP_NR(addr) ((addr) >> PAGE_SHIFT)
210 #define MAP_PAGE_RESERVED (1<<15)
211
212 extern unsigned short * mem_map;
213
214 #define PAGE_PRESENT 0x001
215 #define PAGE_RW 0x002
216 #define PAGE_USER 0x004
217 #define PAGE_PWT 0x008
218 #define PAGE_PCD 0x010
219 #define PAGE_ACCESSED 0x020
220 #define PAGE_DIRTY 0x040
221 #define PAGE_COW 0x200
222
223 #define PAGE_PRIVATE (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED | PAGE_COW)
224 #define PAGE_SHARED (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)
225 #define PAGE_COPY (PAGE_PRESENT | PAGE_USER | PAGE_ACCESSED | PAGE_COW)
226 #define PAGE_READONLY (PAGE_PRESENT | PAGE_USER | PAGE_ACCESSED)
227 #define PAGE_TABLE (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)
228
229 #define GFP_BUFFER 0x00
230 #define GFP_ATOMIC 0x01
231 #define GFP_USER 0x02
232 #define GFP_KERNEL 0x03
233 #define GFP_NOBUFFER 0x04
234
235
236
237
238
239
240
241 #define SHM_SWP_TYPE 0x41
242 extern void shm_no_page (ulong *);
243
244
245
246
247 #define SWAP_CACHE_INFO
248
249 extern unsigned long * swap_cache;
250
251 #ifdef SWAP_CACHE_INFO
252 extern unsigned long swap_cache_add_total;
253 extern unsigned long swap_cache_add_success;
254 extern unsigned long swap_cache_del_total;
255 extern unsigned long swap_cache_del_success;
256 extern unsigned long swap_cache_find_total;
257 extern unsigned long swap_cache_find_success;
258 #endif
259
260 extern inline unsigned long in_swap_cache(unsigned long addr)
261 {
262 return swap_cache[addr >> PAGE_SHIFT];
263 }
264
265 extern inline long find_in_swap_cache (unsigned long addr)
266 {
267 unsigned long entry;
268
269 #ifdef SWAP_CACHE_INFO
270 swap_cache_find_total++;
271 #endif
272 __asm__ __volatile__("xchgl %0,%1"
273 :"=m" (swap_cache[addr >> PAGE_SHIFT]),
274 "=r" (entry)
275 :"0" (swap_cache[addr >> PAGE_SHIFT]),
276 "1" (0));
277 #ifdef SWAP_CACHE_INFO
278 if (entry)
279 swap_cache_find_success++;
280 #endif
281 return entry;
282 }
283
284 extern inline int delete_from_swap_cache(unsigned long addr)
285 {
286 unsigned long entry;
287
288 #ifdef SWAP_CACHE_INFO
289 swap_cache_del_total++;
290 #endif
291 __asm__ __volatile__("xchgl %0,%1"
292 :"=m" (swap_cache[addr >> PAGE_SHIFT]),
293 "=r" (entry)
294 :"0" (swap_cache[addr >> PAGE_SHIFT]),
295 "1" (0));
296 if (entry) {
297 #ifdef SWAP_CACHE_INFO
298 swap_cache_del_success++;
299 #endif
300 swap_free(entry);
301 return 1;
302 }
303 return 0;
304 }
305
306 #endif
307
308 #endif