00001 #ifndef _LINUX_MM_H
00002 #define _LINUX_MM_H
00003
00004 #include <linux/sched.h>
00005 #include <linux/errno.h>
00006
00007 #ifdef __KERNEL__
00008
00009 #include <linux/string.h>
00010
00011 extern unsigned long max_mapnr;
00012 extern unsigned long num_physpages;
00013 extern void * high_memory;
00014 extern int page_cluster;
00015
00016 #include <asm/page.h>
00017 #include <asm/atomic.h>
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 struct vm_area_struct {
00035 struct mm_struct * vm_mm;
00036 unsigned long vm_start;
00037 unsigned long vm_end;
00038
00039
00040 struct vm_area_struct *vm_next;
00041
00042 pgprot_t vm_page_prot;
00043 unsigned short vm_flags;
00044
00045
00046 short vm_avl_height;
00047 struct vm_area_struct * vm_avl_left;
00048 struct vm_area_struct * vm_avl_right;
00049
00050
00051
00052
00053 struct vm_area_struct *vm_next_share;
00054 struct vm_area_struct **vm_pprev_share;
00055
00056 struct vm_operations_struct * vm_ops;
00057 unsigned long vm_offset;
00058 struct file * vm_file;
00059 unsigned long vm_pte;
00060 };
00061
00062
00063
00064
00065 #define VM_READ 0x0001
00066 #define VM_WRITE 0x0002
00067 #define VM_EXEC 0x0004
00068 #define VM_SHARED 0x0008
00069
00070 #define VM_MAYREAD 0x0010
00071 #define VM_MAYWRITE 0x0020
00072 #define VM_MAYEXEC 0x0040
00073 #define VM_MAYSHARE 0x0080
00074
00075 #define VM_GROWSDOWN 0x0100
00076 #define VM_GROWSUP 0x0200
00077 #define VM_SHM 0x0400
00078 #define VM_DENYWRITE 0x0800
00079
00080 #define VM_EXECUTABLE 0x1000
00081 #define VM_LOCKED 0x2000
00082 #define VM_IO 0x4000
00083
00084 #define VM_STACK_FLAGS 0x0177
00085
00086
00087
00088
00089
00090 extern pgprot_t protection_map[16];
00091
00092
00093
00094
00095
00096
00097
00098 struct vm_operations_struct {
00099 void (*open)(struct vm_area_struct * area);
00100 void (*close)(struct vm_area_struct * area);
00101 void (*unmap)(struct vm_area_struct *area, unsigned long, size_t);
00102 void (*protect)(struct vm_area_struct *area, unsigned long, size_t, unsigned int newprot);
00103 int (*sync)(struct vm_area_struct *area, unsigned long, size_t, unsigned int flags);
00104 void (*advise)(struct vm_area_struct *area, unsigned long, size_t, unsigned int advise);
00105 unsigned long (*nopage)(struct vm_area_struct * area, unsigned long address, int write_access);
00106 unsigned long (*wppage)(struct vm_area_struct * area, unsigned long address,
00107 unsigned long page);
00108 int (*swapout)(struct vm_area_struct *, struct page *);
00109 pte_t (*swapin)(struct vm_area_struct *, unsigned long, unsigned long);
00110 };
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 typedef struct page {
00121
00122 struct page *next;
00123 struct page *prev;
00124 struct inode *inode;
00125 unsigned long offset;
00126 struct page *next_hash;
00127 atomic_t count;
00128 unsigned long flags;
00129 struct wait_queue *wait;
00130 struct page **pprev_hash;
00131 struct buffer_head * buffers;
00132 } mem_map_t;
00133
00134
00135 #define PG_locked 0
00136 #define PG_error 1
00137 #define PG_referenced 2
00138 #define PG_dirty 3
00139 #define PG_uptodate 4
00140 #define PG_free_after 5
00141 #define PG_decr_after 6
00142 #define PG_swap_unlock_after 7
00143 #define PG_DMA 8
00144 #define PG_Slab 9
00145 #define PG_swap_cache 10
00146 #define PG_skip 11
00147 #define PG_reserved 31
00148
00149
00150 #define PageLocked(page) (test_bit(PG_locked, &(page)->flags))
00151 #define PageError(page) (test_bit(PG_error, &(page)->flags))
00152 #define PageReferenced(page) (test_bit(PG_referenced, &(page)->flags))
00153 #define PageDirty(page) (test_bit(PG_dirty, &(page)->flags))
00154 #define PageUptodate(page) (test_bit(PG_uptodate, &(page)->flags))
00155 #define PageFreeAfter(page) (test_bit(PG_free_after, &(page)->flags))
00156 #define PageDecrAfter(page) (test_bit(PG_decr_after, &(page)->flags))
00157 #define PageSwapUnlockAfter(page) (test_bit(PG_swap_unlock_after, &(page)->flags))
00158 #define PageDMA(page) (test_bit(PG_DMA, &(page)->flags))
00159 #define PageSlab(page) (test_bit(PG_Slab, &(page)->flags))
00160 #define PageSwapCache(page) (test_bit(PG_swap_cache, &(page)->flags))
00161 #define PageReserved(page) (test_bit(PG_reserved, &(page)->flags))
00162
00163 #define PageSetSlab(page) (set_bit(PG_Slab, &(page)->flags))
00164 #define PageSetSwapCache(page) (set_bit(PG_swap_cache, &(page)->flags))
00165
00166 #define PageTestandSetDirty(page) \
00167 (test_and_set_bit(PG_dirty, &(page)->flags))
00168 #define PageTestandSetSwapCache(page) \
00169 (test_and_set_bit(PG_swap_cache, &(page)->flags))
00170
00171 #define PageClearSlab(page) (clear_bit(PG_Slab, &(page)->flags))
00172 #define PageClearSwapCache(page)(clear_bit(PG_swap_cache, &(page)->flags))
00173
00174 #define PageTestandClearDirty(page) \
00175 (test_and_clear_bit(PG_dirty, &(page)->flags))
00176 #define PageTestandClearSwapCache(page) \
00177 (test_and_clear_bit(PG_swap_cache, &(page)->flags))
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 extern mem_map_t * mem_map;
00252
00253
00254
00255
00256
00257
00258 #define __get_free_page(gfp_mask) __get_free_pages((gfp_mask),0)
00259 #define __get_dma_pages(gfp_mask, order) __get_free_pages((gfp_mask) | GFP_DMA,(order))
00260 extern unsigned long FASTCALL(__get_free_pages(int gfp_mask, unsigned long gfp_order));
00261
00262 extern inline unsigned long get_free_page(int gfp_mask)
00263 {
00264 unsigned long page;
00265
00266 page = __get_free_page(gfp_mask);
00267 if (page)
00268 clear_page(page);
00269 return page;
00270 }
00271
00272 extern int low_on_memory;
00273
00274
00275
00276 #define free_page(addr) free_pages((addr),0)
00277 extern void FASTCALL(free_pages(unsigned long addr, unsigned long order));
00278 #define __free_page(page) __free_pages((page),0)
00279 extern void FASTCALL(__free_pages(struct page *, unsigned long));
00280
00281 extern void show_free_areas(void);
00282 extern unsigned long put_dirty_page(struct task_struct * tsk,unsigned long page,
00283 unsigned long address);
00284
00285 extern void free_page_tables(struct mm_struct * mm);
00286 extern void clear_page_tables(struct mm_struct *, unsigned long, int);
00287 extern int new_page_tables(struct task_struct * tsk);
00288
00289 extern void zap_page_range(struct mm_struct *mm, unsigned long address, unsigned long size);
00290 extern int copy_page_range(struct mm_struct *dst, struct mm_struct *src, struct vm_area_struct *vma);
00291 extern int remap_page_range(unsigned long from, unsigned long to, unsigned long size, pgprot_t prot);
00292 extern int zeromap_page_range(unsigned long from, unsigned long size, pgprot_t prot);
00293
00294 extern void vmtruncate(struct inode * inode, unsigned long offset);
00295 extern int handle_mm_fault(struct task_struct *tsk,struct vm_area_struct *vma, unsigned long address, int write_access);
00296 extern int make_pages_present(unsigned long addr, unsigned long end);
00297
00298 extern int pgt_cache_water[2];
00299 extern int check_pgt_cache(void);
00300
00301 extern unsigned long paging_init(unsigned long start_mem, unsigned long end_mem);
00302 extern void mem_init(unsigned long start_mem, unsigned long end_mem);
00303 extern void show_mem(void);
00304 extern void si_meminfo(struct sysinfo * val);
00305
00306
00307 extern void vma_init(void);
00308 extern void merge_segments(struct mm_struct *, unsigned long, unsigned long);
00309 extern void insert_vm_struct(struct mm_struct *, struct vm_area_struct *);
00310 extern void build_mmap_avl(struct mm_struct *);
00311 extern void exit_mmap(struct mm_struct *);
00312 extern unsigned long get_unmapped_area(unsigned long, unsigned long);
00313
00314 extern unsigned long do_mmap(struct file *, unsigned long, unsigned long,
00315 unsigned long, unsigned long, unsigned long);
00316 extern int do_munmap(unsigned long, size_t);
00317
00318
00319 extern void remove_inode_page(struct page *);
00320 extern unsigned long page_unuse(struct page *);
00321 extern int shrink_mmap(int, int);
00322 extern void truncate_inode_pages(struct inode *, unsigned long);
00323 extern unsigned long get_cached_page(struct inode *, unsigned long, int);
00324 extern void put_cached_page(unsigned long);
00325
00326
00327
00328
00329 #define __GFP_WAIT 0x01
00330 #define __GFP_LOW 0x02
00331 #define __GFP_MED 0x04
00332 #define __GFP_HIGH 0x08
00333 #define __GFP_IO 0x10
00334 #define __GFP_SWAP 0x20
00335
00336 #define __GFP_DMA 0x80
00337
00338 #define GFP_BUFFER (__GFP_MED | __GFP_WAIT)
00339 #define GFP_ATOMIC (__GFP_HIGH)
00340 #define GFP_USER (__GFP_LOW | __GFP_WAIT | __GFP_IO)
00341 #define GFP_KERNEL (__GFP_MED | __GFP_WAIT | __GFP_IO)
00342 #define GFP_NFS (__GFP_HIGH | __GFP_WAIT | __GFP_IO)
00343 #define GFP_KSWAPD (__GFP_IO | __GFP_SWAP)
00344
00345
00346
00347
00348 #define GFP_DMA __GFP_DMA
00349
00350
00351
00352 static inline int expand_stack(struct vm_area_struct * vma, unsigned long address)
00353 {
00354 unsigned long grow;
00355
00356 address &= PAGE_MASK;
00357 grow = vma->vm_start - address;
00358 if ((vma->vm_end - address
00359 > current->rlim[RLIMIT_STACK].rlim_cur) ||
00360 ((current->rlim[RLIMIT_AS].rlim_cur < RLIM_INFINITY) &&
00361 ((vma->vm_mm->total_vm << PAGE_SHIFT) + grow
00362 > current->rlim[RLIMIT_AS].rlim_cur)))
00363 return -ENOMEM;
00364 vma->vm_start = address;
00365 vma->vm_offset -= grow;
00366 vma->vm_mm->total_vm += grow >> PAGE_SHIFT;
00367 if (vma->vm_flags & VM_LOCKED)
00368 vma->vm_mm->locked_vm += grow >> PAGE_SHIFT;
00369 return 0;
00370 }
00371
00372
00373 extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);
00374
00375
00376
00377 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
00378 {
00379 struct vm_area_struct * vma = find_vma(mm,start_addr);
00380
00381 if (vma && end_addr <= vma->vm_start)
00382 vma = NULL;
00383 return vma;
00384 }
00385
00386 #define buffer_under_min() ((buffermem >> PAGE_SHIFT) * 100 < \
00387 buffer_mem.min_percent * num_physpages)
00388 #define pgcache_under_min() (page_cache_size * 100 < \
00389 page_cache.min_percent * num_physpages)
00390
00391 #endif
00392
00393 #endif