Merge with Linux 2.4.0-test5-pre3.
[linux-2.6/linux-mips.git] / include / linux / swap.h
blob9226ce0a5e98727d2e9e8291954a9f464daa98e4
1 #ifndef _LINUX_SWAP_H
2 #define _LINUX_SWAP_H
4 #include <linux/spinlock.h>
5 #include <asm/page.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 8
13 union swap_header {
14 struct
16 char reserved[PAGE_SIZE - 10];
17 char magic[10];
18 } magic;
19 struct
21 char bootbits[1024]; /* Space for disklabel etc. */
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;
30 #ifdef __KERNEL__
33 * Max bad pages in the new format..
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))
39 #include <asm/atomic.h>
41 #define SWP_USED 1
42 #define SWP_WRITEOK 3
44 #define SWAP_CLUSTER_MAX 32
46 #define SWAP_MAP_MAX 0x7fff
47 #define SWAP_MAP_BAD 0x8000
49 struct 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; /* swap priority */
61 int pages;
62 unsigned long max;
63 int next; /* next entry on swap list */
66 extern int nr_swap_pages;
67 FASTCALL(unsigned int nr_free_pages(void));
68 FASTCALL(unsigned int nr_free_buffer_pages(void));
69 FASTCALL(unsigned int nr_free_highpages(void));
70 extern int nr_lru_pages;
71 extern atomic_t nr_async_pages;
72 extern struct address_space swapper_space;
73 extern atomic_t page_cache_size;
74 extern atomic_t buffermem_pages;
76 /* Incomplete types for prototype declarations: */
77 struct task_struct;
78 struct vm_area_struct;
79 struct sysinfo;
81 struct zone_t;
82 /* linux/ipc/shm.c */
83 extern int shm_swap(int, int);
85 /* linux/mm/swap.c */
86 extern void swap_setup(void);
88 /* linux/mm/vmscan.c */
89 extern int try_to_free_pages(unsigned int gfp_mask);
91 /* linux/mm/page_io.c */
92 extern void rw_swap_page(int, struct page *, int);
93 extern void rw_swap_page_nolock(int, swp_entry_t, char *, int);
95 /* linux/mm/page_alloc.c */
97 /* linux/mm/swap_state.c */
98 extern void show_swap_cache_info(void);
99 extern void add_to_swap_cache(struct page *, swp_entry_t);
100 extern int swap_check_entry(unsigned long);
101 extern struct page * lookup_swap_cache(swp_entry_t);
102 extern struct page * read_swap_cache_async(swp_entry_t, int);
103 #define read_swap_cache(entry) read_swap_cache_async(entry, 1);
106 * Make these inline later once they are working properly.
108 extern void __delete_from_swap_cache(struct page *page);
109 extern void delete_from_swap_cache(struct page *page);
110 extern void delete_from_swap_cache_nolock(struct page *page);
111 extern void free_page_and_swap_cache(struct page *page);
113 /* linux/mm/swapfile.c */
114 extern unsigned int nr_swapfiles;
115 extern struct swap_info_struct swap_info[];
116 extern int is_swap_partition(kdev_t);
117 extern void si_swapinfo(struct sysinfo *);
118 extern swp_entry_t __get_swap_page(unsigned short);
119 extern void get_swaphandle_info(swp_entry_t, unsigned long *, kdev_t *,
120 struct inode **);
121 extern int swap_duplicate(swp_entry_t);
122 extern int swap_count(struct page *);
123 extern int valid_swaphandles(swp_entry_t, unsigned long *);
124 #define get_swap_page() __get_swap_page(1)
125 extern void __swap_free(swp_entry_t, unsigned short);
126 #define swap_free(entry) __swap_free((entry), 1)
127 struct swap_list_t {
128 int head; /* head of priority-ordered swapfile list */
129 int next; /* swapfile to be used next */
131 extern struct swap_list_t swap_list;
132 asmlinkage long sys_swapoff(const char *);
133 asmlinkage long sys_swapon(const char *, int);
135 #define SWAP_CACHE_INFO
137 #ifdef SWAP_CACHE_INFO
138 extern unsigned long swap_cache_add_total;
139 extern unsigned long swap_cache_del_total;
140 extern unsigned long swap_cache_find_total;
141 extern unsigned long swap_cache_find_success;
142 #endif
145 * Work out if there are any other processes sharing this page, ignoring
146 * any page reference coming from the swap cache, or from outstanding
147 * swap IO on this page. (The page cache _does_ count as another valid
148 * reference to the page, however.)
150 static inline int is_page_shared(struct page *page)
152 unsigned int count;
153 if (PageReserved(page))
154 return 1;
155 count = page_count(page);
156 if (PageSwapCache(page))
157 count += swap_count(page) - 2 - !!page->buffers;
158 return count > 1;
161 extern spinlock_t pagemap_lru_lock;
164 * Helper macros for lru_pages handling.
166 #define lru_cache_add(page) \
167 do { \
168 spin_lock(&pagemap_lru_lock); \
169 list_add(&(page)->lru, &lru_cache); \
170 nr_lru_pages++; \
171 spin_unlock(&pagemap_lru_lock); \
172 } while (0)
174 #define __lru_cache_del(page) \
175 do { \
176 list_del(&(page)->lru); \
177 nr_lru_pages--; \
178 } while (0)
180 #define lru_cache_del(page) \
181 do { \
182 if (!PageLocked(page)) \
183 BUG(); \
184 spin_lock(&pagemap_lru_lock); \
185 __lru_cache_del(page); \
186 spin_unlock(&pagemap_lru_lock); \
187 } while (0)
189 extern spinlock_t swaplock;
191 #define swap_list_lock() spin_lock(&swaplock)
192 #define swap_list_unlock() spin_unlock(&swaplock)
193 #define swap_device_lock(p) spin_lock(&p->sdev_lock)
194 #define swap_device_unlock(p) spin_unlock(&p->sdev_lock)
196 #endif /* __KERNEL__*/
198 #endif /* _LINUX_SWAP_H */