Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_MM_TYPES_H |
| 2 | #define _LINUX_MM_TYPES_H |
| 3 | |
Olaf Hering | 4f9a58d | 2007-10-16 23:30:12 -0700 | [diff] [blame] | 4 | #include <linux/auxvec.h> |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 5 | #include <linux/types.h> |
| 6 | #include <linux/threads.h> |
| 7 | #include <linux/list.h> |
| 8 | #include <linux/spinlock.h> |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 9 | #include <linux/prio_tree.h> |
| 10 | #include <linux/rbtree.h> |
| 11 | #include <linux/rwsem.h> |
| 12 | #include <linux/completion.h> |
Andrea Arcangeli | cddb8a5 | 2008-07-28 15:46:29 -0700 | [diff] [blame] | 13 | #include <linux/cpumask.h> |
Akinobu Mita | 6a11f75 | 2009-03-31 15:23:17 -0700 | [diff] [blame] | 14 | #include <linux/page-debug-flags.h> |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 15 | #include <asm/page.h> |
| 16 | #include <asm/mmu.h> |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 17 | |
Olaf Hering | 4f9a58d | 2007-10-16 23:30:12 -0700 | [diff] [blame] | 18 | #ifndef AT_VECTOR_SIZE_ARCH |
| 19 | #define AT_VECTOR_SIZE_ARCH 0 |
| 20 | #endif |
| 21 | #define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1)) |
| 22 | |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 23 | struct address_space; |
| 24 | |
Jeremy Fitzhardinge | f7d0b92 | 2008-09-09 15:43:22 -0700 | [diff] [blame] | 25 | #define USE_SPLIT_PTLOCKS (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS) |
| 26 | |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 27 | /* |
| 28 | * Each physical page in the system has a struct page associated with |
| 29 | * it to keep track of whatever it is we are using the page for at the |
| 30 | * moment. Note that we have no way to track which tasks are using |
| 31 | * a page, though if it is a pagecache page, rmap structures can tell us |
| 32 | * who is mapping it. |
| 33 | */ |
| 34 | struct page { |
| 35 | unsigned long flags; /* Atomic flags, some possibly |
| 36 | * updated asynchronously */ |
| 37 | atomic_t _count; /* Usage count, see below. */ |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 38 | union { |
| 39 | atomic_t _mapcount; /* Count of ptes mapped in mms, |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 40 | * to show when page is mapped |
| 41 | * & limit reverse map searches. |
| 42 | */ |
Christoph Lameter | 39b2646 | 2008-04-14 19:11:30 +0300 | [diff] [blame] | 43 | struct { /* SLUB */ |
| 44 | u16 inuse; |
| 45 | u16 objects; |
| 46 | }; |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 47 | }; |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 48 | union { |
| 49 | struct { |
| 50 | unsigned long private; /* Mapping-private opaque data: |
| 51 | * usually used for buffer_heads |
| 52 | * if PagePrivate set; used for |
| 53 | * swp_entry_t if PageSwapCache; |
| 54 | * indicates order in the buddy |
| 55 | * system if PG_buddy is set. |
| 56 | */ |
| 57 | struct address_space *mapping; /* If low bit clear, points to |
| 58 | * inode address_space, or NULL. |
| 59 | * If page mapped as anonymous |
| 60 | * memory, low bit is set, and |
| 61 | * it points to anon_vma object: |
| 62 | * see PAGE_MAPPING_ANON below. |
| 63 | */ |
| 64 | }; |
Jeremy Fitzhardinge | f7d0b92 | 2008-09-09 15:43:22 -0700 | [diff] [blame] | 65 | #if USE_SPLIT_PTLOCKS |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 66 | spinlock_t ptl; |
| 67 | #endif |
Christoph Lameter | a973e9d | 2008-03-01 13:40:44 -0800 | [diff] [blame] | 68 | struct kmem_cache *slab; /* SLUB: Pointer to slab */ |
Christoph Lameter | 8e65d24 | 2007-10-16 01:26:06 -0700 | [diff] [blame] | 69 | struct page *first_page; /* Compound tail pages */ |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 70 | }; |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 71 | union { |
| 72 | pgoff_t index; /* Our offset within mapping. */ |
Christoph Lameter | 894b878 | 2007-05-10 03:15:16 -0700 | [diff] [blame] | 73 | void *freelist; /* SLUB: freelist req. slab lock */ |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 74 | }; |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 75 | struct list_head lru; /* Pageout list, eg. active_list |
| 76 | * protected by zone->lru_lock ! |
| 77 | */ |
| 78 | /* |
| 79 | * On machines where all RAM is mapped into kernel address space, |
| 80 | * we can simply calculate the virtual address. On machines with |
| 81 | * highmem some memory is mapped into kernel virtual memory |
| 82 | * dynamically, so we need a place to store that address. |
| 83 | * Note that this field could be 16 bits on x86 ... ;) |
| 84 | * |
| 85 | * Architectures with slow multiplication can define |
| 86 | * WANT_PAGE_VIRTUAL in asm/page.h |
| 87 | */ |
| 88 | #if defined(WANT_PAGE_VIRTUAL) |
| 89 | void *virtual; /* Kernel virtual address (NULL if |
| 90 | not kmapped, ie. highmem) */ |
| 91 | #endif /* WANT_PAGE_VIRTUAL */ |
Akinobu Mita | ee3b429 | 2009-04-02 16:56:30 -0700 | [diff] [blame] | 92 | #ifdef CONFIG_WANT_PAGE_DEBUG_FLAGS |
| 93 | unsigned long debug_flags; /* Use atomic bitops on this */ |
| 94 | #endif |
Vegard Nossum | dfec072 | 2008-04-04 00:51:41 +0200 | [diff] [blame] | 95 | |
| 96 | #ifdef CONFIG_KMEMCHECK |
| 97 | /* |
| 98 | * kmemcheck wants to track the status of each byte in a page; this |
| 99 | * is a pointer to such a status block. NULL if not tracked. |
| 100 | */ |
| 101 | void *shadow; |
| 102 | #endif |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 105 | /* |
David Howells | 8feae13 | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 106 | * A region containing a mapping of a non-memory backed file under NOMMU |
| 107 | * conditions. These are held in a global tree and are pinned by the VMAs that |
| 108 | * map parts of them. |
| 109 | */ |
| 110 | struct vm_region { |
| 111 | struct rb_node vm_rb; /* link in global region tree */ |
| 112 | unsigned long vm_flags; /* VMA vm_flags */ |
| 113 | unsigned long vm_start; /* start address of region */ |
| 114 | unsigned long vm_end; /* region initialised to here */ |
Paul Mundt | dd8632a | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 115 | unsigned long vm_top; /* region allocated to here */ |
David Howells | 8feae13 | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 116 | unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */ |
| 117 | struct file *vm_file; /* the backing file or NULL */ |
| 118 | |
David Howells | 1e2ae59 | 2010-01-15 17:01:33 -0800 | [diff] [blame] | 119 | int vm_usage; /* region usage count (access under nommu_region_sem) */ |
Mike Frysinger | cfe79c0 | 2010-01-06 17:23:23 +0000 | [diff] [blame] | 120 | bool vm_icache_flushed : 1; /* true if the icache has been flushed for |
| 121 | * this region */ |
David Howells | 8feae13 | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | /* |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 125 | * This struct defines a memory VMM memory area. There is one of these |
| 126 | * per VM-area/task. A VM area is any part of the process virtual memory |
| 127 | * space that has a special rule for the page-fault handlers (ie a shared |
| 128 | * library, the executable area etc). |
| 129 | */ |
| 130 | struct vm_area_struct { |
| 131 | struct mm_struct * vm_mm; /* The address space we belong to. */ |
| 132 | unsigned long vm_start; /* Our start address within vm_mm. */ |
| 133 | unsigned long vm_end; /* The first byte after our end address |
| 134 | within vm_mm. */ |
| 135 | |
| 136 | /* linked list of VM areas per task, sorted by address */ |
| 137 | struct vm_area_struct *vm_next; |
| 138 | |
| 139 | pgprot_t vm_page_prot; /* Access permissions of this VMA. */ |
Hugh Dickins | 605d928 | 2008-08-16 11:07:21 +0100 | [diff] [blame] | 140 | unsigned long vm_flags; /* Flags, see mm.h. */ |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 141 | |
| 142 | struct rb_node vm_rb; |
| 143 | |
| 144 | /* |
| 145 | * For areas with an address space and backing store, |
| 146 | * linkage into the address_space->i_mmap prio tree, or |
| 147 | * linkage to the list of like vmas hanging off its node, or |
| 148 | * linkage of vma in the address_space->i_mmap_nonlinear list. |
| 149 | */ |
| 150 | union { |
| 151 | struct { |
| 152 | struct list_head list; |
| 153 | void *parent; /* aligns with prio_tree_node parent */ |
| 154 | struct vm_area_struct *head; |
| 155 | } vm_set; |
| 156 | |
| 157 | struct raw_prio_tree_node prio_tree_node; |
| 158 | } shared; |
| 159 | |
| 160 | /* |
| 161 | * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma |
| 162 | * list, after a COW of one of the file pages. A MAP_SHARED vma |
| 163 | * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack |
| 164 | * or brk vma (with NULL file) can only be in an anon_vma list. |
| 165 | */ |
Rik van Riel | 5beb493 | 2010-03-05 13:42:07 -0800 | [diff] [blame] | 166 | struct list_head anon_vma_chain; /* Serialized by mmap_sem & |
| 167 | * page_table_lock */ |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 168 | struct anon_vma *anon_vma; /* Serialized by page_table_lock */ |
| 169 | |
| 170 | /* Function pointers to deal with this struct. */ |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 171 | const struct vm_operations_struct *vm_ops; |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 172 | |
| 173 | /* Information about our backing store: */ |
| 174 | unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE |
| 175 | units, *not* PAGE_CACHE_SIZE */ |
| 176 | struct file * vm_file; /* File we map to (can be NULL). */ |
| 177 | void * vm_private_data; /* was vm_pte (shared mem) */ |
| 178 | unsigned long vm_truncate_count;/* truncate_count or restart_addr */ |
| 179 | |
| 180 | #ifndef CONFIG_MMU |
David Howells | 8feae13 | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 181 | struct vm_region *vm_region; /* NOMMU mapping region */ |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 182 | #endif |
| 183 | #ifdef CONFIG_NUMA |
| 184 | struct mempolicy *vm_policy; /* NUMA policy for the VMA */ |
| 185 | #endif |
| 186 | }; |
| 187 | |
Oleg Nesterov | b564daf | 2008-07-25 01:47:44 -0700 | [diff] [blame] | 188 | struct core_thread { |
| 189 | struct task_struct *task; |
| 190 | struct core_thread *next; |
| 191 | }; |
| 192 | |
Oleg Nesterov | 32ecb1f | 2008-07-25 01:47:41 -0700 | [diff] [blame] | 193 | struct core_state { |
Oleg Nesterov | c5f1cc8 | 2008-07-25 01:47:42 -0700 | [diff] [blame] | 194 | atomic_t nr_threads; |
Oleg Nesterov | b564daf | 2008-07-25 01:47:44 -0700 | [diff] [blame] | 195 | struct core_thread dumper; |
Oleg Nesterov | 32ecb1f | 2008-07-25 01:47:41 -0700 | [diff] [blame] | 196 | struct completion startup; |
| 197 | }; |
| 198 | |
KAMEZAWA Hiroyuki | d559db0 | 2010-03-05 13:41:39 -0800 | [diff] [blame] | 199 | enum { |
| 200 | MM_FILEPAGES, |
| 201 | MM_ANONPAGES, |
KAMEZAWA Hiroyuki | b084d43 | 2010-03-05 13:41:42 -0800 | [diff] [blame] | 202 | MM_SWAPENTS, |
KAMEZAWA Hiroyuki | d559db0 | 2010-03-05 13:41:39 -0800 | [diff] [blame] | 203 | NR_MM_COUNTERS |
| 204 | }; |
| 205 | |
KAMEZAWA Hiroyuki | 53bddb4 | 2010-03-10 15:20:38 -0800 | [diff] [blame] | 206 | #if USE_SPLIT_PTLOCKS && defined(CONFIG_MMU) |
KAMEZAWA Hiroyuki | 34e5523 | 2010-03-05 13:41:40 -0800 | [diff] [blame] | 207 | #define SPLIT_RSS_COUNTING |
KAMEZAWA Hiroyuki | d559db0 | 2010-03-05 13:41:39 -0800 | [diff] [blame] | 208 | struct mm_rss_stat { |
| 209 | atomic_long_t count[NR_MM_COUNTERS]; |
| 210 | }; |
KAMEZAWA Hiroyuki | 34e5523 | 2010-03-05 13:41:40 -0800 | [diff] [blame] | 211 | /* per-thread cached information, */ |
| 212 | struct task_rss_stat { |
| 213 | int events; /* for synchronization threshold */ |
| 214 | int count[NR_MM_COUNTERS]; |
| 215 | }; |
KAMEZAWA Hiroyuki | d559db0 | 2010-03-05 13:41:39 -0800 | [diff] [blame] | 216 | #else /* !USE_SPLIT_PTLOCKS */ |
| 217 | struct mm_rss_stat { |
| 218 | unsigned long count[NR_MM_COUNTERS]; |
| 219 | }; |
| 220 | #endif /* !USE_SPLIT_PTLOCKS */ |
| 221 | |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 222 | struct mm_struct { |
| 223 | struct vm_area_struct * mmap; /* list of VMAs */ |
| 224 | struct rb_root mm_rb; |
| 225 | struct vm_area_struct * mmap_cache; /* last find_vma result */ |
David Howells | efc1a3b | 2010-01-15 17:01:35 -0800 | [diff] [blame] | 226 | #ifdef CONFIG_MMU |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 227 | unsigned long (*get_unmapped_area) (struct file *filp, |
| 228 | unsigned long addr, unsigned long len, |
| 229 | unsigned long pgoff, unsigned long flags); |
| 230 | void (*unmap_area) (struct mm_struct *mm, unsigned long addr); |
David Howells | efc1a3b | 2010-01-15 17:01:35 -0800 | [diff] [blame] | 231 | #endif |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 232 | unsigned long mmap_base; /* base of mmap area */ |
| 233 | unsigned long task_size; /* size of task vm space */ |
| 234 | unsigned long cached_hole_size; /* if non-zero, the largest hole below free_area_cache */ |
| 235 | unsigned long free_area_cache; /* first hole of size cached_hole_size or larger */ |
| 236 | pgd_t * pgd; |
| 237 | atomic_t mm_users; /* How many users with user space? */ |
| 238 | atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */ |
| 239 | int map_count; /* number of VMAs */ |
| 240 | struct rw_semaphore mmap_sem; |
| 241 | spinlock_t page_table_lock; /* Protects page tables and some counters */ |
| 242 | |
| 243 | struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung |
| 244 | * together off init_mm.mmlist, and are protected |
| 245 | * by mmlist_lock |
| 246 | */ |
| 247 | |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 248 | |
| 249 | unsigned long hiwater_rss; /* High-watermark of RSS usage */ |
| 250 | unsigned long hiwater_vm; /* High-water virtual memory usage */ |
| 251 | |
| 252 | unsigned long total_vm, locked_vm, shared_vm, exec_vm; |
| 253 | unsigned long stack_vm, reserved_vm, def_flags, nr_ptes; |
| 254 | unsigned long start_code, end_code, start_data, end_data; |
| 255 | unsigned long start_brk, brk, start_stack; |
| 256 | unsigned long arg_start, arg_end, env_start, env_end; |
| 257 | |
| 258 | unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */ |
| 259 | |
KAMEZAWA Hiroyuki | d559db0 | 2010-03-05 13:41:39 -0800 | [diff] [blame] | 260 | /* |
| 261 | * Special counters, in some configurations protected by the |
| 262 | * page_table_lock, in other configurations by being atomic. |
| 263 | */ |
| 264 | struct mm_rss_stat rss_stat; |
| 265 | |
Hiroshi Shimamoto | 801460d | 2009-09-23 15:57:41 -0700 | [diff] [blame] | 266 | struct linux_binfmt *binfmt; |
| 267 | |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 268 | cpumask_t cpu_vm_mask; |
| 269 | |
| 270 | /* Architecture-specific MM context */ |
| 271 | mm_context_t context; |
| 272 | |
| 273 | /* Swap token stuff */ |
| 274 | /* |
| 275 | * Last value of global fault stamp as seen by this process. |
| 276 | * In other words, this value gives an indication of how long |
| 277 | * it has been since this task got the token. |
| 278 | * Look at mm/thrash.c |
| 279 | */ |
| 280 | unsigned int faultstamp; |
| 281 | unsigned int token_priority; |
| 282 | unsigned int last_interval; |
| 283 | |
| 284 | unsigned long flags; /* Must use atomic bitops to access the bits */ |
| 285 | |
Oleg Nesterov | a94e2d4 | 2008-07-25 01:47:46 -0700 | [diff] [blame] | 286 | struct core_state *core_state; /* coredumping support */ |
Alexey Dobriyan | 858f099 | 2009-09-23 15:57:32 -0700 | [diff] [blame] | 287 | #ifdef CONFIG_AIO |
Jens Axboe | abf137d | 2008-12-09 08:11:22 +0100 | [diff] [blame] | 288 | spinlock_t ioctx_lock; |
| 289 | struct hlist_head ioctx_list; |
Alexey Dobriyan | 858f099 | 2009-09-23 15:57:32 -0700 | [diff] [blame] | 290 | #endif |
Balbir Singh | cf475ad | 2008-04-29 01:00:16 -0700 | [diff] [blame] | 291 | #ifdef CONFIG_MM_OWNER |
KOSAKI Motohiro | 4cd1a8f | 2008-05-12 14:02:31 -0700 | [diff] [blame] | 292 | /* |
| 293 | * "owner" points to a task that is regarded as the canonical |
| 294 | * user/owner of this mm. All of the following must be true in |
| 295 | * order for it to be changed: |
| 296 | * |
| 297 | * current == mm->owner |
| 298 | * current->mm != mm |
| 299 | * new_owner->mm == mm |
| 300 | * new_owner->alloc_lock is held |
| 301 | */ |
| 302 | struct task_struct *owner; |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 303 | #endif |
Matt Helsley | 925d1c4 | 2008-04-29 01:01:36 -0700 | [diff] [blame] | 304 | |
| 305 | #ifdef CONFIG_PROC_FS |
| 306 | /* store ref to file /proc/<pid>/exe symlink points to */ |
| 307 | struct file *exe_file; |
| 308 | unsigned long num_exe_file_vmas; |
| 309 | #endif |
Andrea Arcangeli | cddb8a5 | 2008-07-28 15:46:29 -0700 | [diff] [blame] | 310 | #ifdef CONFIG_MMU_NOTIFIER |
| 311 | struct mmu_notifier_mm *mmu_notifier_mm; |
| 312 | #endif |
Martin Schwidefsky | c92ff1b | 2007-10-16 01:24:43 -0700 | [diff] [blame] | 313 | }; |
| 314 | |
Rusty Russell | 45e575a | 2009-03-12 14:35:44 -0600 | [diff] [blame] | 315 | /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */ |
| 316 | #define mm_cpumask(mm) (&(mm)->cpu_vm_mask) |
| 317 | |
Heiko Carstens | 5b99cd0 | 2006-09-27 01:50:01 -0700 | [diff] [blame] | 318 | #endif /* _LINUX_MM_TYPES_H */ |