Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_SWAP_H |
2 | #define _LINUX_SWAP_H | |
3 | ||
4 | #include <linux/config.h> | |
5 | #include <linux/spinlock.h> | |
6 | #include <linux/linkage.h> | |
7 | #include <linux/mmzone.h> | |
8 | #include <linux/list.h> | |
9 | #include <linux/sched.h> | |
542d1c88 AM |
10 | #include <linux/pagemap.h> |
11 | ||
1da177e4 LT |
12 | #include <asm/atomic.h> |
13 | #include <asm/page.h> | |
14 | ||
15 | #define SWAP_FLAG_PREFER 0x8000 /* set if swap priority specified */ | |
16 | #define SWAP_FLAG_PRIO_MASK 0x7fff | |
17 | #define SWAP_FLAG_PRIO_SHIFT 0 | |
18 | ||
19 | static inline int current_is_kswapd(void) | |
20 | { | |
21 | return current->flags & PF_KSWAPD; | |
22 | } | |
23 | ||
24 | /* | |
25 | * MAX_SWAPFILES defines the maximum number of swaptypes: things which can | |
26 | * be swapped to. The swap type and the offset into that swap type are | |
27 | * encoded into pte's and into pgoff_t's in the swapcache. Using five bits | |
28 | * for the type means that the maximum number of swapcache pages is 27 bits | |
29 | * on 32-bit-pgoff_t architectures. And that assumes that the architecture packs | |
30 | * the type/offset into the pte as 5/27 as well. | |
31 | */ | |
32 | #define MAX_SWAPFILES_SHIFT 5 | |
33 | #define MAX_SWAPFILES (1 << MAX_SWAPFILES_SHIFT) | |
34 | ||
35 | /* | |
36 | * Magic header for a swap area. The first part of the union is | |
37 | * what the swap magic looks like for the old (limited to 128MB) | |
38 | * swap area format, the second part of the union adds - in the | |
39 | * old reserved area - some extra information. Note that the first | |
40 | * kilobyte is reserved for boot loader or disk label stuff... | |
41 | * | |
42 | * Having the magic at the end of the PAGE_SIZE makes detecting swap | |
43 | * areas somewhat tricky on machines that support multiple page sizes. | |
44 | * For 2.5 we'll probably want to move the magic to just beyond the | |
45 | * bootbits... | |
46 | */ | |
47 | union swap_header { | |
48 | struct { | |
49 | char reserved[PAGE_SIZE - 10]; | |
50 | char magic[10]; /* SWAP-SPACE or SWAPSPACE2 */ | |
51 | } magic; | |
52 | struct { | |
53 | char bootbits[1024]; /* Space for disklabel etc. */ | |
54 | unsigned int version; | |
55 | unsigned int last_page; | |
56 | unsigned int nr_badpages; | |
57 | unsigned int padding[125]; | |
58 | unsigned int badpages[1]; | |
59 | } info; | |
60 | }; | |
61 | ||
62 | /* A swap entry has to fit into a "unsigned long", as | |
63 | * the entry is hidden in the "index" field of the | |
64 | * swapper address space. | |
65 | */ | |
66 | typedef struct { | |
67 | unsigned long val; | |
68 | } swp_entry_t; | |
69 | ||
70 | /* | |
71 | * current->reclaim_state points to one of these when a task is running | |
72 | * memory reclaim | |
73 | */ | |
74 | struct reclaim_state { | |
75 | unsigned long reclaimed_slab; | |
76 | }; | |
77 | ||
78 | #ifdef __KERNEL__ | |
79 | ||
80 | struct address_space; | |
81 | struct sysinfo; | |
82 | struct writeback_control; | |
83 | struct zone; | |
84 | ||
85 | /* | |
86 | * A swap extent maps a range of a swapfile's PAGE_SIZE pages onto a range of | |
87 | * disk blocks. A list of swap extents maps the entire swapfile. (Where the | |
88 | * term `swapfile' refers to either a blockdevice or an IS_REG file. Apart | |
89 | * from setup, they're handled identically. | |
90 | * | |
91 | * We always assume that blocks are of size PAGE_SIZE. | |
92 | */ | |
93 | struct swap_extent { | |
94 | struct list_head list; | |
95 | pgoff_t start_page; | |
96 | pgoff_t nr_pages; | |
97 | sector_t start_block; | |
98 | }; | |
99 | ||
100 | /* | |
101 | * Max bad pages in the new format.. | |
102 | */ | |
103 | #define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x) | |
104 | #define MAX_SWAP_BADPAGES \ | |
105 | ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int)) | |
106 | ||
107 | enum { | |
108 | SWP_USED = (1 << 0), /* is slot in swap_info[] used? */ | |
109 | SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */ | |
110 | SWP_ACTIVE = (SWP_USED | SWP_WRITEOK), | |
111 | }; | |
112 | ||
113 | #define SWAP_CLUSTER_MAX 32 | |
114 | ||
115 | #define SWAP_MAP_MAX 0x7fff | |
116 | #define SWAP_MAP_BAD 0x8000 | |
117 | ||
118 | /* | |
119 | * The in-memory structure used to track swap areas. | |
120 | * extent_list.prev points at the lowest-index extent. That list is | |
121 | * sorted. | |
122 | */ | |
123 | struct swap_info_struct { | |
124 | unsigned int flags; | |
125 | spinlock_t sdev_lock; | |
126 | struct file *swap_file; | |
127 | struct block_device *bdev; | |
128 | struct list_head extent_list; | |
129 | int nr_extents; | |
130 | struct swap_extent *curr_swap_extent; | |
131 | unsigned old_block_size; | |
132 | unsigned short * swap_map; | |
133 | unsigned int lowest_bit; | |
134 | unsigned int highest_bit; | |
135 | unsigned int cluster_next; | |
136 | unsigned int cluster_nr; | |
137 | int prio; /* swap priority */ | |
138 | int pages; | |
139 | unsigned long max; | |
140 | unsigned long inuse_pages; | |
141 | int next; /* next entry on swap list */ | |
142 | }; | |
143 | ||
144 | struct swap_list_t { | |
145 | int head; /* head of priority-ordered swapfile list */ | |
146 | int next; /* swapfile to be used next */ | |
147 | }; | |
148 | ||
149 | /* Swap 50% full? Release swapcache more aggressively.. */ | |
150 | #define vm_swap_full() (nr_swap_pages*2 < total_swap_pages) | |
151 | ||
152 | /* linux/mm/oom_kill.c */ | |
79b9ce31 | 153 | extern void out_of_memory(unsigned int __nocast gfp_mask, int order); |
1da177e4 LT |
154 | |
155 | /* linux/mm/memory.c */ | |
156 | extern void swapin_readahead(swp_entry_t, unsigned long, struct vm_area_struct *); | |
157 | ||
158 | /* linux/mm/page_alloc.c */ | |
159 | extern unsigned long totalram_pages; | |
160 | extern unsigned long totalhigh_pages; | |
161 | extern long nr_swap_pages; | |
162 | extern unsigned int nr_free_pages(void); | |
163 | extern unsigned int nr_free_pages_pgdat(pg_data_t *pgdat); | |
164 | extern unsigned int nr_free_buffer_pages(void); | |
165 | extern unsigned int nr_free_pagecache_pages(void); | |
166 | ||
167 | /* linux/mm/swap.c */ | |
168 | extern void FASTCALL(lru_cache_add(struct page *)); | |
169 | extern void FASTCALL(lru_cache_add_active(struct page *)); | |
170 | extern void FASTCALL(activate_page(struct page *)); | |
171 | extern void FASTCALL(mark_page_accessed(struct page *)); | |
172 | extern void lru_add_drain(void); | |
173 | extern int rotate_reclaimable_page(struct page *page); | |
174 | extern void swap_setup(void); | |
175 | ||
176 | /* linux/mm/vmscan.c */ | |
1ad539b2 | 177 | extern int try_to_free_pages(struct zone **, unsigned int); |
753ee728 | 178 | extern int zone_reclaim(struct zone *, unsigned int, unsigned int); |
1da177e4 LT |
179 | extern int shrink_all_memory(int); |
180 | extern int vm_swappiness; | |
181 | ||
182 | #ifdef CONFIG_MMU | |
183 | /* linux/mm/shmem.c */ | |
184 | extern int shmem_unuse(swp_entry_t entry, struct page *page); | |
185 | #endif /* CONFIG_MMU */ | |
186 | ||
187 | extern void swap_unplug_io_fn(struct backing_dev_info *, struct page *); | |
188 | ||
189 | #ifdef CONFIG_SWAP | |
190 | /* linux/mm/page_io.c */ | |
191 | extern int swap_readpage(struct file *, struct page *); | |
192 | extern int swap_writepage(struct page *page, struct writeback_control *wbc); | |
193 | extern int rw_swap_page_sync(int, swp_entry_t, struct page *); | |
194 | ||
195 | /* linux/mm/swap_state.c */ | |
196 | extern struct address_space swapper_space; | |
197 | #define total_swapcache_pages swapper_space.nrpages | |
198 | extern void show_swap_cache_info(void); | |
199 | extern int add_to_swap(struct page *); | |
200 | extern void __delete_from_swap_cache(struct page *); | |
201 | extern void delete_from_swap_cache(struct page *); | |
202 | extern int move_to_swap_cache(struct page *, swp_entry_t); | |
203 | extern int move_from_swap_cache(struct page *, unsigned long, | |
204 | struct address_space *); | |
205 | extern void free_page_and_swap_cache(struct page *); | |
206 | extern void free_pages_and_swap_cache(struct page **, int); | |
207 | extern struct page * lookup_swap_cache(swp_entry_t); | |
208 | extern struct page * read_swap_cache_async(swp_entry_t, struct vm_area_struct *vma, | |
209 | unsigned long addr); | |
210 | /* linux/mm/swapfile.c */ | |
211 | extern long total_swap_pages; | |
212 | extern unsigned int nr_swapfiles; | |
213 | extern struct swap_info_struct swap_info[]; | |
214 | extern void si_swapinfo(struct sysinfo *); | |
215 | extern swp_entry_t get_swap_page(void); | |
216 | extern int swap_duplicate(swp_entry_t); | |
217 | extern int valid_swaphandles(swp_entry_t, unsigned long *); | |
218 | extern void swap_free(swp_entry_t); | |
219 | extern void free_swap_and_cache(swp_entry_t); | |
220 | extern sector_t map_swap_page(struct swap_info_struct *, pgoff_t); | |
221 | extern struct swap_info_struct *get_swap_info_struct(unsigned); | |
222 | extern int can_share_swap_page(struct page *); | |
223 | extern int remove_exclusive_swap_page(struct page *); | |
224 | struct backing_dev_info; | |
225 | ||
226 | extern struct swap_list_t swap_list; | |
227 | extern spinlock_t swaplock; | |
228 | ||
229 | #define swap_list_lock() spin_lock(&swaplock) | |
230 | #define swap_list_unlock() spin_unlock(&swaplock) | |
231 | #define swap_device_lock(p) spin_lock(&p->sdev_lock) | |
232 | #define swap_device_unlock(p) spin_unlock(&p->sdev_lock) | |
233 | ||
234 | /* linux/mm/thrash.c */ | |
235 | extern struct mm_struct * swap_token_mm; | |
236 | extern unsigned long swap_token_default_timeout; | |
237 | extern void grab_swap_token(void); | |
238 | extern void __put_swap_token(struct mm_struct *); | |
239 | ||
240 | static inline int has_swap_token(struct mm_struct *mm) | |
241 | { | |
242 | return (mm == swap_token_mm); | |
243 | } | |
244 | ||
245 | static inline void put_swap_token(struct mm_struct *mm) | |
246 | { | |
247 | if (has_swap_token(mm)) | |
248 | __put_swap_token(mm); | |
249 | } | |
250 | ||
251 | #else /* CONFIG_SWAP */ | |
252 | ||
253 | #define total_swap_pages 0 | |
254 | #define total_swapcache_pages 0UL | |
255 | ||
256 | #define si_swapinfo(val) \ | |
257 | do { (val)->freeswap = (val)->totalswap = 0; } while (0) | |
258 | #define free_page_and_swap_cache(page) \ | |
259 | page_cache_release(page) | |
260 | #define free_pages_and_swap_cache(pages, nr) \ | |
261 | release_pages((pages), (nr), 0); | |
262 | ||
263 | #define show_swap_cache_info() /*NOTHING*/ | |
264 | #define free_swap_and_cache(swp) /*NOTHING*/ | |
265 | #define swap_duplicate(swp) /*NOTHING*/ | |
266 | #define swap_free(swp) /*NOTHING*/ | |
267 | #define read_swap_cache_async(swp,vma,addr) NULL | |
268 | #define lookup_swap_cache(swp) NULL | |
269 | #define valid_swaphandles(swp, off) 0 | |
270 | #define can_share_swap_page(p) 0 | |
271 | #define move_to_swap_cache(p, swp) 1 | |
272 | #define move_from_swap_cache(p, i, m) 1 | |
273 | #define __delete_from_swap_cache(p) /*NOTHING*/ | |
274 | #define delete_from_swap_cache(p) /*NOTHING*/ | |
275 | #define swap_token_default_timeout 0 | |
276 | ||
277 | static inline int remove_exclusive_swap_page(struct page *p) | |
278 | { | |
279 | return 0; | |
280 | } | |
281 | ||
282 | static inline swp_entry_t get_swap_page(void) | |
283 | { | |
284 | swp_entry_t entry; | |
285 | entry.val = 0; | |
286 | return entry; | |
287 | } | |
288 | ||
289 | /* linux/mm/thrash.c */ | |
290 | #define put_swap_token(x) do { } while(0) | |
291 | #define grab_swap_token() do { } while(0) | |
292 | #define has_swap_token(x) 0 | |
293 | ||
294 | #endif /* CONFIG_SWAP */ | |
295 | #endif /* __KERNEL__*/ | |
296 | #endif /* _LINUX_SWAP_H */ |