vserver 1.9.3
[linux-2.6.git] / include / linux / mm.h
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/gfp.h>
11 #include <linux/list.h>
12 #include <linux/mmzone.h>
13 #include <linux/rbtree.h>
14 #include <linux/prio_tree.h>
15 #include <linux/fs.h>
16
17 struct mempolicy;
18 struct anon_vma;
19
20 #ifndef CONFIG_DISCONTIGMEM          /* Don't use mapnrs, do it properly */
21 extern unsigned long max_mapnr;
22 #endif
23
24 extern unsigned long num_physpages;
25 extern void * high_memory;
26 extern unsigned long vmalloc_earlyreserve;
27 extern int page_cluster;
28
29 #ifdef CONFIG_SYSCTL
30 extern int sysctl_legacy_va_layout;
31 #else
32 #define sysctl_legacy_va_layout 0
33 #endif
34
35 #include <asm/page.h>
36 #include <asm/pgtable.h>
37 #include <asm/processor.h>
38 #include <asm/atomic.h>
39
40 #ifndef MM_VM_SIZE
41 #define MM_VM_SIZE(mm)  TASK_SIZE
42 #endif
43
44 /*
45  * Linux kernel virtual memory manager primitives.
46  * The idea being to have a "virtual" mm in the same way
47  * we have a virtual fs - giving a cleaner interface to the
48  * mm details, and allowing different kinds of memory mappings
49  * (from shared memory to executable loading to arbitrary
50  * mmap() functions).
51  */
52
53 /*
54  * This struct defines a memory VMM memory area. There is one of these
55  * per VM-area/task.  A VM area is any part of the process virtual memory
56  * space that has a special rule for the page-fault handlers (ie a shared
57  * library, the executable area etc).
58  */
59 struct vm_area_struct {
60         struct mm_struct * vm_mm;       /* The address space we belong to. */
61         unsigned long vm_start;         /* Our start address within vm_mm. */
62         unsigned long vm_end;           /* The first byte after our end address
63                                            within vm_mm. */
64
65         /* linked list of VM areas per task, sorted by address */
66         struct vm_area_struct *vm_next;
67
68         pgprot_t vm_page_prot;          /* Access permissions of this VMA. */
69         unsigned long vm_flags;         /* Flags, listed below. */
70
71         struct rb_node vm_rb;
72
73         /*
74          * For areas with an address space and backing store,
75          * linkage into the address_space->i_mmap prio tree, or
76          * linkage to the list of like vmas hanging off its node, or
77          * linkage of vma in the address_space->i_mmap_nonlinear list.
78          */
79         union {
80                 struct {
81                         struct list_head list;
82                         void *parent;   /* aligns with prio_tree_node parent */
83                         struct vm_area_struct *head;
84                 } vm_set;
85
86                 struct prio_tree_node prio_tree_node;
87         } shared;
88
89         /*
90          * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
91          * list, after a COW of one of the file pages.  A MAP_SHARED vma
92          * can only be in the i_mmap tree.  An anonymous MAP_PRIVATE, stack
93          * or brk vma (with NULL file) can only be in an anon_vma list.
94          */
95         struct list_head anon_vma_node; /* Serialized by anon_vma->lock */
96         struct anon_vma *anon_vma;      /* Serialized by page_table_lock */
97
98         /* Function pointers to deal with this struct. */
99         struct vm_operations_struct * vm_ops;
100
101         /* Information about our backing store: */
102         unsigned long vm_pgoff;         /* Offset (within vm_file) in PAGE_SIZE
103                                            units, *not* PAGE_CACHE_SIZE */
104         struct file * vm_file;          /* File we map to (can be NULL). */
105         void * vm_private_data;         /* was vm_pte (shared mem) */
106
107 #ifdef CONFIG_NUMA
108         struct mempolicy *vm_policy;    /* NUMA policy for the VMA */
109 #endif
110 };
111
112 /*
113  * vm_flags..
114  */
115 #define VM_READ         0x00000001      /* currently active flags */
116 #define VM_WRITE        0x00000002
117 #define VM_EXEC         0x00000004
118 #define VM_SHARED       0x00000008
119
120 #define VM_MAYREAD      0x00000010      /* limits for mprotect() etc */
121 #define VM_MAYWRITE     0x00000020
122 #define VM_MAYEXEC      0x00000040
123 #define VM_MAYSHARE     0x00000080
124
125 #define VM_GROWSDOWN    0x00000100      /* general info on the segment */
126 #define VM_GROWSUP      0x00000200
127 #define VM_SHM          0x00000400      /* shared memory area, don't swap out */
128 #define VM_DENYWRITE    0x00000800      /* ETXTBSY on write attempts.. */
129
130 #define VM_EXECUTABLE   0x00001000
131 #define VM_LOCKED       0x00002000
132 #define VM_IO           0x00004000      /* Memory mapped I/O or similar */
133
134                                         /* Used by sys_madvise() */
135 #define VM_SEQ_READ     0x00008000      /* App will access data sequentially */
136 #define VM_RAND_READ    0x00010000      /* App will not benefit from clustered reads */
137
138 #define VM_DONTCOPY     0x00020000      /* Do not copy this vma on fork */
139 #define VM_DONTEXPAND   0x00040000      /* Cannot expand with mremap() */
140 #define VM_RESERVED     0x00080000      /* Don't unmap it from swap_out */
141 #define VM_ACCOUNT      0x00100000      /* Is a VM accounted object */
142 #define VM_HUGETLB      0x00400000      /* Huge TLB Page VM */
143 #define VM_NONLINEAR    0x00800000      /* Is non-linear (remap_file_pages) */
144
145 #ifndef VM_STACK_DEFAULT_FLAGS          /* arch can override this */
146 #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
147 #endif
148
149 #ifdef CONFIG_STACK_GROWSUP
150 #define VM_STACK_FLAGS  (VM_GROWSUP | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
151 #else
152 #define VM_STACK_FLAGS  (VM_GROWSDOWN | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
153 #endif
154
155 #define VM_READHINTMASK                 (VM_SEQ_READ | VM_RAND_READ)
156 #define VM_ClearReadHint(v)             (v)->vm_flags &= ~VM_READHINTMASK
157 #define VM_NormalReadHint(v)            (!((v)->vm_flags & VM_READHINTMASK))
158 #define VM_SequentialReadHint(v)        ((v)->vm_flags & VM_SEQ_READ)
159 #define VM_RandomReadHint(v)            ((v)->vm_flags & VM_RAND_READ)
160
161 /*
162  * mapping from the currently active vm_flags protection bits (the
163  * low four bits) to a page protection mask..
164  */
165 extern pgprot_t protection_map[16];
166
167
168 /*
169  * These are the virtual MM functions - opening of an area, closing and
170  * unmapping it (needed to keep files on disk up-to-date etc), pointer
171  * to the functions called when a no-page or a wp-page exception occurs. 
172  */
173 struct vm_operations_struct {
174         void (*open)(struct vm_area_struct * area);
175         void (*close)(struct vm_area_struct * area);
176         struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type);
177         int (*populate)(struct vm_area_struct * area, unsigned long address, unsigned long len, pgprot_t prot, unsigned long pgoff, int nonblock);
178 #ifdef CONFIG_NUMA
179         int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new);
180         struct mempolicy *(*get_policy)(struct vm_area_struct *vma,
181                                         unsigned long addr);
182 #endif
183 };
184
185 struct mmu_gather;
186 struct inode;
187
188 #ifdef ARCH_HAS_ATOMIC_UNSIGNED
189 typedef unsigned page_flags_t;
190 #else
191 typedef unsigned long page_flags_t;
192 #endif
193
194 /*
195  * Each physical page in the system has a struct page associated with
196  * it to keep track of whatever it is we are using the page for at the
197  * moment. Note that we have no way to track which tasks are using
198  * a page.
199  */
200 struct page {
201         page_flags_t flags;             /* Atomic flags, some possibly
202                                          * updated asynchronously */
203         atomic_t _count;                /* Usage count, see below. */
204         atomic_t _mapcount;             /* Count of ptes mapped in mms,
205                                          * to show when page is mapped
206                                          * & limit reverse map searches.
207                                          */
208         unsigned long private;          /* Mapping-private opaque data:
209                                          * usually used for buffer_heads
210                                          * if PagePrivate set; used for
211                                          * swp_entry_t if PageSwapCache
212                                          */
213         struct address_space *mapping;  /* If low bit clear, points to
214                                          * inode address_space, or NULL.
215                                          * If page mapped as anonymous
216                                          * memory, low bit is set, and
217                                          * it points to anon_vma object:
218                                          * see PAGE_MAPPING_ANON below.
219                                          */
220         pgoff_t index;                  /* Our offset within mapping. */
221         struct list_head lru;           /* Pageout list, eg. active_list
222                                          * protected by zone->lru_lock !
223                                          */
224         /*
225          * On machines where all RAM is mapped into kernel address space,
226          * we can simply calculate the virtual address. On machines with
227          * highmem some memory is mapped into kernel virtual memory
228          * dynamically, so we need a place to store that address.
229          * Note that this field could be 16 bits on x86 ... ;)
230          *
231          * Architectures with slow multiplication can define
232          * WANT_PAGE_VIRTUAL in asm/page.h
233          */
234 #if defined(WANT_PAGE_VIRTUAL)
235         void *virtual;                  /* Kernel virtual address (NULL if
236                                            not kmapped, ie. highmem) */
237 #endif /* WANT_PAGE_VIRTUAL */
238 };
239
240 /*
241  * FIXME: take this include out, include page-flags.h in
242  * files which need it (119 of them)
243  */
244 #include <linux/page-flags.h>
245
246 /*
247  * Methods to modify the page usage count.
248  *
249  * What counts for a page usage:
250  * - cache mapping   (page->mapping)
251  * - private data    (page->private)
252  * - page mapped in a task's page tables, each mapping
253  *   is counted separately
254  *
255  * Also, many kernel routines increase the page count before a critical
256  * routine so they can be sure the page doesn't go away from under them.
257  *
258  * Since 2.6.6 (approx), a free page has ->_count = -1.  This is so that we
259  * can use atomic_add_negative(-1, page->_count) to detect when the page
260  * becomes free and so that we can also use atomic_inc_and_test to atomically
261  * detect when we just tried to grab a ref on a page which some other CPU has
262  * already deemed to be freeable.
263  *
264  * NO code should make assumptions about this internal detail!  Use the provided
265  * macros which retain the old rules: page_count(page) == 0 is a free page.
266  */
267
268 /*
269  * Drop a ref, return true if the logical refcount fell to zero (the page has
270  * no users)
271  */
272 #define put_page_testzero(p)                            \
273         ({                                              \
274                 BUG_ON(page_count(p) == 0);             \
275                 atomic_add_negative(-1, &(p)->_count);  \
276         })
277
278 /*
279  * Grab a ref, return true if the page previously had a logical refcount of
280  * zero.  ie: returns true if we just grabbed an already-deemed-to-be-free page
281  */
282 #define get_page_testone(p)     atomic_inc_and_test(&(p)->_count)
283
284 #define set_page_count(p,v)     atomic_set(&(p)->_count, v - 1)
285 #define __put_page(p)           atomic_dec(&(p)->_count)
286
287 extern void FASTCALL(__page_cache_release(struct page *));
288
289 #ifdef CONFIG_HUGETLB_PAGE
290
291 static inline int page_count(struct page *p)
292 {
293         if (PageCompound(p))
294                 p = (struct page *)p->private;
295         return atomic_read(&(p)->_count) + 1;
296 }
297
298 static inline void get_page(struct page *page)
299 {
300         if (unlikely(PageCompound(page)))
301                 page = (struct page *)page->private;
302         atomic_inc(&page->_count);
303 }
304
305 void put_page(struct page *page);
306
307 #else           /* CONFIG_HUGETLB_PAGE */
308
309 #define page_count(p)           (atomic_read(&(p)->_count) + 1)
310
311 static inline void get_page(struct page *page)
312 {
313         atomic_inc(&page->_count);
314 }
315
316 static inline void put_page(struct page *page)
317 {
318         if (!PageReserved(page) && put_page_testzero(page))
319                 __page_cache_release(page);
320 }
321
322 #endif          /* CONFIG_HUGETLB_PAGE */
323
324 /*
325  * Multiple processes may "see" the same page. E.g. for untouched
326  * mappings of /dev/null, all processes see the same page full of
327  * zeroes, and text pages of executables and shared libraries have
328  * only one copy in memory, at most, normally.
329  *
330  * For the non-reserved pages, page_count(page) denotes a reference count.
331  *   page_count() == 0 means the page is free.
332  *   page_count() == 1 means the page is used for exactly one purpose
333  *   (e.g. a private data page of one process).
334  *
335  * A page may be used for kmalloc() or anyone else who does a
336  * __get_free_page(). In this case the page_count() is at least 1, and
337  * all other fields are unused but should be 0 or NULL. The
338  * management of this page is the responsibility of the one who uses
339  * it.
340  *
341  * The other pages (we may call them "process pages") are completely
342  * managed by the Linux memory manager: I/O, buffers, swapping etc.
343  * The following discussion applies only to them.
344  *
345  * A page may belong to an inode's memory mapping. In this case,
346  * page->mapping is the pointer to the inode, and page->index is the
347  * file offset of the page, in units of PAGE_CACHE_SIZE.
348  *
349  * A page contains an opaque `private' member, which belongs to the
350  * page's address_space.  Usually, this is the address of a circular
351  * list of the page's disk buffers.
352  *
353  * For pages belonging to inodes, the page_count() is the number of
354  * attaches, plus 1 if `private' contains something, plus one for
355  * the page cache itself.
356  *
357  * All pages belonging to an inode are in these doubly linked lists:
358  * mapping->clean_pages, mapping->dirty_pages and mapping->locked_pages;
359  * using the page->list list_head. These fields are also used for
360  * freelist managemet (when page_count()==0).
361  *
362  * There is also a per-mapping radix tree mapping index to the page
363  * in memory if present. The tree is rooted at mapping->root.  
364  *
365  * All process pages can do I/O:
366  * - inode pages may need to be read from disk,
367  * - inode pages which have been modified and are MAP_SHARED may need
368  *   to be written to disk,
369  * - private pages which have been modified may need to be swapped out
370  *   to swap space and (later) to be read back into memory.
371  */
372
373 /*
374  * The zone field is never updated after free_area_init_core()
375  * sets it, so none of the operations on it need to be atomic.
376  * We'll have up to (MAX_NUMNODES * MAX_NR_ZONES) zones total,
377  * so we use (MAX_NODES_SHIFT + MAX_ZONES_SHIFT) here to get enough bits.
378  */
379 #define NODEZONE_SHIFT (sizeof(page_flags_t)*8 - MAX_NODES_SHIFT - MAX_ZONES_SHIFT)
380 #define NODEZONE(node, zone)    ((node << ZONES_SHIFT) | zone)
381
382 static inline unsigned long page_zonenum(struct page *page)
383 {
384         return (page->flags >> NODEZONE_SHIFT) & (~(~0UL << ZONES_SHIFT));
385 }
386 static inline unsigned long page_to_nid(struct page *page)
387 {
388         return (page->flags >> (NODEZONE_SHIFT + ZONES_SHIFT));
389 }
390
391 struct zone;
392 extern struct zone *zone_table[];
393
394 static inline struct zone *page_zone(struct page *page)
395 {
396         return zone_table[page->flags >> NODEZONE_SHIFT];
397 }
398
399 static inline void set_page_zone(struct page *page, unsigned long nodezone_num)
400 {
401         page->flags &= ~(~0UL << NODEZONE_SHIFT);
402         page->flags |= nodezone_num << NODEZONE_SHIFT;
403 }
404
405 #ifndef CONFIG_DISCONTIGMEM
406 /* The array of struct pages - for discontigmem use pgdat->lmem_map */
407 extern struct page *mem_map;
408 #endif
409
410 static inline void *lowmem_page_address(struct page *page)
411 {
412         return __va(page_to_pfn(page) << PAGE_SHIFT);
413 }
414
415 #if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL)
416 #define HASHED_PAGE_VIRTUAL
417 #endif
418
419 #if defined(WANT_PAGE_VIRTUAL)
420 #define page_address(page) ((page)->virtual)
421 #define set_page_address(page, address)                 \
422         do {                                            \
423                 (page)->virtual = (address);            \
424         } while(0)
425 #define page_address_init()  do { } while(0)
426 #endif
427
428 #if defined(HASHED_PAGE_VIRTUAL)
429 void *page_address(struct page *page);
430 void set_page_address(struct page *page, void *virtual);
431 void page_address_init(void);
432 #endif
433
434 #if !defined(HASHED_PAGE_VIRTUAL) && !defined(WANT_PAGE_VIRTUAL)
435 #define page_address(page) lowmem_page_address(page)
436 #define set_page_address(page, address)  do { } while(0)
437 #define page_address_init()  do { } while(0)
438 #endif
439
440 /*
441  * On an anonymous page mapped into a user virtual memory area,
442  * page->mapping points to its anon_vma, not to a struct address_space;
443  * with the PAGE_MAPPING_ANON bit set to distinguish it.
444  *
445  * Please note that, confusingly, "page_mapping" refers to the inode
446  * address_space which maps the page from disk; whereas "page_mapped"
447  * refers to user virtual address space into which the page is mapped.
448  */
449 #define PAGE_MAPPING_ANON       1
450
451 extern struct address_space swapper_space;
452 static inline struct address_space *page_mapping(struct page *page)
453 {
454         struct address_space *mapping = page->mapping;
455
456         if (unlikely(PageSwapCache(page)))
457                 mapping = &swapper_space;
458         else if (unlikely((unsigned long)mapping & PAGE_MAPPING_ANON))
459                 mapping = NULL;
460         return mapping;
461 }
462
463 static inline int PageAnon(struct page *page)
464 {
465         return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0;
466 }
467
468 /*
469  * Return the pagecache index of the passed page.  Regular pagecache pages
470  * use ->index whereas swapcache pages use ->private
471  */
472 static inline pgoff_t page_index(struct page *page)
473 {
474         if (unlikely(PageSwapCache(page)))
475                 return page->private;
476         return page->index;
477 }
478
479 /*
480  * The atomic page->_mapcount, like _count, starts from -1:
481  * so that transitions both from it and to it can be tracked,
482  * using atomic_inc_and_test and atomic_add_negative(-1).
483  */
484 static inline void reset_page_mapcount(struct page *page)
485 {
486         atomic_set(&(page)->_mapcount, -1);
487 }
488
489 static inline int page_mapcount(struct page *page)
490 {
491         return atomic_read(&(page)->_mapcount) + 1;
492 }
493
494 /*
495  * Return true if this page is mapped into pagetables.
496  */
497 static inline int page_mapped(struct page *page)
498 {
499         return atomic_read(&(page)->_mapcount) >= 0;
500 }
501
502 /*
503  * Error return values for the *_nopage functions
504  */
505 #define NOPAGE_SIGBUS   (NULL)
506 #define NOPAGE_OOM      ((struct page *) (-1))
507
508 /*
509  * Different kinds of faults, as returned by handle_mm_fault().
510  * Used to decide whether a process gets delivered SIGBUS or
511  * just gets major/minor fault counters bumped up.
512  */
513 #define VM_FAULT_OOM    (-1)
514 #define VM_FAULT_SIGBUS 0
515 #define VM_FAULT_MINOR  1
516 #define VM_FAULT_MAJOR  2
517
518 #define offset_in_page(p)       ((unsigned long)(p) & ~PAGE_MASK)
519
520 extern void show_free_areas(void);
521
522 #ifdef CONFIG_SHMEM
523 struct page *shmem_nopage(struct vm_area_struct *vma,
524                         unsigned long address, int *type);
525 int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *new);
526 struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
527                                         unsigned long addr);
528 int shmem_lock(struct file *file, int lock, struct user_struct *user);
529 #else
530 #define shmem_nopage filemap_nopage
531 #define shmem_lock(a, b, c)     ({0;})  /* always in memory, no need to lock */
532 #define shmem_set_policy(a, b)  (0)
533 #define shmem_get_policy(a, b)  (NULL)
534 #endif
535 struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags);
536
537 int shmem_zero_setup(struct vm_area_struct *);
538
539 static inline int can_do_mlock(void)
540 {
541         if (capable(CAP_IPC_LOCK))
542                 return 1;
543         if (current->rlim[RLIMIT_MEMLOCK].rlim_cur != 0)
544                 return 1;
545         return 0;
546 }
547 extern int user_shm_lock(size_t, struct user_struct *);
548 extern void user_shm_unlock(size_t, struct user_struct *);
549
550 /*
551  * Parameter block passed down to zap_pte_range in exceptional cases.
552  */
553 struct zap_details {
554         struct vm_area_struct *nonlinear_vma;   /* Check page->index if set */
555         struct address_space *check_mapping;    /* Check page->mapping if set */
556         pgoff_t first_index;                    /* Lowest page->index to unmap */
557         pgoff_t last_index;                     /* Highest page->index to unmap */
558         int atomic;                             /* May not schedule() */
559 };
560
561 void zap_page_range(struct vm_area_struct *vma, unsigned long address,
562                 unsigned long size, struct zap_details *);
563 int unmap_vmas(struct mmu_gather **tlbp, struct mm_struct *mm,
564                 struct vm_area_struct *start_vma, unsigned long start_addr,
565                 unsigned long end_addr, unsigned long *nr_accounted,
566                 struct zap_details *);
567 void clear_page_tables(struct mmu_gather *tlb, unsigned long first, int nr);
568 int copy_page_range(struct mm_struct *dst, struct mm_struct *src,
569                         struct vm_area_struct *vma);
570 int zeromap_page_range(struct vm_area_struct *vma, unsigned long from,
571                         unsigned long size, pgprot_t prot);
572 void unmap_mapping_range(struct address_space *mapping,
573                 loff_t const holebegin, loff_t const holelen, int even_cows);
574
575 static inline void unmap_shared_mapping_range(struct address_space *mapping,
576                 loff_t const holebegin, loff_t const holelen)
577 {
578         unmap_mapping_range(mapping, holebegin, holelen, 0);
579 }
580
581 extern int vmtruncate(struct inode * inode, loff_t offset);
582 extern pmd_t *FASTCALL(__pmd_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address));
583 extern pte_t *FASTCALL(pte_alloc_kernel(struct mm_struct *mm, pmd_t *pmd, unsigned long address));
584 extern pte_t *FASTCALL(pte_alloc_map(struct mm_struct *mm, pmd_t *pmd, unsigned long address));
585 extern int install_page(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, struct page *page, pgprot_t prot);
586 extern int install_file_pte(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, unsigned long pgoff, pgprot_t prot);
587 extern int handle_mm_fault(struct mm_struct *mm,struct vm_area_struct *vma, unsigned long address, int write_access);
588 extern int make_pages_present(unsigned long addr, unsigned long end);
589 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
590 void install_arg_page(struct vm_area_struct *, struct page *, unsigned long);
591
592 int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, unsigned long start,
593                 int len, int write, int force, struct page **pages, struct vm_area_struct **vmas);
594
595 int __set_page_dirty_buffers(struct page *page);
596 int __set_page_dirty_nobuffers(struct page *page);
597 int redirty_page_for_writepage(struct writeback_control *wbc,
598                                 struct page *page);
599 int FASTCALL(set_page_dirty(struct page *page));
600 int set_page_dirty_lock(struct page *page);
601 int clear_page_dirty_for_io(struct page *page);
602
603 /*
604  * Prototype to add a shrinker callback for ageable caches.
605  * 
606  * These functions are passed a count `nr_to_scan' and a gfpmask.  They should
607  * scan `nr_to_scan' objects, attempting to free them.
608  *
609  * The callback must the number of objects which remain in the cache.
610  *
611  * The callback will be passes nr_to_scan == 0 when the VM is querying the
612  * cache size, so a fastpath for that case is appropriate.
613  */
614 typedef int (*shrinker_t)(int nr_to_scan, unsigned int gfp_mask);
615
616 /*
617  * Add an aging callback.  The int is the number of 'seeks' it takes
618  * to recreate one of the objects that these functions age.
619  */
620
621 #define DEFAULT_SEEKS 2
622 struct shrinker;
623 extern struct shrinker *set_shrinker(int, shrinker_t);
624 extern void remove_shrinker(struct shrinker *shrinker);
625
626 /*
627  * On a two-level page table, this ends up being trivial. Thus the
628  * inlining and the symmetry break with pte_alloc_map() that does all
629  * of this out-of-line.
630  */
631 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
632 {
633         if (pgd_none(*pgd))
634                 return __pmd_alloc(mm, pgd, address);
635         return pmd_offset(pgd, address);
636 }
637
638 extern void free_area_init(unsigned long * zones_size);
639 extern void free_area_init_node(int nid, pg_data_t *pgdat,
640         unsigned long * zones_size, unsigned long zone_start_pfn, 
641         unsigned long *zholes_size);
642 extern void memmap_init_zone(unsigned long, int, unsigned long, unsigned long);
643 extern void mem_init(void);
644 extern void show_mem(void);
645 extern void si_meminfo(struct sysinfo * val);
646 extern void si_meminfo_node(struct sysinfo *val, int nid);
647
648 /* prio_tree.c */
649 void vma_prio_tree_add(struct vm_area_struct *, struct vm_area_struct *old);
650 void vma_prio_tree_insert(struct vm_area_struct *, struct prio_tree_root *);
651 void vma_prio_tree_remove(struct vm_area_struct *, struct prio_tree_root *);
652 struct vm_area_struct *vma_prio_tree_next(struct vm_area_struct *vma,
653         struct prio_tree_iter *iter);
654
655 #define vma_prio_tree_foreach(vma, iter, root, begin, end)      \
656         for (prio_tree_iter_init(iter, root, begin, end), vma = NULL;   \
657                 (vma = vma_prio_tree_next(vma, iter)); )
658
659 static inline void vma_nonlinear_insert(struct vm_area_struct *vma,
660                                         struct list_head *list)
661 {
662         vma->shared.vm_set.parent = NULL;
663         list_add_tail(&vma->shared.vm_set.list, list);
664 }
665
666 /* mmap.c */
667 extern void vma_adjust(struct vm_area_struct *vma, unsigned long start,
668         unsigned long end, pgoff_t pgoff, struct vm_area_struct *insert);
669 extern struct vm_area_struct *vma_merge(struct mm_struct *,
670         struct vm_area_struct *prev, unsigned long addr, unsigned long end,
671         unsigned long vm_flags, struct anon_vma *, struct file *, pgoff_t,
672         struct mempolicy *);
673 extern struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *);
674 extern int split_vma(struct mm_struct *,
675         struct vm_area_struct *, unsigned long addr, int new_below);
676 extern void insert_vm_struct(struct mm_struct *, struct vm_area_struct *);
677 extern void __vma_link_rb(struct mm_struct *, struct vm_area_struct *,
678         struct rb_node **, struct rb_node *);
679 extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
680         unsigned long addr, unsigned long len, pgoff_t pgoff);
681 extern void exit_mmap(struct mm_struct *);
682
683 extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
684
685 extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
686         unsigned long len, unsigned long prot,
687         unsigned long flag, unsigned long pgoff);
688
689 static inline unsigned long do_mmap(struct file *file, unsigned long addr,
690         unsigned long len, unsigned long prot,
691         unsigned long flag, unsigned long offset)
692 {
693         unsigned long ret = -EINVAL;
694         if ((offset + PAGE_ALIGN(len)) < offset)
695                 goto out;
696         if (!(offset & ~PAGE_MASK))
697                 ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
698 out:
699         return ret;
700 }
701
702 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
703
704 extern unsigned long do_brk(unsigned long, unsigned long);
705
706 /* filemap.c */
707 extern unsigned long page_unuse(struct page *);
708 extern void truncate_inode_pages(struct address_space *, loff_t);
709
710 /* generic vm_area_ops exported for stackable file systems */
711 struct page *filemap_nopage(struct vm_area_struct *, unsigned long, int *);
712
713 /* mm/page-writeback.c */
714 int write_one_page(struct page *page, int wait);
715
716 /* readahead.c */
717 #define VM_MAX_READAHEAD        128     /* kbytes */
718 #define VM_MIN_READAHEAD        16      /* kbytes (includes current page) */
719
720 int do_page_cache_readahead(struct address_space *mapping, struct file *filp,
721                         unsigned long offset, unsigned long nr_to_read);
722 int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
723                         unsigned long offset, unsigned long nr_to_read);
724 void page_cache_readahead(struct address_space *mapping, 
725                           struct file_ra_state *ra,
726                           struct file *filp,
727                           unsigned long offset);
728 void handle_ra_miss(struct address_space *mapping, 
729                     struct file_ra_state *ra, pgoff_t offset);
730 unsigned long max_sane_readahead(unsigned long nr);
731
732 /* Do stack extension */
733 extern int expand_stack(struct vm_area_struct * vma, unsigned long address);
734
735 /* Look up the first VMA which satisfies  addr < vm_end,  NULL if none. */
736 extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);
737 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
738                                              struct vm_area_struct **pprev);
739
740 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
741    NULL if none.  Assume start_addr < end_addr. */
742 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
743 {
744         struct vm_area_struct * vma = find_vma(mm,start_addr);
745
746         if (vma && end_addr <= vma->vm_start)
747                 vma = NULL;
748         return vma;
749 }
750
751 static inline unsigned long vma_pages(struct vm_area_struct *vma)
752 {
753         return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
754 }
755
756 extern struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr);
757
758 extern struct page * vmalloc_to_page(void *addr);
759 extern struct page * follow_page(struct mm_struct *mm, unsigned long address,
760                 int write);
761 extern int remap_page_range(struct vm_area_struct *vma, unsigned long from,
762                 unsigned long to, unsigned long size, pgprot_t prot);
763
764 #ifdef CONFIG_PROC_FS
765 void __vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
766 #else
767 static inline void __vm_stat_account(struct mm_struct *mm,
768                         unsigned long flags, struct file *file, long pages)
769 {
770 }
771 #endif /* CONFIG_PROC_FS */
772
773 static inline void vm_stat_account(struct vm_area_struct *vma)
774 {
775         __vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
776                                                         vma_pages(vma));
777 }
778
779 static inline void vm_stat_unaccount(struct vm_area_struct *vma)
780 {
781         __vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
782                                                         -vma_pages(vma));
783 }
784
785 #ifndef CONFIG_DEBUG_PAGEALLOC
786 static inline void
787 kernel_map_pages(struct page *page, int numpages, int enable)
788 {
789 }
790 #endif
791
792 #ifndef CONFIG_ARCH_GATE_AREA
793 extern struct vm_area_struct *get_gate_vma(struct task_struct *tsk);
794 int in_gate_area(struct task_struct *task, unsigned long addr);
795 #endif
796
797 #endif /* __KERNEL__ */
798 #endif /* _LINUX_MM_H */