4 #include <linux/spinlock.h>
7 #define SWAP_FLAG_PREFER 0x8000 /* set if swap priority specified */
8 #define SWAP_FLAG_PRIO_MASK 0x7fff
9 #define SWAP_FLAG_PRIO_SHIFT 0
11 #define MAX_SWAPFILES 32
14 * Magic header for a swap area. The first part of the union is
15 * what the swap magic looks like for the old (limited to 128MB)
16 * swap area format, the second part of the union adds - in the
17 * old reserved area - some extra information. Note that the first
18 * kilobyte is reserved for boot loader or disk label stuff...
20 * Having the magic at the end of the PAGE_SIZE makes detecting swap
21 * areas somewhat tricky on machines that support multiple page sizes.
22 * For 2.5 we'll probably want to move the magic to just beyond the
28 char reserved[PAGE_SIZE - 10];
29 char magic[10]; /* SWAP-SPACE or SWAPSPACE2 */
33 char bootbits[1024]; /* Space for disklabel etc. */
35 unsigned int last_page;
36 unsigned int nr_badpages;
37 unsigned int padding[125];
38 unsigned int badpages[1];
45 * Max bad pages in the new format..
47 #define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x)
48 #define MAX_SWAP_BADPAGES \
49 ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int))
51 #include <asm/atomic.h>
56 #define SWAP_CLUSTER_MAX 32
58 #define SWAP_MAP_MAX 0x7fff
59 #define SWAP_MAP_BAD 0x8000
62 * The in-memory structure used to track swap areas.
64 struct swap_info_struct {
68 struct dentry * swap_file;
69 struct vfsmount *swap_vfsmnt;
70 unsigned short * swap_map;
71 unsigned int lowest_bit;
72 unsigned int highest_bit;
73 unsigned int cluster_next;
74 unsigned int cluster_nr;
75 int prio; /* swap priority */
78 int next; /* next entry on swap list */
81 extern int nr_swap_pages;
83 /* Swap 50% full? Release swapcache more aggressively.. */
84 #define vm_swap_full() (nr_swap_pages*2 < total_swap_pages)
86 extern unsigned int nr_free_pages(void);
87 extern unsigned int nr_free_buffer_pages(void);
88 extern int nr_active_pages;
89 extern int nr_inactive_pages;
90 extern atomic_t page_cache_size;
91 extern atomic_t buffermem_pages;
93 extern spinlock_cacheline_t pagecache_lock_cacheline;
94 #define pagecache_lock (pagecache_lock_cacheline.lock)
96 extern void __remove_inode_page(struct page *);
98 /* Incomplete types for prototype declarations: */
100 struct vm_area_struct;
105 /* linux/mm/swap.c */
106 extern void FASTCALL(lru_cache_add(struct page *));
107 extern void FASTCALL(__lru_cache_del(struct page *));
108 extern void FASTCALL(lru_cache_del(struct page *));
110 extern void FASTCALL(activate_page(struct page *));
112 extern void swap_setup(void);
114 /* linux/mm/vmscan.c */
115 extern wait_queue_head_t kswapd_wait;
116 extern int FASTCALL(try_to_free_pages_zone(zone_t *, unsigned int));
117 extern int FASTCALL(try_to_free_pages(unsigned int));
119 /* linux/mm/page_io.c */
120 extern void rw_swap_page(int, struct page *);
121 extern void rw_swap_page_nolock(int, swp_entry_t, char *);
123 /* linux/mm/page_alloc.c */
125 /* linux/mm/swap_state.c */
126 #define SWAP_CACHE_INFO
127 #ifdef SWAP_CACHE_INFO
128 extern void show_swap_cache_info(void);
130 extern int add_to_swap_cache(struct page *, swp_entry_t);
131 extern void __delete_from_swap_cache(struct page *page);
132 extern void delete_from_swap_cache(struct page *page);
133 extern void free_page_and_swap_cache(struct page *page);
134 extern struct page * lookup_swap_cache(swp_entry_t);
135 extern struct page * read_swap_cache_async(swp_entry_t);
137 /* linux/mm/oom_kill.c */
138 extern void out_of_memory(void);
140 /* linux/mm/swapfile.c */
141 extern int total_swap_pages;
142 extern unsigned int nr_swapfiles;
143 extern struct swap_info_struct swap_info[];
144 extern int is_swap_partition(kdev_t);
145 extern void si_swapinfo(struct sysinfo *);
146 extern swp_entry_t get_swap_page(void);
147 extern void get_swaphandle_info(swp_entry_t, unsigned long *, kdev_t *,
149 extern int swap_duplicate(swp_entry_t);
150 extern int valid_swaphandles(swp_entry_t, unsigned long *);
151 extern void swap_free(swp_entry_t);
152 extern void free_swap_and_cache(swp_entry_t);
154 int head; /* head of priority-ordered swapfile list */
155 int next; /* swapfile to be used next */
157 extern struct swap_list_t swap_list;
158 asmlinkage long sys_swapoff(const char *);
159 asmlinkage long sys_swapon(const char *, int);
161 extern spinlock_cacheline_t pagemap_lru_lock_cacheline;
162 #define pagemap_lru_lock pagemap_lru_lock_cacheline.lock
164 extern void FASTCALL(mark_page_accessed(struct page *));
167 * List add/del helper macros. These must be called
168 * with the pagemap_lru_lock held!
170 #define DEBUG_LRU_PAGE(page) \
172 if (!PageLRU(page)) \
174 if (PageActive(page)) \
178 #define add_page_to_active_list(page) \
180 DEBUG_LRU_PAGE(page); \
181 SetPageActive(page); \
182 list_add(&(page)->lru, &active_list); \
186 #define add_page_to_inactive_list(page) \
188 DEBUG_LRU_PAGE(page); \
189 list_add(&(page)->lru, &inactive_list); \
190 nr_inactive_pages++; \
193 #define del_page_from_active_list(page) \
195 list_del(&(page)->lru); \
196 ClearPageActive(page); \
200 #define del_page_from_inactive_list(page) \
202 list_del(&(page)->lru); \
203 nr_inactive_pages--; \
206 extern spinlock_t swaplock;
208 #define swap_list_lock() spin_lock(&swaplock)
209 #define swap_list_unlock() spin_unlock(&swaplock)
210 #define swap_device_lock(p) spin_lock(&p->sdev_lock)
211 #define swap_device_unlock(p) spin_unlock(&p->sdev_lock)
213 extern void shmem_unuse(swp_entry_t entry, struct page *page);
215 #endif /* __KERNEL__*/
217 #endif /* _LINUX_SWAP_H */