linux-old/include/linux/mm.h
<<
>>
Prefs
   1#ifndef _LINUX_MM_H
   2#define _LINUX_MM_H
   3
   4#include <linux/sched.h>
   5#include <linux/errno.h>
   6
   7#ifdef __KERNEL__
   8
   9#include <linux/config.h>
  10#include <linux/string.h>
  11#include <linux/list.h>
  12#include <linux/mmzone.h>
  13#include <linux/swap.h>
  14#include <linux/rbtree.h>
  15
  16extern unsigned long max_mapnr;
  17extern unsigned long num_physpages;
  18extern void * high_memory;
  19extern int page_cluster;
  20/* The inactive_clean lists are per zone. */
  21extern struct list_head active_list;
  22extern struct list_head inactive_list;
  23
  24#include <asm/page.h>
  25#include <asm/pgtable.h>
  26#include <asm/atomic.h>
  27
  28/*
  29 * Linux kernel virtual memory manager primitives.
  30 * The idea being to have a "virtual" mm in the same way
  31 * we have a virtual fs - giving a cleaner interface to the
  32 * mm details, and allowing different kinds of memory mappings
  33 * (from shared memory to executable loading to arbitrary
  34 * mmap() functions).
  35 */
  36
  37/*
  38 * This struct defines a memory VMM memory area. There is one of these
  39 * per VM-area/task.  A VM area is any part of the process virtual memory
  40 * space that has a special rule for the page-fault handlers (ie a shared
  41 * library, the executable area etc).
  42 */
  43struct vm_area_struct {
  44        struct mm_struct * vm_mm;       /* The address space we belong to. */
  45        unsigned long vm_start;         /* Our start address within vm_mm. */
  46        unsigned long vm_end;           /* The first byte after our end address
  47                                           within vm_mm. */
  48
  49        /* linked list of VM areas per task, sorted by address */
  50        struct vm_area_struct *vm_next;
  51
  52        pgprot_t vm_page_prot;          /* Access permissions of this VMA. */
  53        unsigned long vm_flags;         /* Flags, listed below. */
  54
  55        rb_node_t vm_rb;
  56
  57        /*
  58         * For areas with an address space and backing store,
  59         * one of the address_space->i_mmap{,shared} lists,
  60         * for shm areas, the list of attaches, otherwise unused.
  61         */
  62        struct vm_area_struct *vm_next_share;
  63        struct vm_area_struct **vm_pprev_share;
  64
  65        /* Function pointers to deal with this struct. */
  66        struct vm_operations_struct * vm_ops;
  67
  68        /* Information about our backing store: */
  69        unsigned long vm_pgoff;         /* Offset (within vm_file) in PAGE_SIZE
  70                                           units, *not* PAGE_CACHE_SIZE */
  71        struct file * vm_file;          /* File we map to (can be NULL). */
  72        unsigned long vm_raend;         /* XXX: put full readahead info here. */
  73        void * vm_private_data;         /* was vm_pte (shared mem) */
  74};
  75
  76/*
  77 * vm_flags..
  78 */
  79#define VM_READ         0x00000001      /* currently active flags */
  80#define VM_WRITE        0x00000002
  81#define VM_EXEC         0x00000004
  82#define VM_SHARED       0x00000008
  83
  84#define VM_MAYREAD      0x00000010      /* limits for mprotect() etc */
  85#define VM_MAYWRITE     0x00000020
  86#define VM_MAYEXEC      0x00000040
  87#define VM_MAYSHARE     0x00000080
  88
  89#define VM_GROWSDOWN    0x00000100      /* general info on the segment */
  90#define VM_GROWSUP      0x00000200
  91#define VM_SHM          0x00000400      /* shared memory area, don't swap out */
  92#define VM_DENYWRITE    0x00000800      /* ETXTBSY on write attempts.. */
  93
  94#define VM_EXECUTABLE   0x00001000
  95#define VM_LOCKED       0x00002000
  96#define VM_IO           0x00004000      /* Memory mapped I/O or similar */
  97
  98                                        /* Used by sys_madvise() */
  99#define VM_SEQ_READ     0x00008000      /* App will access data sequentially */
 100#define VM_RAND_READ    0x00010000      /* App will not benefit from clustered reads */
 101
 102#define VM_DONTCOPY     0x00020000      /* Do not copy this vma on fork */
 103#define VM_DONTEXPAND   0x00040000      /* Cannot expand with mremap() */
 104#define VM_RESERVED     0x00080000      /* Don't unmap it from swap_out */
 105
 106#define VM_STACK_FLAGS  0x00000177
 107
 108#define VM_READHINTMASK                 (VM_SEQ_READ | VM_RAND_READ)
 109#define VM_ClearReadHint(v)             (v)->vm_flags &= ~VM_READHINTMASK
 110#define VM_NormalReadHint(v)            (!((v)->vm_flags & VM_READHINTMASK))
 111#define VM_SequentialReadHint(v)        ((v)->vm_flags & VM_SEQ_READ)
 112#define VM_RandomReadHint(v)            ((v)->vm_flags & VM_RAND_READ)
 113
 114/* read ahead limits */
 115extern int vm_min_readahead;
 116extern int vm_max_readahead;
 117
 118/*
 119 * mapping from the currently active vm_flags protection bits (the
 120 * low four bits) to a page protection mask..
 121 */
 122extern pgprot_t protection_map[16];
 123
 124
 125/*
 126 * These are the virtual MM functions - opening of an area, closing and
 127 * unmapping it (needed to keep files on disk up-to-date etc), pointer
 128 * to the functions called when a no-page or a wp-page exception occurs. 
 129 */
 130struct vm_operations_struct {
 131        void (*open)(struct vm_area_struct * area);
 132        void (*close)(struct vm_area_struct * area);
 133        struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int unused);
 134};
 135
 136/*
 137 * Each physical page in the system has a struct page associated with
 138 * it to keep track of whatever it is we are using the page for at the
 139 * moment. Note that we have no way to track which tasks are using
 140 * a page.
 141 *
 142 * Try to keep the most commonly accessed fields in single cache lines
 143 * here (16 bytes or greater).  This ordering should be particularly
 144 * beneficial on 32-bit processors.
 145 *
 146 * The first line is data used in page cache lookup, the second line
 147 * is used for linear searches (eg. clock algorithm scans). 
 148 *
 149 * TODO: make this structure smaller, it could be as small as 32 bytes.
 150 */
 151typedef struct page {
 152        struct list_head list;          /* ->mapping has some page lists. */
 153        struct address_space *mapping;  /* The inode (or ...) we belong to. */
 154        unsigned long index;            /* Our offset within mapping. */
 155        struct page *next_hash;         /* Next page sharing our hash bucket in
 156                                           the pagecache hash table. */
 157        atomic_t count;                 /* Usage count, see below. */
 158        unsigned long flags;            /* atomic flags, some possibly
 159                                           updated asynchronously */
 160        struct list_head lru;           /* Pageout list, eg. active_list;
 161                                           protected by pagemap_lru_lock !! */
 162        wait_queue_head_t wait;         /* Page locked?  Stand in line... */
 163        struct page **pprev_hash;       /* Complement to *next_hash. */
 164        struct buffer_head * buffers;   /* Buffer maps us to a disk block. */
 165        void *virtual;                  /* Kernel virtual address (NULL if
 166                                           not kmapped, ie. highmem) */
 167        struct zone_struct *zone;       /* Memory zone we are in. */
 168} mem_map_t;
 169
 170/*
 171 * Methods to modify the page usage count.
 172 *
 173 * What counts for a page usage:
 174 * - cache mapping   (page->mapping)
 175 * - disk mapping    (page->buffers)
 176 * - page mapped in a task's page tables, each mapping
 177 *   is counted separately
 178 *
 179 * Also, many kernel routines increase the page count before a critical
 180 * routine so they can be sure the page doesn't go away from under them.
 181 */
 182#define get_page(p)             atomic_inc(&(p)->count)
 183#define put_page(p)             __free_page(p)
 184#define put_page_testzero(p)    atomic_dec_and_test(&(p)->count)
 185#define page_count(p)           atomic_read(&(p)->count)
 186#define set_page_count(p,v)     atomic_set(&(p)->count, v)
 187
 188/*
 189 * Various page->flags bits:
 190 *
 191 * PG_reserved is set for special pages, which can never be swapped
 192 * out. Some of them might not even exist (eg empty_bad_page)...
 193 *
 194 * Multiple processes may "see" the same page. E.g. for untouched
 195 * mappings of /dev/null, all processes see the same page full of
 196 * zeroes, and text pages of executables and shared libraries have
 197 * only one copy in memory, at most, normally.
 198 *
 199 * For the non-reserved pages, page->count denotes a reference count.
 200 *   page->count == 0 means the page is free.
 201 *   page->count == 1 means the page is used for exactly one purpose
 202 *   (e.g. a private data page of one process).
 203 *
 204 * A page may be used for kmalloc() or anyone else who does a
 205 * __get_free_page(). In this case the page->count is at least 1, and
 206 * all other fields are unused but should be 0 or NULL. The
 207 * management of this page is the responsibility of the one who uses
 208 * it.
 209 *
 210 * The other pages (we may call them "process pages") are completely
 211 * managed by the Linux memory manager: I/O, buffers, swapping etc.
 212 * The following discussion applies only to them.
 213 *
 214 * A page may belong to an inode's memory mapping. In this case,
 215 * page->mapping is the pointer to the inode, and page->index is the
 216 * file offset of the page, in units of PAGE_CACHE_SIZE.
 217 *
 218 * A page may have buffers allocated to it. In this case,
 219 * page->buffers is a circular list of these buffer heads. Else,
 220 * page->buffers == NULL.
 221 *
 222 * For pages belonging to inodes, the page->count is the number of
 223 * attaches, plus 1 if buffers are allocated to the page, plus one
 224 * for the page cache itself.
 225 *
 226 * All pages belonging to an inode are in these doubly linked lists:
 227 * mapping->clean_pages, mapping->dirty_pages and mapping->locked_pages;
 228 * using the page->list list_head. These fields are also used for
 229 * freelist managemet (when page->count==0).
 230 *
 231 * There is also a hash table mapping (mapping,index) to the page
 232 * in memory if present. The lists for this hash table use the fields
 233 * page->next_hash and page->pprev_hash.
 234 *
 235 * All process pages can do I/O:
 236 * - inode pages may need to be read from disk,
 237 * - inode pages which have been modified and are MAP_SHARED may need
 238 *   to be written to disk,
 239 * - private pages which have been modified may need to be swapped out
 240 *   to swap space and (later) to be read back into memory.
 241 * During disk I/O, PG_locked is used. This bit is set before I/O
 242 * and reset when I/O completes. page->wait is a wait queue of all
 243 * tasks waiting for the I/O on this page to complete.
 244 * PG_uptodate tells whether the page's contents is valid.
 245 * When a read completes, the page becomes uptodate, unless a disk I/O
 246 * error happened.
 247 *
 248 * For choosing which pages to swap out, inode pages carry a
 249 * PG_referenced bit, which is set any time the system accesses
 250 * that page through the (mapping,index) hash table. This referenced
 251 * bit, together with the referenced bit in the page tables, is used
 252 * to manipulate page->age and move the page across the active,
 253 * inactive_dirty and inactive_clean lists.
 254 *
 255 * Note that the referenced bit, the page->lru list_head and the
 256 * active, inactive_dirty and inactive_clean lists are protected by
 257 * the pagemap_lru_lock, and *NOT* by the usual PG_locked bit!
 258 *
 259 * PG_skip is used on sparc/sparc64 architectures to "skip" certain
 260 * parts of the address space.
 261 *
 262 * PG_error is set to indicate that an I/O error occurred on this page.
 263 *
 264 * PG_arch_1 is an architecture specific page state bit.  The generic
 265 * code guarantees that this bit is cleared for a page when it first
 266 * is entered into the page cache.
 267 *
 268 * PG_highmem pages are not permanently mapped into the kernel virtual
 269 * address space, they need to be kmapped separately for doing IO on
 270 * the pages. The struct page (these bits with information) are always
 271 * mapped into kernel address space...
 272 */
 273#define PG_locked                0      /* Page is locked. Don't touch. */
 274#define PG_error                 1
 275#define PG_referenced            2
 276#define PG_uptodate              3
 277#define PG_dirty                 4
 278#define PG_unused                5
 279#define PG_lru                   6
 280#define PG_active                7
 281#define PG_slab                  8
 282#define PG_skip                 10
 283#define PG_highmem              11
 284#define PG_checked              12      /* kill me in 2.5.<early>. */
 285#define PG_arch_1               13
 286#define PG_reserved             14
 287#define PG_launder              15      /* written out by VM pressure.. */
 288
 289/* Make it prettier to test the above... */
 290#define UnlockPage(page)        unlock_page(page)
 291#define Page_Uptodate(page)     test_bit(PG_uptodate, &(page)->flags)
 292#define SetPageUptodate(page)   set_bit(PG_uptodate, &(page)->flags)
 293#define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags)
 294#define PageDirty(page)         test_bit(PG_dirty, &(page)->flags)
 295#define SetPageDirty(page)      set_bit(PG_dirty, &(page)->flags)
 296#define ClearPageDirty(page)    clear_bit(PG_dirty, &(page)->flags)
 297#define PageLocked(page)        test_bit(PG_locked, &(page)->flags)
 298#define LockPage(page)          set_bit(PG_locked, &(page)->flags)
 299#define TryLockPage(page)       test_and_set_bit(PG_locked, &(page)->flags)
 300#define PageChecked(page)       test_bit(PG_checked, &(page)->flags)
 301#define SetPageChecked(page)    set_bit(PG_checked, &(page)->flags)
 302#define PageLaunder(page)       test_bit(PG_launder, &(page)->flags)
 303#define SetPageLaunder(page)    set_bit(PG_launder, &(page)->flags)
 304
 305extern void FASTCALL(set_page_dirty(struct page *));
 306
 307/*
 308 * The first mb is necessary to safely close the critical section opened by the
 309 * TryLockPage(), the second mb is necessary to enforce ordering between
 310 * the clear_bit and the read of the waitqueue (to avoid SMP races with a
 311 * parallel wait_on_page).
 312 */
 313#define PageError(page)         test_bit(PG_error, &(page)->flags)
 314#define SetPageError(page)      set_bit(PG_error, &(page)->flags)
 315#define ClearPageError(page)    clear_bit(PG_error, &(page)->flags)
 316#define PageReferenced(page)    test_bit(PG_referenced, &(page)->flags)
 317#define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags)
 318#define ClearPageReferenced(page)       clear_bit(PG_referenced, &(page)->flags)
 319#define PageTestandClearReferenced(page)        test_and_clear_bit(PG_referenced, &(page)->flags)
 320#define PageSlab(page)          test_bit(PG_slab, &(page)->flags)
 321#define PageSetSlab(page)       set_bit(PG_slab, &(page)->flags)
 322#define PageClearSlab(page)     clear_bit(PG_slab, &(page)->flags)
 323#define PageReserved(page)      test_bit(PG_reserved, &(page)->flags)
 324
 325#define PageActive(page)        test_bit(PG_active, &(page)->flags)
 326#define SetPageActive(page)     set_bit(PG_active, &(page)->flags)
 327#define ClearPageActive(page)   clear_bit(PG_active, &(page)->flags)
 328
 329#define PageLRU(page)           test_bit(PG_lru, &(page)->flags)
 330#define TestSetPageLRU(page)    test_and_set_bit(PG_lru, &(page)->flags)
 331#define TestClearPageLRU(page)  test_and_clear_bit(PG_lru, &(page)->flags)
 332
 333#ifdef CONFIG_HIGHMEM
 334#define PageHighMem(page)               test_bit(PG_highmem, &(page)->flags)
 335#else
 336#define PageHighMem(page)               0 /* needed to optimize away at compile time */
 337#endif
 338
 339#define SetPageReserved(page)           set_bit(PG_reserved, &(page)->flags)
 340#define ClearPageReserved(page)         clear_bit(PG_reserved, &(page)->flags)
 341
 342/*
 343 * Error return values for the *_nopage functions
 344 */
 345#define NOPAGE_SIGBUS   (NULL)
 346#define NOPAGE_OOM      ((struct page *) (-1))
 347
 348/* The array of struct pages */
 349extern mem_map_t * mem_map;
 350
 351/*
 352 * There is only one page-allocator function, and two main namespaces to
 353 * it. The alloc_page*() variants return 'struct page *' and as such
 354 * can allocate highmem pages, the *get*page*() variants return
 355 * virtual kernel addresses to the allocated page(s).
 356 */
 357extern struct page * FASTCALL(_alloc_pages(unsigned int gfp_mask, unsigned int order));
 358extern struct page * FASTCALL(__alloc_pages(unsigned int gfp_mask, unsigned int order, zonelist_t *zonelist));
 359extern struct page * alloc_pages_node(int nid, unsigned int gfp_mask, unsigned int order);
 360
 361static inline struct page * alloc_pages(unsigned int gfp_mask, unsigned int order)
 362{
 363        /*
 364         * Gets optimized away by the compiler.
 365         */
 366        if (order >= MAX_ORDER)
 367                return NULL;
 368        return _alloc_pages(gfp_mask, order);
 369}
 370
 371#define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0)
 372
 373extern unsigned long FASTCALL(__get_free_pages(unsigned int gfp_mask, unsigned int order));
 374extern unsigned long FASTCALL(get_zeroed_page(unsigned int gfp_mask));
 375
 376#define __get_free_page(gfp_mask) \
 377                __get_free_pages((gfp_mask),0)
 378
 379#define __get_dma_pages(gfp_mask, order) \
 380                __get_free_pages((gfp_mask) | GFP_DMA,(order))
 381
 382/*
 383 * The old interface name will be removed in 2.5:
 384 */
 385#define get_free_page get_zeroed_page
 386
 387/*
 388 * There is only one 'core' page-freeing function.
 389 */
 390extern void FASTCALL(__free_pages(struct page *page, unsigned int order));
 391extern void FASTCALL(free_pages(unsigned long addr, unsigned int order));
 392
 393#define __free_page(page) __free_pages((page), 0)
 394#define free_page(addr) free_pages((addr),0)
 395
 396extern void show_free_areas(void);
 397extern void show_free_areas_node(pg_data_t *pgdat);
 398
 399extern void clear_page_tables(struct mm_struct *, unsigned long, int);
 400
 401extern int fail_writepage(struct page *);
 402struct page * shmem_nopage(struct vm_area_struct * vma, unsigned long address, int unused);
 403struct file *shmem_file_setup(char * name, loff_t size);
 404extern void shmem_lock(struct file * file, int lock);
 405extern int shmem_zero_setup(struct vm_area_struct *);
 406
 407extern void zap_page_range(struct mm_struct *mm, unsigned long address, unsigned long size);
 408extern int copy_page_range(struct mm_struct *dst, struct mm_struct *src, struct vm_area_struct *vma);
 409extern int remap_page_range(unsigned long from, unsigned long to, unsigned long size, pgprot_t prot);
 410extern int zeromap_page_range(unsigned long from, unsigned long size, pgprot_t prot);
 411
 412extern int vmtruncate(struct inode * inode, loff_t offset);
 413extern pmd_t *FASTCALL(__pmd_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address));
 414extern pte_t *FASTCALL(pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address));
 415extern int handle_mm_fault(struct mm_struct *mm,struct vm_area_struct *vma, unsigned long address, int write_access);
 416extern int make_pages_present(unsigned long addr, unsigned long end);
 417extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
 418extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char *dst, int len);
 419extern int ptrace_writedata(struct task_struct *tsk, char * src, unsigned long dst, int len);
 420extern int ptrace_attach(struct task_struct *tsk);
 421extern int ptrace_detach(struct task_struct *, unsigned int);
 422extern void ptrace_disable(struct task_struct *);
 423extern int ptrace_check_attach(struct task_struct *task, int kill);
 424
 425int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, unsigned long start,
 426                int len, int write, int force, struct page **pages, struct vm_area_struct **vmas);
 427
 428/*
 429 * On a two-level page table, this ends up being trivial. Thus the
 430 * inlining and the symmetry break with pte_alloc() that does all
 431 * of this out-of-line.
 432 */
 433static inline pmd_t *pmd_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
 434{
 435        if (pgd_none(*pgd))
 436                return __pmd_alloc(mm, pgd, address);
 437        return pmd_offset(pgd, address);
 438}
 439
 440extern int pgt_cache_water[2];
 441extern int check_pgt_cache(void);
 442
 443extern void free_area_init(unsigned long * zones_size);
 444extern void free_area_init_node(int nid, pg_data_t *pgdat, struct page *pmap,
 445        unsigned long * zones_size, unsigned long zone_start_paddr, 
 446        unsigned long *zholes_size);
 447extern void mem_init(void);
 448extern void show_mem(void);
 449extern void si_meminfo(struct sysinfo * val);
 450extern void swapin_readahead(swp_entry_t);
 451
 452extern struct address_space swapper_space;
 453#define PageSwapCache(page) ((page)->mapping == &swapper_space)
 454
 455static inline int is_page_cache_freeable(struct page * page)
 456{
 457        return page_count(page) - !!page->buffers == 1;
 458}
 459
 460extern int can_share_swap_page(struct page *);
 461extern int remove_exclusive_swap_page(struct page *);
 462
 463extern void __free_pte(pte_t);
 464
 465/* mmap.c */
 466extern void lock_vma_mappings(struct vm_area_struct *);
 467extern void unlock_vma_mappings(struct vm_area_struct *);
 468extern void insert_vm_struct(struct mm_struct *, struct vm_area_struct *);
 469extern void __insert_vm_struct(struct mm_struct *, struct vm_area_struct *);
 470extern void build_mmap_rb(struct mm_struct *);
 471extern void exit_mmap(struct mm_struct *);
 472
 473extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
 474
 475extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
 476        unsigned long len, unsigned long prot,
 477        unsigned long flag, unsigned long pgoff);
 478
 479static inline unsigned long do_mmap(struct file *file, unsigned long addr,
 480        unsigned long len, unsigned long prot,
 481        unsigned long flag, unsigned long offset)
 482{
 483        unsigned long ret = -EINVAL;
 484        if ((offset + PAGE_ALIGN(len)) < offset)
 485                goto out;
 486        if (!(offset & ~PAGE_MASK))
 487                ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
 488out:
 489        return ret;
 490}
 491
 492extern int do_munmap(struct mm_struct *, unsigned long, size_t);
 493
 494extern unsigned long do_brk(unsigned long, unsigned long);
 495
 496static inline void __vma_unlink(struct mm_struct * mm, struct vm_area_struct * vma, struct vm_area_struct * prev)
 497{
 498        prev->vm_next = vma->vm_next;
 499        rb_erase(&vma->vm_rb, &mm->mm_rb);
 500        if (mm->mmap_cache == vma)
 501                mm->mmap_cache = prev;
 502}
 503
 504static inline int can_vma_merge(struct vm_area_struct * vma, unsigned long vm_flags)
 505{
 506        if (!vma->vm_file && vma->vm_flags == vm_flags)
 507                return 1;
 508        else
 509                return 0;
 510}
 511
 512struct zone_t;
 513/* filemap.c */
 514extern void remove_inode_page(struct page *);
 515extern unsigned long page_unuse(struct page *);
 516extern void truncate_inode_pages(struct address_space *, loff_t);
 517
 518/* generic vm_area_ops exported for stackable file systems */
 519extern int filemap_sync(struct vm_area_struct *, unsigned long, size_t, unsigned int);
 520extern struct page *filemap_nopage(struct vm_area_struct *, unsigned long, int);
 521
 522/*
 523 * GFP bitmasks..
 524 */
 525/* Zone modifiers in GFP_ZONEMASK (see linux/mmzone.h - low four bits) */
 526#define __GFP_DMA       0x01
 527#define __GFP_HIGHMEM   0x02
 528
 529/* Action modifiers - doesn't change the zoning */
 530#define __GFP_WAIT      0x10    /* Can wait and reschedule? */
 531#define __GFP_HIGH      0x20    /* Should access emergency pools? */
 532#define __GFP_IO        0x40    /* Can start low memory physical IO? */
 533#define __GFP_HIGHIO    0x80    /* Can start high mem physical IO? */
 534#define __GFP_FS        0x100   /* Can call down to low-level FS? */
 535
 536#define GFP_NOHIGHIO    (__GFP_HIGH | __GFP_WAIT | __GFP_IO)
 537#define GFP_NOIO        (__GFP_HIGH | __GFP_WAIT)
 538#define GFP_NOFS        (__GFP_HIGH | __GFP_WAIT | __GFP_IO | __GFP_HIGHIO)
 539#define GFP_ATOMIC      (__GFP_HIGH)
 540#define GFP_USER        (             __GFP_WAIT | __GFP_IO | __GFP_HIGHIO | __GFP_FS)
 541#define GFP_HIGHUSER    (             __GFP_WAIT | __GFP_IO | __GFP_HIGHIO | __GFP_FS | __GFP_HIGHMEM)
 542#define GFP_KERNEL      (__GFP_HIGH | __GFP_WAIT | __GFP_IO | __GFP_HIGHIO | __GFP_FS)
 543#define GFP_NFS         (__GFP_HIGH | __GFP_WAIT | __GFP_IO | __GFP_HIGHIO | __GFP_FS)
 544#define GFP_KSWAPD      (             __GFP_WAIT | __GFP_IO | __GFP_HIGHIO | __GFP_FS)
 545
 546/* Flag - indicates that the buffer will be suitable for DMA.  Ignored on some
 547   platforms, used as appropriate on others */
 548
 549#define GFP_DMA         __GFP_DMA
 550
 551static inline unsigned int pf_gfp_mask(unsigned int gfp_mask)
 552{
 553        /* avoid all memory balancing I/O methods if this task cannot block on I/O */
 554        if (current->flags & PF_NOIO)
 555                gfp_mask &= ~(__GFP_IO | __GFP_HIGHIO | __GFP_FS);
 556
 557        return gfp_mask;
 558}
 559        
 560/* vma is the first one with  address < vma->vm_end,
 561 * and even  address < vma->vm_start. Have to extend vma. */
 562static inline int expand_stack(struct vm_area_struct * vma, unsigned long address)
 563{
 564        unsigned long grow;
 565
 566        /*
 567         * vma->vm_start/vm_end cannot change under us because the caller is required
 568         * to hold the mmap_sem in write mode. We need to get the spinlock only
 569         * before relocating the vma range ourself.
 570         */
 571        address &= PAGE_MASK;
 572        spin_lock(&vma->vm_mm->page_table_lock);
 573        grow = (vma->vm_start - address) >> PAGE_SHIFT;
 574        if (vma->vm_end - address > current->rlim[RLIMIT_STACK].rlim_cur ||
 575            ((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) > current->rlim[RLIMIT_AS].rlim_cur) {
 576                spin_unlock(&vma->vm_mm->page_table_lock);
 577                return -ENOMEM;
 578        }
 579        vma->vm_start = address;
 580        vma->vm_pgoff -= grow;
 581        vma->vm_mm->total_vm += grow;
 582        if (vma->vm_flags & VM_LOCKED)
 583                vma->vm_mm->locked_vm += grow;
 584        spin_unlock(&vma->vm_mm->page_table_lock);
 585        return 0;
 586}
 587
 588/* Look up the first VMA which satisfies  addr < vm_end,  NULL if none. */
 589extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);
 590extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
 591                                             struct vm_area_struct **pprev);
 592
 593/* Look up the first VMA which intersects the interval start_addr..end_addr-1,
 594   NULL if none.  Assume start_addr < end_addr. */
 595static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
 596{
 597        struct vm_area_struct * vma = find_vma(mm,start_addr);
 598
 599        if (vma && end_addr <= vma->vm_start)
 600                vma = NULL;
 601        return vma;
 602}
 603
 604extern struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr);
 605
 606#endif /* __KERNEL__ */
 607
 608#endif
 609
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.