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

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