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. expand_stack
  3. find_vma
  4. find_vma_intersection
  5. in_swap_cache
  6. find_in_swap_cache
  7. delete_from_swap_cache

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

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