~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/include/linux/swap.h

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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  /* set if swap priority specified */
  8 #define SWAP_FLAG_PRIO_MASK     0x7fff
  9 #define SWAP_FLAG_PRIO_SHIFT    0
 10 
 11 #define MAX_SWAPFILES 8
 12 
 13 union swap_header {
 14         struct 
 15         {
 16                 char reserved[PAGE_SIZE - 10];
 17                 char magic[10];
 18         } magic;
 19         struct 
 20         {
 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;
 28 };
 29 
 30 #ifdef __KERNEL__
 31 
 32 /*
 33  * Max bad pages in the new format..
 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 
 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 */
 64 };
 65 
 66 extern int nr_swap_pages;
 67 FASTCALL(unsigned int nr_free_pages(void));
 68 FASTCALL(unsigned int nr_inactive_clean_pages(void));
 69 FASTCALL(unsigned int nr_free_buffer_pages(void));
 70 extern int nr_active_pages;
 71 extern int nr_inactive_dirty_pages;
 72 extern atomic_t nr_async_pages;
 73 extern struct address_space swapper_space;
 74 extern atomic_t page_cache_size;
 75 extern atomic_t buffermem_pages;
 76 extern spinlock_t pagecache_lock;
 77 extern void __remove_inode_page(struct page *);
 78 
 79 /* Incomplete types for prototype declarations: */
 80 struct task_struct;
 81 struct vm_area_struct;
 82 struct sysinfo;
 83 
 84 struct zone_t;
 85 
 86 /* linux/mm/swap.c */
 87 extern int memory_pressure;
 88 extern void age_page_up(struct page *);
 89 extern void age_page_up_nolock(struct page *);
 90 extern void age_page_down(struct page *);
 91 extern void age_page_down_nolock(struct page *);
 92 extern void age_page_down_ageonly(struct page *);
 93 extern void deactivate_page(struct page *);
 94 extern void deactivate_page_nolock(struct page *);
 95 extern void activate_page(struct page *);
 96 extern void activate_page_nolock(struct page *);
 97 extern void lru_cache_add(struct page *);
 98 extern void __lru_cache_del(struct page *);
 99 extern void lru_cache_del(struct page *);
100 extern void recalculate_vm_stats(void);
101 extern void swap_setup(void);
102 
103 /* linux/mm/vmscan.c */
104 extern struct page * reclaim_page(zone_t *);
105 extern wait_queue_head_t kswapd_wait;
106 extern wait_queue_head_t kreclaimd_wait;
107 extern int page_launder(int, int);
108 extern int free_shortage(void);
109 extern int inactive_shortage(void);
110 extern void wakeup_kswapd(int);
111 extern int try_to_free_pages(unsigned int gfp_mask);
112 
113 /* linux/mm/page_io.c */
114 extern void rw_swap_page(int, struct page *, int);
115 extern void rw_swap_page_nolock(int, swp_entry_t, char *, int);
116 
117 /* linux/mm/page_alloc.c */
118 
119 /* linux/mm/swap_state.c */
120 extern void show_swap_cache_info(void);
121 extern void add_to_swap_cache(struct page *, swp_entry_t);
122 extern int swap_check_entry(unsigned long);
123 extern struct page * lookup_swap_cache(swp_entry_t);
124 extern struct page * read_swap_cache_async(swp_entry_t, int);
125 #define read_swap_cache(entry) read_swap_cache_async(entry, 1);
126 
127 /* linux/mm/oom_kill.c */
128 extern int out_of_memory(void);
129 extern void oom_kill(void);
130 
131 /*
132  * Make these inline later once they are working properly.
133  */
134 extern void __delete_from_swap_cache(struct page *page);
135 extern void delete_from_swap_cache(struct page *page);
136 extern void delete_from_swap_cache_nolock(struct page *page);
137 extern void free_page_and_swap_cache(struct page *page);
138 
139 /* linux/mm/swapfile.c */
140 extern unsigned int nr_swapfiles;
141 extern struct swap_info_struct swap_info[];
142 extern int is_swap_partition(kdev_t);
143 extern void si_swapinfo(struct sysinfo *);
144 extern swp_entry_t __get_swap_page(unsigned short);
145 extern void get_swaphandle_info(swp_entry_t, unsigned long *, kdev_t *, 
146                                         struct inode **);
147 extern int swap_duplicate(swp_entry_t);
148 extern int swap_count(struct page *);
149 extern int valid_swaphandles(swp_entry_t, unsigned long *);
150 #define get_swap_page() __get_swap_page(1)
151 extern void __swap_free(swp_entry_t, unsigned short);
152 #define swap_free(entry) __swap_free((entry), 1)
153 struct swap_list_t {
154         int head;       /* head of priority-ordered swapfile list */
155         int next;       /* swapfile to be used next */
156 };
157 extern struct swap_list_t swap_list;
158 asmlinkage long sys_swapoff(const char *);
159 asmlinkage long sys_swapon(const char *, int);
160 
161 #define SWAP_CACHE_INFO
162 
163 #ifdef SWAP_CACHE_INFO
164 extern unsigned long swap_cache_add_total;
165 extern unsigned long swap_cache_del_total;
166 extern unsigned long swap_cache_find_total;
167 extern unsigned long swap_cache_find_success;
168 #endif
169 
170 /*
171  * Work out if there are any other processes sharing this page, ignoring
172  * any page reference coming from the swap cache, or from outstanding
173  * swap IO on this page.  (The page cache _does_ count as another valid
174  * reference to the page, however.)
175  */
176 static 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 
187 extern spinlock_t pagemap_lru_lock;
188 
189 /*
190  * Page aging defines.
191  * Since we do exponential decay of the page age, we
192  * can chose a fairly large maximum.
193  */
194 #define PAGE_AGE_START 2
195 #define PAGE_AGE_ADV 3
196 #define PAGE_AGE_MAX 64
197 
198 /*
199  * List add/del helper macros. These must be called
200  * with the pagemap_lru_lock held!
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  * In mm/swap.c::recalculate_vm_stats(), we substract
261  * inactive_target from memory_pressure every second.
262  * This means that memory_pressure is smoothed over
263  * 64 (1 << INACTIVE_SHIFT) seconds.
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  * Ugly ugly ugly HACK to make sure the inactive lists
272  * don't fill up with unfreeable ramdisk pages. We really
273  * want to fix the ramdisk driver to mark its pages as
274  * unfreeable instead of using dirty buffer magic, but the
275  * next code-change time is when 2.5 is forked...
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 
287 extern 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 
294 extern void shmem_unuse(swp_entry_t entry, struct page *page);
295 
296 #endif /* __KERNEL__*/
297 
298 #endif /* _LINUX_SWAP_H */
299 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.