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