linux-bk/include/linux/swap.h
<<
>>
Prefs
   1#ifndef _LINUX_SWAP_H
   2#define _LINUX_SWAP_H
   3
   4#include <linux/spinlock.h>
   5#include <linux/kdev_t.h>
   6#include <linux/linkage.h>
   7#include <linux/mmzone.h>
   8#include <linux/list.h>
   9#include <asm/page.h>
  10
  11#define SWAP_FLAG_PREFER        0x8000  /* set if swap priority specified */
  12#define SWAP_FLAG_PRIO_MASK     0x7fff
  13#define SWAP_FLAG_PRIO_SHIFT    0
  14
  15/*
  16 * MAX_SWAPFILES defines the maximum number of swaptypes: things which can
  17 * be swapped to.  The swap type and the offset into that swap type are
  18 * encoded into pte's and into pgoff_t's in the swapcache.  Using five bits
  19 * for the type means that the maximum number of swapcache pages is 27 bits
  20 * on 32-bit-pgoff_t architectures.  And that assumes that the architecture packs
  21 * the type/offset into the pte as 5/27 as well.
  22 */
  23#define MAX_SWAPFILES_SHIFT     5
  24#define MAX_SWAPFILES           (1 << MAX_SWAPFILES_SHIFT)
  25
  26/*
  27 * Magic header for a swap area. The first part of the union is
  28 * what the swap magic looks like for the old (limited to 128MB)
  29 * swap area format, the second part of the union adds - in the
  30 * old reserved area - some extra information. Note that the first
  31 * kilobyte is reserved for boot loader or disk label stuff...
  32 *
  33 * Having the magic at the end of the PAGE_SIZE makes detecting swap
  34 * areas somewhat tricky on machines that support multiple page sizes.
  35 * For 2.5 we'll probably want to move the magic to just beyond the
  36 * bootbits...
  37 */
  38union swap_header {
  39        struct 
  40        {
  41                char reserved[PAGE_SIZE - 10];
  42                char magic[10];                 /* SWAP-SPACE or SWAPSPACE2 */
  43        } magic;
  44        struct 
  45        {
  46                char         bootbits[1024];    /* Space for disklabel etc. */
  47                unsigned int version;
  48                unsigned int last_page;
  49                unsigned int nr_badpages;
  50                unsigned int padding[125];
  51                unsigned int badpages[1];
  52        } info;
  53};
  54
  55 /* A swap entry has to fit into a "unsigned long", as
  56  * the entry is hidden in the "index" field of the
  57  * swapper address space.
  58  */
  59typedef struct {
  60        unsigned long val;
  61} swp_entry_t;
  62
  63#ifdef __KERNEL__
  64
  65/*
  66 * A swap extent maps a range of a swapfile's PAGE_SIZE pages onto a range of
  67 * disk blocks.  A list of swap extents maps the entire swapfile.  (Where the
  68 * term `swapfile' refers to either a blockdevice or an IS_REG file.  Apart
  69 * from setup, they're handled identically.
  70 *
  71 * We always assume that blocks are of size PAGE_SIZE.
  72 */
  73struct swap_extent {
  74        struct list_head list;
  75        pgoff_t start_page;
  76        pgoff_t nr_pages;
  77        sector_t start_block;
  78};
  79
  80/*
  81 * Max bad pages in the new format..
  82 */
  83#define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x)
  84#define MAX_SWAP_BADPAGES \
  85        ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int))
  86
  87#include <asm/atomic.h>
  88
  89enum {
  90        SWP_USED        = (1 << 0),     /* is slot in swap_info[] used? */
  91        SWP_WRITEOK     = (1 << 1),     /* ok to write to this swap?    */
  92        SWP_ACTIVE      = (SWP_USED | SWP_WRITEOK),
  93};
  94
  95#define SWAP_CLUSTER_MAX 32
  96
  97#define SWAP_MAP_MAX    0x7fff
  98#define SWAP_MAP_BAD    0x8000
  99
 100/*
 101 * The in-memory structure used to track swap areas.
 102 * extent_list.prev points at the lowest-index extent.  That list is
 103 * sorted.
 104 */
 105struct swap_info_struct {
 106        unsigned int flags;
 107        spinlock_t sdev_lock;
 108        struct file *swap_file;
 109        struct block_device *bdev;
 110        struct list_head extent_list;
 111        int nr_extents;
 112        struct swap_extent *curr_swap_extent;
 113        unsigned old_block_size;
 114        unsigned short * swap_map;
 115        unsigned int lowest_bit;
 116        unsigned int highest_bit;
 117        unsigned int cluster_next;
 118        unsigned int cluster_nr;
 119        int prio;                       /* swap priority */
 120        int pages;
 121        unsigned long max;
 122        int next;                       /* next entry on swap list */
 123};
 124
 125struct inode;
 126extern int nr_swap_pages;
 127
 128/* Swap 50% full? Release swapcache more aggressively.. */
 129#define vm_swap_full() (nr_swap_pages*2 < total_swap_pages)
 130
 131extern unsigned long totalram_pages;
 132extern unsigned long totalhigh_pages;
 133extern unsigned int nr_free_pages(void);
 134extern unsigned int nr_free_buffer_pages(void);
 135extern unsigned int nr_free_pagecache_pages(void);
 136extern void __remove_inode_page(struct page *);
 137
 138/* Incomplete types for prototype declarations: */
 139struct task_struct;
 140struct vm_area_struct;
 141struct sysinfo;
 142struct address_space;
 143struct zone_t;
 144
 145/* linux/mm/rmap.c */
 146extern int FASTCALL(page_referenced(struct page *));
 147extern void FASTCALL(page_add_rmap(struct page *, pte_t *));
 148extern void FASTCALL(page_remove_rmap(struct page *, pte_t *));
 149extern int FASTCALL(try_to_unmap(struct page *));
 150extern int FASTCALL(page_over_rsslimit(struct page *));
 151
 152/* return values of try_to_unmap */
 153#define SWAP_SUCCESS    0
 154#define SWAP_AGAIN      1
 155#define SWAP_FAIL       2
 156#define SWAP_ERROR      3
 157
 158/* linux/mm/swap.c */
 159extern void FASTCALL(lru_cache_add(struct page *));
 160extern void FASTCALL(__lru_cache_del(struct page *));
 161extern void FASTCALL(lru_cache_del(struct page *));
 162
 163extern void FASTCALL(activate_page(struct page *));
 164
 165extern void swap_setup(void);
 166
 167/* linux/mm/vmscan.c */
 168extern wait_queue_head_t kswapd_wait;
 169extern int FASTCALL(try_to_free_pages(zone_t *, unsigned int, unsigned int));
 170
 171/* linux/mm/page_io.c */
 172int swap_readpage(struct file *file, struct page *page);
 173int swap_writepage(struct page *page);
 174int rw_swap_page_sync(int rw, swp_entry_t entry, struct page *page);
 175
 176/* linux/mm/page_alloc.c */
 177
 178/* linux/mm/swap_state.c */
 179#define SWAP_CACHE_INFO
 180#ifdef SWAP_CACHE_INFO
 181extern void show_swap_cache_info(void);
 182#endif
 183extern int add_to_swap_cache(struct page *, swp_entry_t);
 184extern int add_to_swap(struct page *);
 185extern void __delete_from_swap_cache(struct page *page);
 186extern void delete_from_swap_cache(struct page *page);
 187extern int move_to_swap_cache(struct page *page, swp_entry_t entry);
 188extern int move_from_swap_cache(struct page *page, unsigned long index,
 189                struct address_space *mapping);
 190extern void free_page_and_swap_cache(struct page *page);
 191extern struct page * lookup_swap_cache(swp_entry_t);
 192extern struct page * read_swap_cache_async(swp_entry_t);
 193
 194/* linux/mm/oom_kill.c */
 195extern void out_of_memory(void);
 196
 197/* linux/mm/swapfile.c */
 198extern int total_swap_pages;
 199extern unsigned int nr_swapfiles;
 200extern struct swap_info_struct swap_info[];
 201extern void si_swapinfo(struct sysinfo *);
 202extern swp_entry_t get_swap_page(void);
 203extern int swap_duplicate(swp_entry_t);
 204extern int valid_swaphandles(swp_entry_t, unsigned long *);
 205extern void swap_free(swp_entry_t);
 206extern void free_swap_and_cache(swp_entry_t);
 207sector_t map_swap_page(struct swap_info_struct *p, pgoff_t offset);
 208struct swap_info_struct *get_swap_info_struct(unsigned type);
 209
 210struct swap_list_t {
 211        int head;       /* head of priority-ordered swapfile list */
 212        int next;       /* swapfile to be used next */
 213};
 214extern struct swap_list_t swap_list;
 215asmlinkage long sys_swapoff(const char *);
 216asmlinkage long sys_swapon(const char *, int);
 217
 218extern spinlock_t pagemap_lru_lock;
 219
 220extern void FASTCALL(mark_page_accessed(struct page *));
 221
 222/*
 223 * List add/del helper macros. These must be called
 224 * with the pagemap_lru_lock held!
 225 */
 226#define DEBUG_LRU_PAGE(page)                    \
 227do {                                            \
 228        if (!PageLRU(page))                     \
 229                BUG();                          \
 230        if (PageActive(page))                   \
 231                BUG();                          \
 232} while (0)
 233
 234#define add_page_to_active_list(page)           \
 235do {                                            \
 236        DEBUG_LRU_PAGE(page);                   \
 237        SetPageActive(page);                    \
 238        list_add(&(page)->lru, &active_list);   \
 239        inc_page_state(nr_active);              \
 240} while (0)
 241
 242#define add_page_to_inactive_list(page)         \
 243do {                                            \
 244        DEBUG_LRU_PAGE(page);                   \
 245        list_add(&(page)->lru, &inactive_list); \
 246        inc_page_state(nr_inactive);            \
 247} while (0)
 248
 249#define del_page_from_active_list(page)         \
 250do {                                            \
 251        list_del(&(page)->lru);                 \
 252        ClearPageActive(page);                  \
 253        dec_page_state(nr_active);              \
 254} while (0)
 255
 256#define del_page_from_inactive_list(page)       \
 257do {                                            \
 258        list_del(&(page)->lru);                 \
 259        dec_page_state(nr_inactive);            \
 260} while (0)
 261
 262extern spinlock_t swaplock;
 263
 264#define swap_list_lock()        spin_lock(&swaplock)
 265#define swap_list_unlock()      spin_unlock(&swaplock)
 266#define swap_device_lock(p)     spin_lock(&p->sdev_lock)
 267#define swap_device_unlock(p)   spin_unlock(&p->sdev_lock)
 268
 269extern void shmem_unuse(swp_entry_t entry, struct page *page);
 270
 271#endif /* __KERNEL__*/
 272
 273#endif /* _LINUX_SWAP_H */
 274
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.