blob: 917f2b6a0cdee69a111e17312715483b287f7b2c [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/rbtree.h>
10#include <linux/rwsem.h>
11#include <linux/completion.h>
Andrea Arcangelicddb8a52008-07-28 15:46:29 -070012#include <linux/cpumask.h>
Srikar Dronamrajud4b3b632012-03-30 23:56:31 +053013#include <linux/uprobes.h>
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080014#include <linux/page-flags-layout.h>
Michal Hockoec8d7c12016-05-20 16:57:21 -070015#include <linux/workqueue.h>
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -070016#include <asm/page.h>
17#include <asm/mmu.h>
Heiko Carstens5b99cd02006-09-27 01:50:01 -070018
Olaf Hering4f9a58d2007-10-16 23:30:12 -070019#ifndef AT_VECTOR_SIZE_ARCH
20#define AT_VECTOR_SIZE_ARCH 0
21#endif
22#define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
23
Heiko Carstens5b99cd02006-09-27 01:50:01 -070024struct address_space;
Johannes Weiner1306a852014-12-10 15:44:52 -080025struct mem_cgroup;
Heiko Carstens5b99cd02006-09-27 01:50:01 -070026
Kirill A. Shutemov57c1ffc2013-11-14 14:30:45 -080027#define USE_SPLIT_PTE_PTLOCKS (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS)
Kirill A. Shutemove009bb32013-11-14 14:31:07 -080028#define USE_SPLIT_PMD_PTLOCKS (USE_SPLIT_PTE_PTLOCKS && \
29 IS_ENABLED(CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK))
Kirill A. Shutemov597d7952013-12-20 13:35:58 +020030#define ALLOC_SPLIT_PTLOCKS (SPINLOCK_SIZE > BITS_PER_LONG/8)
Jeremy Fitzhardingef7d0b922008-09-09 15:43:22 -070031
Heiko Carstens5b99cd02006-09-27 01:50:01 -070032/*
33 * Each physical page in the system has a struct page associated with
34 * it to keep track of whatever it is we are using the page for at the
35 * moment. Note that we have no way to track which tasks are using
36 * a page, though if it is a pagecache page, rmap structures can tell us
37 * who is mapping it.
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -050038 *
39 * The objects in struct page are organized in double word blocks in
40 * order to allows us to use atomic double word operations on portions
41 * of struct page. That is currently only used by slub but the arrangement
42 * allows the use of atomic double word operations on the flags/mapping
43 * and lru list pointers also.
Heiko Carstens5b99cd02006-09-27 01:50:01 -070044 */
45struct page {
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -050046 /* First double word block */
Heiko Carstens5b99cd02006-09-27 01:50:01 -070047 unsigned long flags; /* Atomic flags, some possibly
48 * updated asynchronously */
Joonsoo Kim8456a642013-10-24 10:07:49 +090049 union {
50 struct address_space *mapping; /* If low bit clear, points to
51 * inode address_space, or NULL.
52 * If page mapped as anonymous
53 * memory, low bit is set, and
54 * it points to anon_vma object:
55 * see PAGE_MAPPING_ANON below.
56 */
57 void *s_mem; /* slab first object */
Kirill A. Shutemov53f92632016-01-15 16:53:42 -080058 atomic_t compound_mapcount; /* first tail page */
Kirill A. Shutemov9a982252016-01-15 16:54:17 -080059 /* page_deferred_list().next -- second tail page */
Joonsoo Kim8456a642013-10-24 10:07:49 +090060 };
61
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -050062 /* Second double word */
Christoph Lameter013e8962011-07-14 12:48:14 -050063 struct {
64 union {
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -050065 pgoff_t index; /* Our offset within mapping. */
Joonsoo Kim8456a642013-10-24 10:07:49 +090066 void *freelist; /* sl[aou]b first free object */
Kirill A. Shutemov9a982252016-01-15 16:54:17 -080067 /* page_deferred_list().prev -- second tail page */
Christoph Lameter013e8962011-07-14 12:48:14 -050068 };
69
70 union {
Pravin B Shelarabca7c42012-06-20 12:52:56 -070071#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
72 defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
Christoph Lameter013e8962011-07-14 12:48:14 -050073 /* Used for cmpxchg_double in slub */
74 unsigned long counters;
Pravin B Shelarabca7c42012-06-20 12:52:56 -070075#else
76 /*
Joonsoo Kim0139aa72016-05-19 17:10:49 -070077 * Keep _refcount separate from slub cmpxchg_double
78 * data. As the rest of the double word is protected by
79 * slab_lock but _refcount is not.
Pravin B Shelarabca7c42012-06-20 12:52:56 -070080 */
81 unsigned counters;
82#endif
Christoph Lameter013e8962011-07-14 12:48:14 -050083
84 struct {
85
86 union {
Andrea Arcangeli70b50f92011-11-02 13:36:59 -070087 /*
Kirill A. Shutemovddc58f22016-01-15 16:52:56 -080088 * Count of ptes mapped in mms, to show
89 * when page is mapped & limit reverse
90 * map searches.
Andrea Arcangeli70b50f92011-11-02 13:36:59 -070091 */
92 atomic_t _mapcount;
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -050093
Christoph Lameterb8c24c42012-06-13 10:24:52 -050094 struct { /* SLUB */
Christoph Lameter013e8962011-07-14 12:48:14 -050095 unsigned inuse:16;
96 unsigned objects:15;
97 unsigned frozen:1;
98 };
Christoph Lameterb8c24c42012-06-13 10:24:52 -050099 int units; /* SLOB */
Pekka Enberg3adf0042011-07-18 15:16:55 +0300100 };
Joonsoo Kim0139aa72016-05-19 17:10:49 -0700101 /*
102 * Usage count, *USE WRAPPER FUNCTION*
103 * when manual accounting. See page_ref.h
104 */
105 atomic_t _refcount;
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -0500106 };
Joonsoo Kim8456a642013-10-24 10:07:49 +0900107 unsigned int active; /* SLAB */
Christoph Lameter39b26462008-04-14 19:11:30 +0300108 };
Christoph Lameter81819f02007-05-06 14:49:36 -0700109 };
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -0500110
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800111 /*
112 * Third double word block
113 *
114 * WARNING: bit 0 of the first word encode PageTail(). That means
115 * the rest users of the storage space MUST NOT use the bit to
116 * avoid collision and false-positive PageTail().
117 */
Christoph Lameter49e22582011-08-09 16:12:27 -0500118 union {
119 struct list_head lru; /* Pageout list, eg. active_list
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -0500120 * protected by zone->lru_lock !
Dave Hansen34bf6ef2014-04-08 13:44:27 -0700121 * Can be used as a generic list
122 * by the page owner.
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -0500123 */
Dan Williams5c2c2582016-01-15 16:56:49 -0800124 struct dev_pagemap *pgmap; /* ZONE_DEVICE pages are never on an
125 * lru or handled by a slab
126 * allocator, this points to the
127 * hosting device page map.
128 */
Christoph Lameter49e22582011-08-09 16:12:27 -0500129 struct { /* slub per cpu partial pages */
130 struct page *next; /* Next partial slab */
131#ifdef CONFIG_64BIT
132 int pages; /* Nr of partial slabs left */
133 int pobjects; /* Approximate # of objects */
134#else
135 short int pages;
136 short int pobjects;
137#endif
138 };
Christoph Lameterb8c24c42012-06-13 10:24:52 -0500139
Joonsoo Kim68126702013-10-24 10:07:42 +0900140 struct rcu_head rcu_head; /* Used by SLAB
141 * when destroying via RCU
142 */
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800143 /* Tail pages of compound page */
Kirill A. Shutemove4b294c2015-02-11 15:24:46 -0800144 struct {
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800145 unsigned long compound_head; /* If bit zero is set */
146
147 /* First tail page only */
Kirill A. Shutemov1965c8b2015-11-06 16:30:00 -0800148#ifdef CONFIG_64BIT
149 /*
150 * On 64 bit system we have enough space in struct page
151 * to encode compound_dtor and compound_order with
152 * unsigned int. It can help compiler generate better or
153 * smaller code on some archtectures.
154 */
155 unsigned int compound_dtor;
156 unsigned int compound_order;
157#else
Kirill A. Shutemovf1e61552015-11-06 16:29:50 -0800158 unsigned short int compound_dtor;
159 unsigned short int compound_order;
Kirill A. Shutemov1965c8b2015-11-06 16:30:00 -0800160#endif
Kirill A. Shutemove4b294c2015-02-11 15:24:46 -0800161 };
162
Kirill A. Shutemov7aa555b2013-11-21 14:32:11 -0800163#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -0800164 struct {
165 unsigned long __pad; /* do not overlay pmd_huge_pte
166 * with compound_head to avoid
167 * possible bit 0 collision.
168 */
169 pgtable_t pmd_huge_pte; /* protected by page->ptl */
170 };
Kirill A. Shutemov7aa555b2013-11-21 14:32:11 -0800171#endif
Christoph Lameter49e22582011-08-09 16:12:27 -0500172 };
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -0500173
174 /* Remainder is not double word aligned */
Heiko Carstens5b99cd02006-09-27 01:50:01 -0700175 union {
Heiko Carstens5b99cd02006-09-27 01:50:01 -0700176 unsigned long private; /* Mapping-private opaque data:
177 * usually used for buffer_heads
178 * if PagePrivate set; used for
179 * swp_entry_t if PageSwapCache;
180 * indicates order in the buddy
181 * system if PG_buddy is set.
182 */
Kirill A. Shutemov57c1ffc2013-11-14 14:30:45 -0800183#if USE_SPLIT_PTE_PTLOCKS
Kirill A. Shutemov597d7952013-12-20 13:35:58 +0200184#if ALLOC_SPLIT_PTLOCKS
Peter Zijlstra539edb52013-11-14 14:31:52 -0800185 spinlock_t *ptl;
186#else
187 spinlock_t ptl;
188#endif
Heiko Carstens5b99cd02006-09-27 01:50:01 -0700189#endif
Glauber Costa1b4f59e32012-10-22 18:05:36 +0400190 struct kmem_cache *slab_cache; /* SL[AU]B: Pointer to slab */
Heiko Carstens5b99cd02006-09-27 01:50:01 -0700191 };
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -0500192
Johannes Weiner1306a852014-12-10 15:44:52 -0800193#ifdef CONFIG_MEMCG
194 struct mem_cgroup *mem_cgroup;
195#endif
196
Heiko Carstens5b99cd02006-09-27 01:50:01 -0700197 /*
198 * On machines where all RAM is mapped into kernel address space,
199 * we can simply calculate the virtual address. On machines with
200 * highmem some memory is mapped into kernel virtual memory
201 * dynamically, so we need a place to store that address.
202 * Note that this field could be 16 bits on x86 ... ;)
203 *
204 * Architectures with slow multiplication can define
205 * WANT_PAGE_VIRTUAL in asm/page.h
206 */
207#if defined(WANT_PAGE_VIRTUAL)
208 void *virtual; /* Kernel virtual address (NULL if
209 not kmapped, ie. highmem) */
210#endif /* WANT_PAGE_VIRTUAL */
Vegard Nossumdfec0722008-04-04 00:51:41 +0200211
212#ifdef CONFIG_KMEMCHECK
213 /*
214 * kmemcheck wants to track the status of each byte in a page; this
215 * is a pointer to such a status block. NULL if not tracked.
216 */
217 void *shadow;
218#endif
Mel Gorman57e0a032012-11-12 09:06:20 +0000219
Peter Zijlstra90572892013-10-07 11:29:20 +0100220#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
221 int _last_cpupid;
Mel Gorman57e0a032012-11-12 09:06:20 +0000222#endif
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -0500223}
224/*
Heiko Carstens43570fd2012-01-12 17:17:27 -0800225 * The struct page can be forced to be double word aligned so that atomic ops
226 * on double words work. The SLUB allocator can make use of such a feature.
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -0500227 */
Heiko Carstens43570fd2012-01-12 17:17:27 -0800228#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
229 __aligned(2 * sizeof(unsigned long))
Christoph Lameterfc9bb8c2011-06-01 12:25:48 -0500230#endif
231;
Heiko Carstens5b99cd02006-09-27 01:50:01 -0700232
Ian Campbell30d3c122011-10-20 04:58:32 -0400233struct page_frag {
234 struct page *page;
235#if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
236 __u32 offset;
237 __u32 size;
238#else
239 __u16 offset;
240 __u16 size;
241#endif
242};
243
Alexander Duyckb63ae8c2015-05-06 21:11:57 -0700244#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK)
245#define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE)
246
247struct page_frag_cache {
248 void * va;
249#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
250 __u16 offset;
251 __u16 size;
252#else
253 __u32 offset;
254#endif
255 /* we maintain a pagecount bias, so that we dont dirty cache line
Joonsoo Kim0139aa72016-05-19 17:10:49 -0700256 * containing page->_refcount every time we allocate a fragment.
Alexander Duyckb63ae8c2015-05-06 21:11:57 -0700257 */
258 unsigned int pagecnt_bias;
259 bool pfmemalloc;
260};
261
Kirill A. Shutemov64b990d2015-09-08 15:02:15 -0700262typedef unsigned long vm_flags_t;
KOSAKI Motohiroca16d142011-05-26 19:16:19 +0900263
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700264/*
David Howells8feae132009-01-08 12:04:47 +0000265 * A region containing a mapping of a non-memory backed file under NOMMU
266 * conditions. These are held in a global tree and are pinned by the VMAs that
267 * map parts of them.
268 */
269struct vm_region {
270 struct rb_node vm_rb; /* link in global region tree */
KOSAKI Motohiroca16d142011-05-26 19:16:19 +0900271 vm_flags_t vm_flags; /* VMA vm_flags */
David Howells8feae132009-01-08 12:04:47 +0000272 unsigned long vm_start; /* start address of region */
273 unsigned long vm_end; /* region initialised to here */
Paul Mundtdd8632a2009-01-08 12:04:47 +0000274 unsigned long vm_top; /* region allocated to here */
David Howells8feae132009-01-08 12:04:47 +0000275 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
276 struct file *vm_file; /* the backing file or NULL */
277
David Howells1e2ae592010-01-15 17:01:33 -0800278 int vm_usage; /* region usage count (access under nommu_region_sem) */
Mike Frysingercfe79c02010-01-06 17:23:23 +0000279 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
280 * this region */
David Howells8feae132009-01-08 12:04:47 +0000281};
282
Andrea Arcangeli745f2342015-09-04 15:46:14 -0700283#ifdef CONFIG_USERFAULTFD
284#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
285struct vm_userfaultfd_ctx {
286 struct userfaultfd_ctx *ctx;
287};
288#else /* CONFIG_USERFAULTFD */
289#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
290struct vm_userfaultfd_ctx {};
291#endif /* CONFIG_USERFAULTFD */
292
David Howells8feae132009-01-08 12:04:47 +0000293/*
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700294 * This struct defines a memory VMM memory area. There is one of these
295 * per VM-area/task. A VM area is any part of the process virtual memory
296 * space that has a special rule for the page-fault handlers (ie a shared
297 * library, the executable area etc).
298 */
299struct vm_area_struct {
Rik van Riele4c6bfd2012-12-11 16:01:44 -0800300 /* The first cache line has the info for VMA tree walking. */
301
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700302 unsigned long vm_start; /* Our start address within vm_mm. */
303 unsigned long vm_end; /* The first byte after our end address
304 within vm_mm. */
305
306 /* linked list of VM areas per task, sorted by address */
Linus Torvalds297c5ee2010-08-20 16:24:55 -0700307 struct vm_area_struct *vm_next, *vm_prev;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700308
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700309 struct rb_node vm_rb;
310
311 /*
Michel Lespinassed3737182012-12-11 16:01:38 -0800312 * Largest free memory gap in bytes to the left of this VMA.
313 * Either between this VMA and vma->vm_prev, or between one of the
314 * VMAs below us in the VMA rbtree and its ->vm_prev. This helps
315 * get_unmapped_area find a free area of the right size.
316 */
317 unsigned long rb_subtree_gap;
318
Rik van Riele4c6bfd2012-12-11 16:01:44 -0800319 /* Second cache line starts here. */
320
321 struct mm_struct *vm_mm; /* The address space we belong to. */
322 pgprot_t vm_page_prot; /* Access permissions of this VMA. */
323 unsigned long vm_flags; /* Flags, see mm.h. */
324
Michel Lespinassed3737182012-12-11 16:01:38 -0800325 /*
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700326 * For areas with an address space and backing store,
Kirill A. Shutemov27ba0642015-02-10 14:09:59 -0800327 * linkage into the address_space->i_mmap interval tree.
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700328 */
Kirill A. Shutemovac51b932015-02-10 14:10:02 -0800329 struct {
330 struct rb_node rb;
331 unsigned long rb_subtree_last;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700332 } shared;
333
334 /*
335 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
336 * list, after a COW of one of the file pages. A MAP_SHARED vma
337 * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
338 * or brk vma (with NULL file) can only be in an anon_vma list.
339 */
Rik van Riel5beb4932010-03-05 13:42:07 -0800340 struct list_head anon_vma_chain; /* Serialized by mmap_sem &
341 * page_table_lock */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700342 struct anon_vma *anon_vma; /* Serialized by page_table_lock */
343
344 /* Function pointers to deal with this struct. */
Alexey Dobriyanf0f37e22009-09-27 22:29:37 +0400345 const struct vm_operations_struct *vm_ops;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700346
347 /* Information about our backing store: */
348 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
Kirill A. Shutemovea1754a2016-04-01 15:29:48 +0300349 units */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700350 struct file * vm_file; /* File we map to (can be NULL). */
351 void * vm_private_data; /* was vm_pte (shared mem) */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700352
353#ifndef CONFIG_MMU
David Howells8feae132009-01-08 12:04:47 +0000354 struct vm_region *vm_region; /* NOMMU mapping region */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700355#endif
356#ifdef CONFIG_NUMA
357 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
358#endif
Andrea Arcangeli745f2342015-09-04 15:46:14 -0700359 struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700360};
361
Oleg Nesterovb564daf2008-07-25 01:47:44 -0700362struct core_thread {
363 struct task_struct *task;
364 struct core_thread *next;
365};
366
Oleg Nesterov32ecb1f2008-07-25 01:47:41 -0700367struct core_state {
Oleg Nesterovc5f1cc82008-07-25 01:47:42 -0700368 atomic_t nr_threads;
Oleg Nesterovb564daf2008-07-25 01:47:44 -0700369 struct core_thread dumper;
Oleg Nesterov32ecb1f2008-07-25 01:47:41 -0700370 struct completion startup;
371};
372
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800373enum {
Jerome Marchandeca56ff2016-01-14 15:19:26 -0800374 MM_FILEPAGES, /* Resident file mapping pages */
375 MM_ANONPAGES, /* Resident anonymous pages */
376 MM_SWAPENTS, /* Anonymous swap entries */
377 MM_SHMEMPAGES, /* Resident shared memory pages */
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800378 NR_MM_COUNTERS
379};
380
Kirill A. Shutemov57c1ffc2013-11-14 14:30:45 -0800381#if USE_SPLIT_PTE_PTLOCKS && defined(CONFIG_MMU)
KAMEZAWA Hiroyuki34e55232010-03-05 13:41:40 -0800382#define SPLIT_RSS_COUNTING
KAMEZAWA Hiroyuki34e55232010-03-05 13:41:40 -0800383/* per-thread cached information, */
384struct task_rss_stat {
385 int events; /* for synchronization threshold */
386 int count[NR_MM_COUNTERS];
387};
Kirill A. Shutemov57c1ffc2013-11-14 14:30:45 -0800388#endif /* USE_SPLIT_PTE_PTLOCKS */
Matt Fleming172703b2011-05-24 17:12:36 -0700389
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800390struct mm_rss_stat {
Matt Fleming172703b2011-05-24 17:12:36 -0700391 atomic_long_t count[NR_MM_COUNTERS];
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800392};
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800393
Benjamin LaHaisedb446a02013-07-30 12:54:40 -0400394struct kioctx_table;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700395struct mm_struct {
Davidlohr Bueso615d6e82014-04-07 15:37:25 -0700396 struct vm_area_struct *mmap; /* list of VMAs */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700397 struct rb_root mm_rb;
Davidlohr Bueso615d6e82014-04-07 15:37:25 -0700398 u32 vmacache_seqnum; /* per-thread vmacache */
David Howellsefc1a3b2010-01-15 17:01:35 -0800399#ifdef CONFIG_MMU
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700400 unsigned long (*get_unmapped_area) (struct file *filp,
401 unsigned long addr, unsigned long len,
402 unsigned long pgoff, unsigned long flags);
David Howellsefc1a3b2010-01-15 17:01:35 -0800403#endif
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700404 unsigned long mmap_base; /* base of mmap area */
Radu Caragea41aacc12013-08-21 20:55:59 +0300405 unsigned long mmap_legacy_base; /* base of mmap area in bottom-up allocations */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700406 unsigned long task_size; /* size of task vm space */
Michel Lespinassed3737182012-12-11 16:01:38 -0800407 unsigned long highest_vm_end; /* highest vma end address */
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700408 pgd_t * pgd;
409 atomic_t mm_users; /* How many users with user space? */
410 atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
Kirill A. Shutemovdc6c9a32015-02-11 15:26:50 -0800411 atomic_long_t nr_ptes; /* PTE page table pages */
Kirill A. Shutemov5a3fbef2015-04-14 15:46:21 -0700412#if CONFIG_PGTABLE_LEVELS > 2
Kirill A. Shutemovdc6c9a32015-02-11 15:26:50 -0800413 atomic_long_t nr_pmds; /* PMD page table pages */
Kirill A. Shutemov5a3fbef2015-04-14 15:46:21 -0700414#endif
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700415 int map_count; /* number of VMAs */
Richard Kennedy481b4bb2011-03-22 16:32:50 -0700416
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700417 spinlock_t page_table_lock; /* Protects page tables and some counters */
Richard Kennedy481b4bb2011-03-22 16:32:50 -0700418 struct rw_semaphore mmap_sem;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700419
420 struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
421 * together off init_mm.mmlist, and are protected
422 * by mmlist_lock
423 */
424
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700425
426 unsigned long hiwater_rss; /* High-watermark of RSS usage */
427 unsigned long hiwater_vm; /* High-water virtual memory usage */
428
Christoph Lametere10d59f2011-10-31 17:07:34 -0700429 unsigned long total_vm; /* Total pages mapped */
430 unsigned long locked_vm; /* Pages that have PG_mlocked set */
431 unsigned long pinned_vm; /* Refcount permanently increased */
Konstantin Khlebnikov30bdbb72016-02-02 16:57:46 -0800432 unsigned long data_vm; /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
433 unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
434 unsigned long stack_vm; /* VM_STACK */
Christoph Lametere10d59f2011-10-31 17:07:34 -0700435 unsigned long def_flags;
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700436 unsigned long start_code, end_code, start_data, end_data;
437 unsigned long start_brk, brk, start_stack;
438 unsigned long arg_start, arg_end, env_start, env_end;
439
440 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
441
KAMEZAWA Hiroyukid559db02010-03-05 13:41:39 -0800442 /*
443 * Special counters, in some configurations protected by the
444 * page_table_lock, in other configurations by being atomic.
445 */
446 struct mm_rss_stat rss_stat;
447
Hiroshi Shimamoto801460d2009-09-23 15:57:41 -0700448 struct linux_binfmt *binfmt;
449
Linus Torvalds6345d242011-05-29 11:32:28 -0700450 cpumask_var_t cpu_vm_mask_var;
451
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700452 /* Architecture-specific MM context */
453 mm_context_t context;
454
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700455 unsigned long flags; /* Must use atomic bitops to access the bits */
456
Oleg Nesterova94e2d42008-07-25 01:47:46 -0700457 struct core_state *core_state; /* coredumping support */
Alexey Dobriyan858f0992009-09-23 15:57:32 -0700458#ifdef CONFIG_AIO
Benjamin LaHaisedb446a02013-07-30 12:54:40 -0400459 spinlock_t ioctx_lock;
460 struct kioctx_table __rcu *ioctx_table;
Alexey Dobriyan858f0992009-09-23 15:57:32 -0700461#endif
Oleg Nesterovf98bafa2014-06-04 16:07:34 -0700462#ifdef CONFIG_MEMCG
KOSAKI Motohiro4cd1a8f2008-05-12 14:02:31 -0700463 /*
464 * "owner" points to a task that is regarded as the canonical
465 * user/owner of this mm. All of the following must be true in
466 * order for it to be changed:
467 *
468 * current == mm->owner
469 * current->mm != mm
470 * new_owner->mm == mm
471 * new_owner->alloc_lock is held
472 */
Arnd Bergmann4d2deb42010-02-24 20:01:56 +0100473 struct task_struct __rcu *owner;
Pavel Emelianov78fb7462008-02-07 00:13:51 -0800474#endif
Matt Helsley925d1c42008-04-29 01:01:36 -0700475
Matt Helsley925d1c42008-04-29 01:01:36 -0700476 /* store ref to file /proc/<pid>/exe symlink points to */
Konstantin Khlebnikov90f31d02015-04-16 12:47:56 -0700477 struct file __rcu *exe_file;
Andrea Arcangelicddb8a52008-07-28 15:46:29 -0700478#ifdef CONFIG_MMU_NOTIFIER
479 struct mmu_notifier_mm *mmu_notifier_mm;
480#endif
Kirill A. Shutemove009bb32013-11-14 14:31:07 -0800481#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
Andrea Arcangelie7a00c42011-01-13 15:46:45 -0800482 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
483#endif
Linus Torvalds6345d242011-05-29 11:32:28 -0700484#ifdef CONFIG_CPUMASK_OFFSTACK
485 struct cpumask cpumask_allocation;
486#endif
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200487#ifdef CONFIG_NUMA_BALANCING
488 /*
Mel Gorman34f03152013-02-22 16:34:25 -0800489 * numa_next_scan is the next time that the PTEs will be marked
490 * pte_numa. NUMA hinting faults will gather statistics and migrate
491 * pages to new nodes if necessary.
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200492 */
493 unsigned long numa_next_scan;
494
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200495 /* Restart point for scanning and setting pte_numa */
496 unsigned long numa_scan_offset;
497
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200498 /* numa_scan_seq prevents two threads setting pte_numa */
499 int numa_scan_seq;
500#endif
Rik van Riel20841402013-12-18 17:08:44 -0800501#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
502 /*
503 * An operation with batched TLB flushing is going on. Anything that
504 * can move process memory needs to flush the TLB when moving a
505 * PROT_NONE or PROT_NUMA mapped page.
506 */
507 bool tlb_flush_pending;
508#endif
Srikar Dronamrajud4b3b632012-03-30 23:56:31 +0530509 struct uprobes_state uprobes_state;
Dave Hansenfe3d1972014-11-14 07:18:29 -0800510#ifdef CONFIG_X86_INTEL_MPX
511 /* address of the bounds directory */
512 void __user *bd_addr;
513#endif
Naoya Horiguchi5d317b22015-11-05 18:47:14 -0800514#ifdef CONFIG_HUGETLB_PAGE
515 atomic_long_t hugetlb_usage;
516#endif
Michal Hocko7ef949d72016-05-26 15:16:22 -0700517#ifdef CONFIG_MMU
Michal Hockoec8d7c12016-05-20 16:57:21 -0700518 struct work_struct async_put_work;
Michal Hocko7ef949d72016-05-26 15:16:22 -0700519#endif
Martin Schwidefskyc92ff1b2007-10-16 01:24:43 -0700520};
521
Linus Torvalds6345d242011-05-29 11:32:28 -0700522static inline void mm_init_cpumask(struct mm_struct *mm)
523{
524#ifdef CONFIG_CPUMASK_OFFSTACK
525 mm->cpu_vm_mask_var = &mm->cpumask_allocation;
526#endif
Vladimir Davydov41f727f2014-08-08 14:21:56 -0700527 cpumask_clear(mm->cpu_vm_mask_var);
Linus Torvalds6345d242011-05-29 11:32:28 -0700528}
529
Rusty Russell45e575a2009-03-12 14:35:44 -0600530/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
KOSAKI Motohirode03c722011-05-24 17:12:15 -0700531static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
532{
533 return mm->cpu_vm_mask_var;
534}
Rusty Russell45e575a2009-03-12 14:35:44 -0600535
Rik van Riel20841402013-12-18 17:08:44 -0800536#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
537/*
538 * Memory barriers to keep this state in sync are graciously provided by
539 * the page table locks, outside of which no page table modifications happen.
540 * The barriers below prevent the compiler from re-ordering the instructions
541 * around the memory barriers that are already present in the code.
542 */
543static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
544{
545 barrier();
546 return mm->tlb_flush_pending;
547}
548static inline void set_tlb_flush_pending(struct mm_struct *mm)
549{
550 mm->tlb_flush_pending = true;
Mel Gormanaf2c1402013-12-18 17:08:45 -0800551
552 /*
553 * Guarantee that the tlb_flush_pending store does not leak into the
554 * critical section updating the page tables
555 */
556 smp_mb__before_spinlock();
Rik van Riel20841402013-12-18 17:08:44 -0800557}
558/* Clearing is done after a TLB flush, which also provides a barrier. */
559static inline void clear_tlb_flush_pending(struct mm_struct *mm)
560{
561 barrier();
562 mm->tlb_flush_pending = false;
563}
564#else
565static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
566{
567 return false;
568}
569static inline void set_tlb_flush_pending(struct mm_struct *mm)
570{
571}
572static inline void clear_tlb_flush_pending(struct mm_struct *mm)
573{
574}
575#endif
576
Andy Lutomirskif872f542015-12-29 20:12:19 -0800577struct vm_fault;
578
579struct vm_special_mapping {
580 const char *name; /* The name, e.g. "[vdso]". */
581
582 /*
583 * If .fault is not provided, this points to a
584 * NULL-terminated array of pages that back the special mapping.
585 *
586 * This must not be NULL unless .fault is provided.
587 */
Andy Lutomirskia62c34b2014-05-19 15:58:33 -0700588 struct page **pages;
Andy Lutomirskif872f542015-12-29 20:12:19 -0800589
590 /*
591 * If non-NULL, then this is called to resolve page faults
592 * on the special mapping. If used, .pages is not checked.
593 */
594 int (*fault)(const struct vm_special_mapping *sm,
595 struct vm_area_struct *vma,
596 struct vm_fault *vmf);
Dmitry Safonovb059a452016-06-28 14:35:38 +0300597
598 int (*mremap)(const struct vm_special_mapping *sm,
599 struct vm_area_struct *new_vma);
Andy Lutomirskia62c34b2014-05-19 15:58:33 -0700600};
601
Dave Hansend17d8f92014-07-31 08:40:59 -0700602enum tlb_flush_reason {
603 TLB_FLUSH_ON_TASK_SWITCH,
604 TLB_REMOTE_SHOOTDOWN,
605 TLB_LOCAL_SHOOTDOWN,
606 TLB_LOCAL_MM_SHOOTDOWN,
Mel Gorman5b742832015-09-04 15:47:29 -0700607 TLB_REMOTE_SEND_IPI,
Dave Hansend17d8f92014-07-31 08:40:59 -0700608 NR_TLB_FLUSH_REASONS,
609};
610
Tejun Heobd6dace2014-12-12 16:55:35 -0800611 /*
612 * A swap entry has to fit into a "unsigned long", as the entry is hidden
613 * in the "index" field of the swapper address space.
614 */
615typedef struct {
616 unsigned long val;
617} swp_entry_t;
618
Heiko Carstens5b99cd02006-09-27 01:50:01 -0700619#endif /* _LINUX_MM_TYPES_H */