root/include/linux/mm.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. get_free_page
  2. in_swap_cache
  3. find_in_swap_cache
  4. delete_from_swap_cache

   1 #ifndef _LINUX_MM_H
   2 #define _LINUX_MM_H
   3 
   4 #include <asm/page.h>
   5 
   6 #include <linux/sched.h>
   7 #include <linux/errno.h>
   8 #include <linux/kernel.h>
   9 #include <linux/string.h>
  10 
  11 #define VERIFY_READ 0
  12 #define VERIFY_WRITE 1
  13 
  14 extern int verify_area(int, const void *, unsigned long);
  15 
  16 /*
  17  * Linux kernel virtual memory manager primitives.
  18  * The idea being to have a "virtual" mm in the same way
  19  * we have a virtual fs - giving a cleaner interface to the
  20  * mm details, and allowing different kinds of memory mappings
  21  * (from shared memory to executable loading to arbitrary
  22  * mmap() functions).
  23  */
  24 
  25 /*
  26  * This struct defines a memory VMM memory area. There is one of these
  27  * per VM-area/task.  A VM area is any part of the process virtual memory
  28  * space that has a special rule for the page-fault handlers (ie a shared
  29  * library, the executable area etc).
  30  */
  31 struct vm_area_struct {
  32         struct task_struct * vm_task;           /* VM area parameters */
  33         unsigned long vm_start;
  34         unsigned long vm_end;
  35         unsigned short vm_page_prot;
  36         unsigned short vm_flags;
  37 /* linked list of VM areas per task, sorted by address */
  38         struct vm_area_struct * vm_next;
  39 /* for areas with inode, the circular list inode->i_mmap */
  40 /* for shm areas, the linked list of attaches */
  41 /* otherwise unused */
  42         struct vm_area_struct * vm_next_share;
  43         struct vm_area_struct * vm_prev_share;
  44 /* more */
  45         struct vm_operations_struct * vm_ops;
  46         unsigned long vm_offset;
  47         struct inode * vm_inode;
  48         unsigned long vm_pte;                   /* shared mem */
  49 };
  50 
  51 /*
  52  * vm_flags..
  53  */
  54 #define VM_READ         0x0001  /* currently active flags */
  55 #define VM_WRITE        0x0002
  56 #define VM_EXEC         0x0004
  57 #define VM_SHARED       0x0008
  58 
  59 #define VM_MAYREAD      0x0010  /* limits for mprotect() etc */
  60 #define VM_MAYWRITE     0x0020
  61 #define VM_MAYEXEC      0x0040
  62 #define VM_MAYSHARE     0x0080
  63 
  64 #define VM_GROWSDOWN    0x0100  /* general info on the segment */
  65 #define VM_GROWSUP      0x0200
  66 #define VM_SHM          0x0400
  67 #define VM_DENYWRITE    0x0800  /* ETXTBSY on write attempts.. */
  68 
  69 #define VM_EXECUTABLE   0x1000
  70 
  71 #define VM_STACK_FLAGS  0x0177
  72 
  73 /*
  74  * These are the virtual MM functions - opening of an area, closing and
  75  * unmapping it (needed to keep files on disk up-to-date etc), pointer
  76  * to the functions called when a no-page or a wp-page exception occurs. 
  77  */
  78 struct vm_operations_struct {
  79         void (*open)(struct vm_area_struct * area);
  80         void (*close)(struct vm_area_struct * area);
  81         void (*unmap)(struct vm_area_struct *area, unsigned long, size_t);
  82         void (*protect)(struct vm_area_struct *area, unsigned long, size_t, unsigned int newprot);
  83         void (*sync)(struct vm_area_struct *area, unsigned long, size_t, unsigned int flags);
  84         void (*advise)(struct vm_area_struct *area, unsigned long, size_t, unsigned int advise);
  85         unsigned long (*nopage)(struct vm_area_struct * area, unsigned long address,
  86                 unsigned long page, int error_code);
  87         unsigned long (*wppage)(struct vm_area_struct * area, unsigned long address,
  88                 unsigned long page);
  89         void (*swapout)(struct vm_area_struct *,  unsigned long, unsigned long *);
  90         unsigned long (*swapin)(struct vm_area_struct *,  unsigned long);
  91 };
  92 
  93 extern unsigned long __bad_page(void);
  94 extern unsigned long __bad_pagetable(void);
  95 extern unsigned long __zero_page(void);
  96 
  97 #define BAD_PAGETABLE __bad_pagetable()
  98 #define BAD_PAGE __bad_page()
  99 #define ZERO_PAGE __zero_page()
 100 
 101 /* planning stage.. */
 102 #define P_DIRTY         0x0001
 103 #define P_LOCKED        0x0002
 104 #define P_UPTODATE      0x0004
 105 #define P_RESERVED      0x8000
 106 
 107 struct page_info {
 108         unsigned short flags;
 109         unsigned short count;
 110         struct inode * inode;
 111         unsigned long offset;
 112         struct page_info * next_same_inode;
 113         struct page_info * prev_same_inode;
 114         struct page_info * next_hash;
 115         struct page_info * prev_hash;
 116         struct wait_queue *wait;
 117 };
 118 /* end of planning stage */
 119 
 120 #ifdef __KERNEL__
 121 
 122 /*
 123  * Free area management
 124  */
 125 
 126 extern int nr_swap_pages;
 127 extern int nr_free_pages;
 128 extern int min_free_pages;
 129 
 130 #define NR_MEM_LISTS 6
 131 
 132 struct mem_list {
 133         struct mem_list * next;
 134         struct mem_list * prev;
 135 };
 136 
 137 extern struct mem_list free_area_list[NR_MEM_LISTS];
 138 extern unsigned char * free_area_map[NR_MEM_LISTS];
 139 
 140 /*
 141  * This is timing-critical - most of the time in getting a new page
 142  * goes to clearing the page. If you want a page without the clearing
 143  * overhead, just use __get_free_page() directly..
 144  */
 145 #define __get_free_page(priority) __get_free_pages((priority),0)
 146 extern unsigned long __get_free_pages(int priority, unsigned long gfporder);
 147 extern unsigned long __get_dma_pages(int priority, unsigned long gfporder);
 148 extern inline unsigned long get_free_page(int priority)
     /* [previous][next][first][last][top][bottom][index][help] */
 149 {
 150         unsigned long page;
 151 
 152         page = __get_free_page(priority);
 153         if (page)
 154                 memset((void *) page, 0, PAGE_SIZE);
 155         return page;
 156 }
 157 
 158 /* memory.c & swap.c*/
 159 
 160 #define free_page(addr) free_pages((addr),0)
 161 extern void free_pages(unsigned long addr, unsigned long order);
 162 
 163 extern void show_free_areas(void);
 164 extern unsigned long put_dirty_page(struct task_struct * tsk,unsigned long page,
 165         unsigned long address);
 166 
 167 extern void free_page_tables(struct task_struct * tsk);
 168 extern void clear_page_tables(struct task_struct * tsk);
 169 extern int copy_page_tables(struct task_struct * to);
 170 extern int clone_page_tables(struct task_struct * to);
 171 extern int unmap_page_range(unsigned long from, unsigned long size);
 172 extern int remap_page_range(unsigned long from, unsigned long to, unsigned long size, int mask);
 173 extern int zeromap_page_range(unsigned long from, unsigned long size, int mask);
 174 
 175 extern void do_wp_page(struct vm_area_struct * vma, unsigned long address,
 176         unsigned long error_code);
 177 extern void do_no_page(struct vm_area_struct * vma, unsigned long address,
 178         unsigned long error_code);
 179 
 180 extern unsigned long paging_init(unsigned long start_mem, unsigned long end_mem);
 181 extern void mem_init(unsigned long low_start_mem,
 182                      unsigned long start_mem, unsigned long end_mem);
 183 extern void show_mem(void);
 184 extern void oom(struct task_struct * task);
 185 extern void si_meminfo(struct sysinfo * val);
 186 
 187 /* vmalloc.c */
 188 
 189 extern void * vmalloc(unsigned long size);
 190 extern void vfree(void * addr);
 191 extern int vread(char *buf, char *addr, int count);
 192 
 193 /* swap.c */
 194 
 195 extern void swap_free(unsigned long page_nr);
 196 extern unsigned long swap_duplicate(unsigned long page_nr);
 197 extern unsigned long swap_in(unsigned long entry);
 198 extern void si_swapinfo(struct sysinfo * val);
 199 extern void rw_swap_page(int rw, unsigned long nr, char * buf);
 200 
 201 /* mmap.c */
 202 extern int do_mmap(struct file * file, unsigned long addr, unsigned long len,
 203         unsigned long prot, unsigned long flags, unsigned long off);
 204 extern void merge_segments(struct vm_area_struct *);
 205 extern void insert_vm_struct(struct task_struct *, struct vm_area_struct *);
 206 extern void remove_shared_vm_struct(struct vm_area_struct *);
 207 extern int do_munmap(unsigned long, size_t);
 208 extern unsigned long get_unmapped_area(unsigned long);
 209 
 210 #define read_swap_page(nr,buf) \
 211         rw_swap_page(READ,(nr),(buf))
 212 #define write_swap_page(nr,buf) \
 213         rw_swap_page(WRITE,(nr),(buf))
 214 
 215 extern unsigned long high_memory;
 216 
 217 #define MAP_NR(addr) ((addr) >> PAGE_SHIFT)
 218 #define MAP_PAGE_RESERVED (1<<15)
 219 
 220 extern unsigned short * mem_map;
 221 
 222 #define PAGE_PRESENT    0x001
 223 #define PAGE_RW         0x002
 224 #define PAGE_USER       0x004
 225 #define PAGE_PWT        0x008   /* 486 only - not used currently */
 226 #define PAGE_PCD        0x010   /* 486 only - not used currently */
 227 #define PAGE_ACCESSED   0x020
 228 #define PAGE_DIRTY      0x040
 229 #define PAGE_COW        0x200   /* implemented in software (one of the AVL bits) */
 230 
 231 #define PAGE_PRIVATE    (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED | PAGE_COW)
 232 #define PAGE_SHARED     (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)
 233 #define PAGE_COPY       (PAGE_PRESENT | PAGE_USER | PAGE_ACCESSED | PAGE_COW)
 234 #define PAGE_READONLY   (PAGE_PRESENT | PAGE_USER | PAGE_ACCESSED)
 235 #define PAGE_TABLE      (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)
 236 
 237 #define GFP_BUFFER      0x00
 238 #define GFP_ATOMIC      0x01
 239 #define GFP_USER        0x02
 240 #define GFP_KERNEL      0x03
 241 #define GFP_NOBUFFER    0x04
 242 #define GFP_NFS         0x05
 243 
 244 /* Flag - indicates that the buffer will be suitable for DMA.  Ignored on some
 245    platforms, used as appropriate on others */
 246 
 247 #define GFP_DMA         0x80
 248 
 249 /*
 250  * vm_ops not present page codes for shared memory.
 251  *
 252  * Will go away eventually..
 253  */
 254 #define SHM_SWP_TYPE 0x41
 255 extern void shm_no_page (ulong *);
 256 
 257 /*
 258  * swap cache stuff (in swap.c)
 259  */
 260 #define SWAP_CACHE_INFO
 261 
 262 extern unsigned long * swap_cache;
 263 
 264 #ifdef SWAP_CACHE_INFO
 265 extern unsigned long swap_cache_add_total;
 266 extern unsigned long swap_cache_add_success;
 267 extern unsigned long swap_cache_del_total;
 268 extern unsigned long swap_cache_del_success;
 269 extern unsigned long swap_cache_find_total;
 270 extern unsigned long swap_cache_find_success;
 271 #endif
 272 
 273 extern inline unsigned long in_swap_cache(unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 274 {
 275         return swap_cache[addr >> PAGE_SHIFT]; 
 276 }
 277 
 278 extern inline long find_in_swap_cache (unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 279 {
 280         unsigned long entry;
 281 
 282 #ifdef SWAP_CACHE_INFO
 283         swap_cache_find_total++;
 284 #endif
 285         __asm__ __volatile__("xchgl %0,%1"
 286                 :"=m" (swap_cache[addr >> PAGE_SHIFT]),
 287                  "=r" (entry)
 288                 :"0" (swap_cache[addr >> PAGE_SHIFT]),
 289                  "1" (0));
 290 #ifdef SWAP_CACHE_INFO
 291         if (entry)
 292                 swap_cache_find_success++;
 293 #endif  
 294         return entry;
 295 }
 296 
 297 extern inline int delete_from_swap_cache(unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 298 {
 299         unsigned long entry;
 300         
 301 #ifdef SWAP_CACHE_INFO
 302         swap_cache_del_total++;
 303 #endif  
 304         __asm__ __volatile__("xchgl %0,%1"
 305                 :"=m" (swap_cache[addr >> PAGE_SHIFT]),
 306                  "=r" (entry)
 307                 :"0" (swap_cache[addr >> PAGE_SHIFT]),
 308                  "1" (0));
 309         if (entry)  {
 310 #ifdef SWAP_CACHE_INFO
 311                 swap_cache_del_success++;
 312 #endif
 313                 swap_free(entry);
 314                 return 1;
 315         }
 316         return 0;
 317 }
 318 
 319 #endif /* __KERNEL__ */
 320 
 321 #endif

/* [previous][next][first][last][top][bottom][index][help] */