1#ifndef _LINUX_SWAP_H
2#define _LINUX_SWAP_H
3
4#include <linux/spinlock.h>
5#include <asm/page.h>
6
7#define SWAP_FLAG_PREFER 0x8000
8#define SWAP_FLAG_PRIO_MASK 0x7fff
9#define SWAP_FLAG_PRIO_SHIFT 0
10
11#define MAX_SWAPFILES 8
12
13union swap_header {
14 struct
15 {
16 char reserved[PAGE_SIZE - 10];
17 char magic[10];
18 } magic;
19 struct
20 {
21 char bootbits[1024];
22 unsigned int version;
23 unsigned int last_page;
24 unsigned int nr_badpages;
25 unsigned int padding[125];
26 unsigned int badpages[1];
27 } info;
28};
29
30#ifdef __KERNEL__
31
32
33
34
35#define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x)
36#define MAX_SWAP_BADPAGES \
37 ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int))
38
39#include <asm/atomic.h>
40
41#define SWP_USED 1
42#define SWP_WRITEOK 3
43
44#define SWAP_CLUSTER_MAX 32
45
46#define SWAP_MAP_MAX 0x7fff
47#define SWAP_MAP_BAD 0x8000
48
49struct swap_info_struct {
50 unsigned int flags;
51 kdev_t swap_device;
52 spinlock_t sdev_lock;
53 struct dentry * swap_file;
54 struct vfsmount *swap_vfsmnt;
55 unsigned short * swap_map;
56 unsigned int lowest_bit;
57 unsigned int highest_bit;
58 unsigned int cluster_next;
59 unsigned int cluster_nr;
60 int prio;
61 int pages;
62 unsigned long max;
63 int next;
64};
65
66extern int nr_swap_pages;
67FASTCALL(unsigned int nr_free_pages(void));
68FASTCALL(unsigned int nr_inactive_clean_pages(void));
69FASTCALL(unsigned int nr_free_buffer_pages(void));
70extern int nr_active_pages;
71extern int nr_inactive_dirty_pages;
72extern atomic_t nr_async_pages;
73extern struct address_space swapper_space;
74extern atomic_t page_cache_size;
75extern atomic_t buffermem_pages;
76extern spinlock_t pagecache_lock;
77extern void __remove_inode_page(struct page *);
78
79
80struct task_struct;
81struct vm_area_struct;
82struct sysinfo;
83
84struct zone_t;
85
86
87extern int memory_pressure;
88extern void age_page_up(struct page *);
89extern void age_page_up_nolock(struct page *);
90extern void age_page_down(struct page *);
91extern void age_page_down_nolock(struct page *);
92extern void age_page_down_ageonly(struct page *);
93extern void deactivate_page(struct page *);
94extern void deactivate_page_nolock(struct page *);
95extern void activate_page(struct page *);
96extern void activate_page_nolock(struct page *);
97extern void lru_cache_add(struct page *);
98extern void __lru_cache_del(struct page *);
99extern void lru_cache_del(struct page *);
100extern void recalculate_vm_stats(void);
101extern void swap_setup(void);
102
103
104extern struct page * reclaim_page(zone_t *);
105extern wait_queue_head_t kswapd_wait;
106extern wait_queue_head_t kreclaimd_wait;
107extern int page_launder(int, int);
108extern int free_shortage(void);
109extern int inactive_shortage(void);
110extern void wakeup_kswapd(int);
111extern int try_to_free_pages(unsigned int gfp_mask);
112
113
114extern void rw_swap_page(int, struct page *, int);
115extern void rw_swap_page_nolock(int, swp_entry_t, char *, int);
116
117
118
119
120extern void show_swap_cache_info(void);
121extern void add_to_swap_cache(struct page *, swp_entry_t);
122extern int swap_check_entry(unsigned long);
123extern struct page * lookup_swap_cache(swp_entry_t);
124extern struct page * read_swap_cache_async(swp_entry_t, int);
125#define read_swap_cache(entry) read_swap_cache_async(entry, 1);
126
127
128extern int out_of_memory(void);
129extern void oom_kill(void);
130
131
132
133
134extern void __delete_from_swap_cache(struct page *page);
135extern void delete_from_swap_cache(struct page *page);
136extern void delete_from_swap_cache_nolock(struct page *page);
137extern void free_page_and_swap_cache(struct page *page);
138
139
140extern unsigned int nr_swapfiles;
141extern struct swap_info_struct swap_info[];
142extern int is_swap_partition(kdev_t);
143extern void si_swapinfo(struct sysinfo *);
144extern swp_entry_t __get_swap_page(unsigned short);
145extern void get_swaphandle_info(swp_entry_t, unsigned long *, kdev_t *,
146 struct inode **);
147extern int swap_duplicate(swp_entry_t);
148extern int swap_count(struct page *);
149extern int valid_swaphandles(swp_entry_t, unsigned long *);
150#define get_swap_page() __get_swap_page(1)
151extern void __swap_free(swp_entry_t, unsigned short);
152#define swap_free(entry) __swap_free((entry), 1)
153struct swap_list_t {
154 int head;
155 int next;
156};
157extern struct swap_list_t swap_list;
158asmlinkage long sys_swapoff(const char *);
159asmlinkage long sys_swapon(const char *, int);
160
161#define SWAP_CACHE_INFO
162
163#ifdef SWAP_CACHE_INFO
164extern unsigned long swap_cache_add_total;
165extern unsigned long swap_cache_del_total;
166extern unsigned long swap_cache_find_total;
167extern unsigned long swap_cache_find_success;
168#endif
169
170
171
172
173
174
175
176static inline int is_page_shared(struct page *page)
177{
178 unsigned int count;
179 if (PageReserved(page))
180 return 1;
181 count = page_count(page);
182 if (PageSwapCache(page))
183 count += swap_count(page) - 2 - !!page->buffers;
184 return count > 1;
185}
186
187extern spinlock_t pagemap_lru_lock;
188
189
190
191
192
193
194#define PAGE_AGE_START 2
195#define PAGE_AGE_ADV 3
196#define PAGE_AGE_MAX 64
197
198
199
200
201
202#define DEBUG_ADD_PAGE \
203 if (PageActive(page) || PageInactiveDirty(page) || \
204 PageInactiveClean(page)) BUG();
205
206#define ZERO_PAGE_BUG \
207 if (page_count(page) == 0) BUG();
208
209#define add_page_to_active_list(page) { \
210 DEBUG_ADD_PAGE \
211 ZERO_PAGE_BUG \
212 SetPageActive(page); \
213 list_add(&(page)->lru, &active_list); \
214 nr_active_pages++; \
215}
216
217#define add_page_to_inactive_dirty_list(page) { \
218 DEBUG_ADD_PAGE \
219 ZERO_PAGE_BUG \
220 SetPageInactiveDirty(page); \
221 list_add(&(page)->lru, &inactive_dirty_list); \
222 nr_inactive_dirty_pages++; \
223 page->zone->inactive_dirty_pages++; \
224}
225
226#define add_page_to_inactive_clean_list(page) { \
227 DEBUG_ADD_PAGE \
228 ZERO_PAGE_BUG \
229 SetPageInactiveClean(page); \
230 list_add(&(page)->lru, &page->zone->inactive_clean_list); \
231 page->zone->inactive_clean_pages++; \
232}
233
234#define del_page_from_active_list(page) { \
235 list_del(&(page)->lru); \
236 ClearPageActive(page); \
237 nr_active_pages--; \
238 DEBUG_ADD_PAGE \
239 ZERO_PAGE_BUG \
240}
241
242#define del_page_from_inactive_dirty_list(page) { \
243 list_del(&(page)->lru); \
244 ClearPageInactiveDirty(page); \
245 nr_inactive_dirty_pages--; \
246 page->zone->inactive_dirty_pages--; \
247 DEBUG_ADD_PAGE \
248 ZERO_PAGE_BUG \
249}
250
251#define del_page_from_inactive_clean_list(page) { \
252 list_del(&(page)->lru); \
253 ClearPageInactiveClean(page); \
254 page->zone->inactive_clean_pages--; \
255 DEBUG_ADD_PAGE \
256 ZERO_PAGE_BUG \
257}
258
259
260
261
262
263
264
265#define INACTIVE_SHIFT 6
266#define inactive_min(a,b) ((a) < (b) ? (a) : (b))
267#define inactive_target inactive_min((memory_pressure >> INACTIVE_SHIFT), \
268 (num_physpages / 4))
269
270
271
272
273
274
275
276
277#ifndef _LINUX_KDEV_T_H
278#include <linux/kdev_t.h>
279#endif
280#ifndef _LINUX_MAJOR_H
281#include <linux/major.h>
282#endif
283
284#define page_ramdisk(page) \
285 (page->buffers && (MAJOR(page->buffers->b_dev) == RAMDISK_MAJOR))
286
287extern spinlock_t swaplock;
288
289#define swap_list_lock() spin_lock(&swaplock)
290#define swap_list_unlock() spin_unlock(&swaplock)
291#define swap_device_lock(p) spin_lock(&p->sdev_lock)
292#define swap_device_unlock(p) spin_unlock(&p->sdev_lock)
293
294extern void shmem_unuse(swp_entry_t entry, struct page *page);
295
296#endif
297
298#endif
299