blob: 027935c86c688df2315d7ea4862d2c8e233ab8aa [file] [log] [blame]
Heiko Carstens5b99cd02006-09-27 01:50:01 -07001#ifndef _LINUX_MM_TYPES_H
2#define _LINUX_MM_TYPES_H
3
Olaf Hering4f9a58d2007-10-16 23:30:12 -07004#include <linux/auxvec.h>
Heiko Carstens5b99cd02006-09-27 01:50:01 -07005#include <linux/types.h>
6#include <linux/threads.h>
7#include <linux/list.h>
8#include <linux/spinlock.h>
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -07009#include <linux/prio_tree.h>
10#include <linux/rbtree.h>
11#include <linux/rwsem.h>
12#include <linux/completion.h>
Andrea Arcangelicddb8a52008-07-28 15:46:29 -070013#include <linux/cpumask.h>
Akinobu Mita6a11f752009-03-31 15:23:17 -070014#include <linux/page-debug-flags.h>
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -070015#include <asm/page.h>
16#include <asm/mmu.h>
Heiko Carstens5b99cd02006-09-27 01:50:01 -070017
Olaf Hering4f9a58d2007-10-16 23:30:12 -070018#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 Carstens5b99cd02006-09-27 01:50:01 -070023struct address_space;
24
Jeremy Fitzhardingef7d0b922008-09-09 15:43:22 -070025#define USE_SPLIT_PTLOCKS (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS)
26
Heiko Carstens5b99cd02006-09-27 01:50:01 -070027/*
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 */
34struct page {
35 unsigned long flags; /* Atomic flags, some possibly
36 * updated asynchronously */
37 atomic_t _count; /* Usage count, see below. */
Christoph Lameter81819f02007-05-06 14:49:36 -070038 union {
39 atomic_t _mapcount; /* Count of ptes mapped in mms,
Heiko Carstens5b99cd02006-09-27 01:50:01 -070040 * to show when page is mapped
41 * & limit reverse map searches.
42 */
Christoph Lameter39b26462008-04-14 19:11:30 +030043 struct { /* SLUB */
44 u16 inuse;
45 u16 objects;
46 };
Christoph Lameter81819f02007-05-06 14:49:36 -070047 };
Heiko Carstens5b99cd02006-09-27 01:50:01 -070048 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 Fitzhardingef7d0b922008-09-09 15:43:22 -070065#if USE_SPLIT_PTLOCKS
Heiko Carstens5b99cd02006-09-27 01:50:01 -070066 spinlock_t ptl;
67#endif
Christoph Lametera973e9d2008-03-01 13:40:44 -080068 struct kmem_cache *slab; /* SLUB: Pointer to slab */
Christoph Lameter8e65d242007-10-16 01:26:06 -070069 struct page *first_page; /* Compound tail pages */
Heiko Carstens5b99cd02006-09-27 01:50:01 -070070 };
Christoph Lameter81819f02007-05-06 14:49:36 -070071 union {
72 pgoff_t index; /* Our offset within mapping. */
Christoph Lameter894b8782007-05-10 03:15:16 -070073 void *freelist; /* SLUB: freelist req. slab lock */
Christoph Lameter81819f02007-05-06 14:49:36 -070074 };
Heiko Carstens5b99cd02006-09-27 01:50:01 -070075 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 Mitaee3b4292009-04-02 16:56:30 -070092#ifdef CONFIG_WANT_PAGE_DEBUG_FLAGS
93 unsigned long debug_flags; /* Use atomic bitops on this */
94#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +020095
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 Carstens5b99cd02006-09-27 01:50:01 -0700103};
104
KOSAKI Motohiroca16d142011-05-26 19:16:19 +0900105typedef unsigned long __nocast vm_flags_t;
106
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700107/*
David Howells8feae132009-01-08 12:04:47 +0000108 * A region containing a mapping of a non-memory backed file under NOMMU
109 * conditions. These are held in a global tree and are pinned by the VMAs that
110 * map parts of them.
111 */
112struct vm_region {
113 struct rb_node vm_rb; /* link in global region tree */
KOSAKI Motohiroca16d142011-05-26 19:16:19 +0900114 vm_flags_t vm_flags; /* VMA vm_flags */
David Howells8feae132009-01-08 12:04:47 +0000115 unsigned long vm_start; /* start address of region */
116 unsigned long vm_end; /* region initialised to here */
Paul Mundtdd8632a2009-01-08 12:04:47 +0000117 unsigned long vm_top; /* region allocated to here */
David Howells8feae132009-01-08 12:04:47 +0000118 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
119 struct file *vm_file; /* the backing file or NULL */
120
David Howells1e2ae592010-01-15 17:01:33 -0800121 int vm_usage; /* region usage count (access under nommu_region_sem) */
Mike Frysingercfe79c02010-01-06 17:23:23 +0000122 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
123 * this region */
David Howells8feae132009-01-08 12:04:47 +0000124};
125
126/*
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700127 * This struct defines a memory VMM memory area. There is one of these
128 * per VM-area/task. A VM area is any part of the process virtual memory
129 * space that has a special rule for the page-fault handlers (ie a shared
130 * library, the executable area etc).
131 */
132struct vm_area_struct {
133 struct mm_struct * vm_mm; /* The address space we belong to. */
134 unsigned long vm_start; /* Our start address within vm_mm. */
135 unsigned long vm_end; /* The first byte after our end address
136 within vm_mm. */
137
138 /* linked list of VM areas per task, sorted by address */
Linus Torvalds297c5ee2010-08-20 16:24:55 -0700139 struct vm_area_struct *vm_next, *vm_prev;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700140
141 pgprot_t vm_page_prot; /* Access permissions of this VMA. */
Hugh Dickins605d9282008-08-16 11:07:21 +0100142 unsigned long vm_flags; /* Flags, see mm.h. */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700143
144 struct rb_node vm_rb;
145
146 /*
147 * For areas with an address space and backing store,
148 * linkage into the address_space->i_mmap prio tree, or
149 * linkage to the list of like vmas hanging off its node, or
150 * linkage of vma in the address_space->i_mmap_nonlinear list.
151 */
152 union {
153 struct {
154 struct list_head list;
155 void *parent; /* aligns with prio_tree_node parent */
156 struct vm_area_struct *head;
157 } vm_set;
158
159 struct raw_prio_tree_node prio_tree_node;
160 } shared;
161
162 /*
163 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
164 * list, after a COW of one of the file pages. A MAP_SHARED vma
165 * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
166 * or brk vma (with NULL file) can only be in an anon_vma list.
167 */
Rik van Riel5beb4932010-03-05 13:42:07 -0800168 struct list_head anon_vma_chain; /* Serialized by mmap_sem &
169 * page_table_lock */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700170 struct anon_vma *anon_vma; /* Serialized by page_table_lock */
171
172 /* Function pointers to deal with this struct. */
Alexey Dobriyanf0f37e22009-09-27 22:29:37 +0400173 const struct vm_operations_struct *vm_ops;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700174
175 /* Information about our backing store: */
176 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
177 units, *not* PAGE_CACHE_SIZE */
178 struct file * vm_file; /* File we map to (can be NULL). */
179 void * vm_private_data; /* was vm_pte (shared mem) */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700180
181#ifndef CONFIG_MMU
David Howells8feae132009-01-08 12:04:47 +0000182 struct vm_region *vm_region; /* NOMMU mapping region */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700183#endif
184#ifdef CONFIG_NUMA
185 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
186#endif
187};
188
Oleg Nesterovb564daf2008-07-25 01:47:44 -0700189struct core_thread {
190 struct task_struct *task;
191 struct core_thread *next;
192};
193
Oleg Nesterov32ecb1f2008-07-25 01:47:41 -0700194struct core_state {
Oleg Nesterovc5f1cc82008-07-25 01:47:42 -0700195 atomic_t nr_threads;
Oleg Nesterovb564daf2008-07-25 01:47:44 -0700196 struct core_thread dumper;
Oleg Nesterov32ecb1f2008-07-25 01:47:41 -0700197 struct completion startup;
198};
199
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800200enum {
201 MM_FILEPAGES,
202 MM_ANONPAGES,
KAMEZAWA Hiroyukib084d432010-03-05 13:41:42 -0800203 MM_SWAPENTS,
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800204 NR_MM_COUNTERS
205};
206
KAMEZAWA Hiroyuki53bddb42010-03-10 15:20:38 -0800207#if USE_SPLIT_PTLOCKS && defined(CONFIG_MMU)
KAMEZAWA Hiroyuki34e55232010-03-05 13:41:40 -0800208#define SPLIT_RSS_COUNTING
KAMEZAWA Hiroyuki34e55232010-03-05 13:41:40 -0800209/* per-thread cached information, */
210struct task_rss_stat {
211 int events; /* for synchronization threshold */
212 int count[NR_MM_COUNTERS];
213};
Matt Fleming172703b2011-05-24 17:12:36 -0700214#endif /* USE_SPLIT_PTLOCKS */
215
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800216struct mm_rss_stat {
Matt Fleming172703b2011-05-24 17:12:36 -0700217 atomic_long_t count[NR_MM_COUNTERS];
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800218};
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800219
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700220struct mm_struct {
221 struct vm_area_struct * mmap; /* list of VMAs */
222 struct rb_root mm_rb;
223 struct vm_area_struct * mmap_cache; /* last find_vma result */
David Howellsefc1a3b2010-01-15 17:01:35 -0800224#ifdef CONFIG_MMU
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700225 unsigned long (*get_unmapped_area) (struct file *filp,
226 unsigned long addr, unsigned long len,
227 unsigned long pgoff, unsigned long flags);
228 void (*unmap_area) (struct mm_struct *mm, unsigned long addr);
David Howellsefc1a3b2010-01-15 17:01:35 -0800229#endif
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700230 unsigned long mmap_base; /* base of mmap area */
231 unsigned long task_size; /* size of task vm space */
232 unsigned long cached_hole_size; /* if non-zero, the largest hole below free_area_cache */
233 unsigned long free_area_cache; /* first hole of size cached_hole_size or larger */
234 pgd_t * pgd;
235 atomic_t mm_users; /* How many users with user space? */
236 atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
237 int map_count; /* number of VMAs */
Richard Kennedy481b4bb2011-03-22 16:32:50 -0700238
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700239 spinlock_t page_table_lock; /* Protects page tables and some counters */
Richard Kennedy481b4bb2011-03-22 16:32:50 -0700240 struct rw_semaphore mmap_sem;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700241
242 struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
243 * together off init_mm.mmlist, and are protected
244 * by mmlist_lock
245 */
246
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700247
248 unsigned long hiwater_rss; /* High-watermark of RSS usage */
249 unsigned long hiwater_vm; /* High-water virtual memory usage */
250
251 unsigned long total_vm, locked_vm, shared_vm, exec_vm;
252 unsigned long stack_vm, reserved_vm, def_flags, nr_ptes;
253 unsigned long start_code, end_code, start_data, end_data;
254 unsigned long start_brk, brk, start_stack;
255 unsigned long arg_start, arg_end, env_start, env_end;
256
257 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
258
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800259 /*
260 * Special counters, in some configurations protected by the
261 * page_table_lock, in other configurations by being atomic.
262 */
263 struct mm_rss_stat rss_stat;
264
Hiroshi Shimamoto801460d2009-09-23 15:57:41 -0700265 struct linux_binfmt *binfmt;
266
Linus Torvalds6345d242011-05-29 11:32:28 -0700267 cpumask_var_t cpu_vm_mask_var;
268
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700269 /* Architecture-specific MM context */
270 mm_context_t context;
271
272 /* Swap token stuff */
273 /*
274 * Last value of global fault stamp as seen by this process.
275 * In other words, this value gives an indication of how long
276 * it has been since this task got the token.
277 * Look at mm/thrash.c
278 */
279 unsigned int faultstamp;
280 unsigned int token_priority;
281 unsigned int last_interval;
282
Richard Kennedy481b4bb2011-03-22 16:32:50 -0700283 /* How many tasks sharing this mm are OOM_DISABLE */
284 atomic_t oom_disable_count;
285
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700286 unsigned long flags; /* Must use atomic bitops to access the bits */
287
Oleg Nesterova94e2d42008-07-25 01:47:46 -0700288 struct core_state *core_state; /* coredumping support */
Alexey Dobriyan858f0992009-09-23 15:57:32 -0700289#ifdef CONFIG_AIO
Jens Axboeabf137d2008-12-09 08:11:22 +0100290 spinlock_t ioctx_lock;
291 struct hlist_head ioctx_list;
Alexey Dobriyan858f0992009-09-23 15:57:32 -0700292#endif
Balbir Singhcf475ad2008-04-29 01:00:16 -0700293#ifdef CONFIG_MM_OWNER
KOSAKI Motohiro4cd1a8f2008-05-12 14:02:31 -0700294 /*
295 * "owner" points to a task that is regarded as the canonical
296 * user/owner of this mm. All of the following must be true in
297 * order for it to be changed:
298 *
299 * current == mm->owner
300 * current->mm != mm
301 * new_owner->mm == mm
302 * new_owner->alloc_lock is held
303 */
Arnd Bergmann4d2deb42010-02-24 20:01:56 +0100304 struct task_struct __rcu *owner;
Pavel Emelianov78fb7462008-02-07 00:13:51 -0800305#endif
Matt Helsley925d1c42008-04-29 01:01:36 -0700306
Matt Helsley925d1c42008-04-29 01:01:36 -0700307 /* store ref to file /proc/<pid>/exe symlink points to */
308 struct file *exe_file;
309 unsigned long num_exe_file_vmas;
Andrea Arcangelicddb8a52008-07-28 15:46:29 -0700310#ifdef CONFIG_MMU_NOTIFIER
311 struct mmu_notifier_mm *mmu_notifier_mm;
312#endif
Andrea Arcangelie7a00c42011-01-13 15:46:45 -0800313#ifdef CONFIG_TRANSPARENT_HUGEPAGE
314 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
315#endif
Linus Torvalds6345d242011-05-29 11:32:28 -0700316#ifdef CONFIG_CPUMASK_OFFSTACK
317 struct cpumask cpumask_allocation;
318#endif
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700319};
320
Linus Torvalds6345d242011-05-29 11:32:28 -0700321static inline void mm_init_cpumask(struct mm_struct *mm)
322{
323#ifdef CONFIG_CPUMASK_OFFSTACK
324 mm->cpu_vm_mask_var = &mm->cpumask_allocation;
325#endif
326}
327
Rusty Russell45e575a2009-03-12 14:35:44 -0600328/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
KOSAKI Motohirode03c722011-05-24 17:12:15 -0700329static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
330{
331 return mm->cpu_vm_mask_var;
332}
Rusty Russell45e575a2009-03-12 14:35:44 -0600333
Heiko Carstens5b99cd02006-09-27 01:50:01 -0700334#endif /* _LINUX_MM_TYPES_H */