]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/mm_types.h
zsmalloc: use page->private instead of page->first_page
[mirror_ubuntu-zesty-kernel.git] / include / linux / mm_types.h
CommitLineData
5b99cd0e
HC
1#ifndef _LINUX_MM_TYPES_H
2#define _LINUX_MM_TYPES_H
3
4f9a58d7 4#include <linux/auxvec.h>
5b99cd0e
HC
5#include <linux/types.h>
6#include <linux/threads.h>
7#include <linux/list.h>
8#include <linux/spinlock.h>
c92ff1bd
MS
9#include <linux/rbtree.h>
10#include <linux/rwsem.h>
11#include <linux/completion.h>
cddb8a5c 12#include <linux/cpumask.h>
d4b3b638 13#include <linux/uprobes.h>
bbeae5b0 14#include <linux/page-flags-layout.h>
c92ff1bd
MS
15#include <asm/page.h>
16#include <asm/mmu.h>
5b99cd0e 17
4f9a58d7
OH
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
5b99cd0e 23struct address_space;
1306a85a 24struct mem_cgroup;
5b99cd0e 25
57c1ffce 26#define USE_SPLIT_PTE_PTLOCKS (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS)
e009bb30
KS
27#define USE_SPLIT_PMD_PTLOCKS (USE_SPLIT_PTE_PTLOCKS && \
28 IS_ENABLED(CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK))
597d795a 29#define ALLOC_SPLIT_PTLOCKS (SPINLOCK_SIZE > BITS_PER_LONG/8)
f7d0b926 30
e4b294c2
KS
31typedef void compound_page_dtor(struct page *);
32
5b99cd0e
HC
33/*
34 * Each physical page in the system has a struct page associated with
35 * it to keep track of whatever it is we are using the page for at the
36 * moment. Note that we have no way to track which tasks are using
37 * a page, though if it is a pagecache page, rmap structures can tell us
38 * who is mapping it.
fc9bb8c7
CL
39 *
40 * The objects in struct page are organized in double word blocks in
41 * order to allows us to use atomic double word operations on portions
42 * of struct page. That is currently only used by slub but the arrangement
43 * allows the use of atomic double word operations on the flags/mapping
44 * and lru list pointers also.
5b99cd0e
HC
45 */
46struct page {
fc9bb8c7 47 /* First double word block */
5b99cd0e
HC
48 unsigned long flags; /* Atomic flags, some possibly
49 * updated asynchronously */
8456a648
JK
50 union {
51 struct address_space *mapping; /* If low bit clear, points to
52 * inode address_space, or NULL.
53 * If page mapped as anonymous
54 * memory, low bit is set, and
55 * it points to anon_vma object:
56 * see PAGE_MAPPING_ANON below.
57 */
58 void *s_mem; /* slab first object */
59 };
60
fc9bb8c7 61 /* Second double word */
013e8963
CL
62 struct {
63 union {
fc9bb8c7 64 pgoff_t index; /* Our offset within mapping. */
8456a648 65 void *freelist; /* sl[aou]b first free object */
013e8963
CL
66 };
67
68 union {
abca7c49
PS
69#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
70 defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
013e8963
CL
71 /* Used for cmpxchg_double in slub */
72 unsigned long counters;
abca7c49
PS
73#else
74 /*
75 * Keep _count separate from slub cmpxchg_double data.
76 * As the rest of the double word is protected by
77 * slab_lock but _count is not.
78 */
79 unsigned counters;
80#endif
013e8963
CL
81
82 struct {
83
84 union {
70b50f94
AA
85 /*
86 * Count of ptes mapped in
87 * mms, to show when page is
88 * mapped & limit reverse map
89 * searches.
90 *
91 * Used also for tail pages
92 * refcounting instead of
93 * _count. Tail pages cannot
94 * be mapped and keeping the
95 * tail page _count zero at
96 * all times guarantees
97 * get_page_unless_zero() will
98 * never succeed on tail
99 * pages.
100 */
101 atomic_t _mapcount;
fc9bb8c7 102
b8c24c4a 103 struct { /* SLUB */
013e8963
CL
104 unsigned inuse:16;
105 unsigned objects:15;
106 unsigned frozen:1;
107 };
b8c24c4a 108 int units; /* SLOB */
3adf004d 109 };
013e8963 110 atomic_t _count; /* Usage count, see below. */
fc9bb8c7 111 };
8456a648 112 unsigned int active; /* SLAB */
39b26464 113 };
81819f0f 114 };
fc9bb8c7
CL
115
116 /* Third double word block */
49e22585
CL
117 union {
118 struct list_head lru; /* Pageout list, eg. active_list
fc9bb8c7 119 * protected by zone->lru_lock !
34bf6ef9
DH
120 * Can be used as a generic list
121 * by the page owner.
fc9bb8c7 122 */
49e22585
CL
123 struct { /* slub per cpu partial pages */
124 struct page *next; /* Next partial slab */
125#ifdef CONFIG_64BIT
126 int pages; /* Nr of partial slabs left */
127 int pobjects; /* Approximate # of objects */
128#else
129 short int pages;
130 short int pobjects;
131#endif
132 };
b8c24c4a 133
68126702
JK
134 struct rcu_head rcu_head; /* Used by SLAB
135 * when destroying via RCU
136 */
e4b294c2
KS
137 /* First tail page of compound page */
138 struct {
139 compound_page_dtor *compound_dtor;
140 unsigned long compound_order;
141 };
142
7aa555bf
KS
143#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS
144 pgtable_t pmd_huge_pte; /* protected by page->ptl */
145#endif
49e22585 146 };
fc9bb8c7
CL
147
148 /* Remainder is not double word aligned */
5b99cd0e 149 union {
5b99cd0e
HC
150 unsigned long private; /* Mapping-private opaque data:
151 * usually used for buffer_heads
152 * if PagePrivate set; used for
153 * swp_entry_t if PageSwapCache;
154 * indicates order in the buddy
155 * system if PG_buddy is set.
156 */
57c1ffce 157#if USE_SPLIT_PTE_PTLOCKS
597d795a 158#if ALLOC_SPLIT_PTLOCKS
539edb58
PZ
159 spinlock_t *ptl;
160#else
161 spinlock_t ptl;
162#endif
5b99cd0e 163#endif
1b4f59e3 164 struct kmem_cache *slab_cache; /* SL[AU]B: Pointer to slab */
fc9bb8c7 165 struct page *first_page; /* Compound tail pages */
81819f0f 166 };
fc9bb8c7 167
1306a85a
JW
168#ifdef CONFIG_MEMCG
169 struct mem_cgroup *mem_cgroup;
170#endif
171
5b99cd0e
HC
172 /*
173 * On machines where all RAM is mapped into kernel address space,
174 * we can simply calculate the virtual address. On machines with
175 * highmem some memory is mapped into kernel virtual memory
176 * dynamically, so we need a place to store that address.
177 * Note that this field could be 16 bits on x86 ... ;)
178 *
179 * Architectures with slow multiplication can define
180 * WANT_PAGE_VIRTUAL in asm/page.h
181 */
182#if defined(WANT_PAGE_VIRTUAL)
183 void *virtual; /* Kernel virtual address (NULL if
184 not kmapped, ie. highmem) */
185#endif /* WANT_PAGE_VIRTUAL */
dfec072e
VN
186
187#ifdef CONFIG_KMEMCHECK
188 /*
189 * kmemcheck wants to track the status of each byte in a page; this
190 * is a pointer to such a status block. NULL if not tracked.
191 */
192 void *shadow;
193#endif
57e0a030 194
90572890
PZ
195#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
196 int _last_cpupid;
57e0a030 197#endif
fc9bb8c7
CL
198}
199/*
43570fd2
HC
200 * The struct page can be forced to be double word aligned so that atomic ops
201 * on double words work. The SLUB allocator can make use of such a feature.
fc9bb8c7 202 */
43570fd2
HC
203#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
204 __aligned(2 * sizeof(unsigned long))
fc9bb8c7
CL
205#endif
206;
5b99cd0e 207
30d3c128
IC
208struct page_frag {
209 struct page *page;
210#if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
211 __u32 offset;
212 __u32 size;
213#else
214 __u16 offset;
215 __u16 size;
216#endif
217};
218
b63ae8ca
AD
219#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK)
220#define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE)
221
222struct page_frag_cache {
223 void * va;
224#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
225 __u16 offset;
226 __u16 size;
227#else
228 __u32 offset;
229#endif
230 /* we maintain a pagecount bias, so that we dont dirty cache line
231 * containing page->_count every time we allocate a fragment.
232 */
233 unsigned int pagecnt_bias;
234 bool pfmemalloc;
235};
236
64b990d2 237typedef unsigned long vm_flags_t;
ca16d140 238
8feae131
DH
239/*
240 * A region containing a mapping of a non-memory backed file under NOMMU
241 * conditions. These are held in a global tree and are pinned by the VMAs that
242 * map parts of them.
243 */
244struct vm_region {
245 struct rb_node vm_rb; /* link in global region tree */
ca16d140 246 vm_flags_t vm_flags; /* VMA vm_flags */
8feae131
DH
247 unsigned long vm_start; /* start address of region */
248 unsigned long vm_end; /* region initialised to here */
dd8632a1 249 unsigned long vm_top; /* region allocated to here */
8feae131
DH
250 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
251 struct file *vm_file; /* the backing file or NULL */
252
1e2ae599 253 int vm_usage; /* region usage count (access under nommu_region_sem) */
cfe79c00
MF
254 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
255 * this region */
8feae131
DH
256};
257
745f234b
AA
258#ifdef CONFIG_USERFAULTFD
259#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
260struct vm_userfaultfd_ctx {
261 struct userfaultfd_ctx *ctx;
262};
263#else /* CONFIG_USERFAULTFD */
264#define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
265struct vm_userfaultfd_ctx {};
266#endif /* CONFIG_USERFAULTFD */
267
c92ff1bd
MS
268/*
269 * This struct defines a memory VMM memory area. There is one of these
270 * per VM-area/task. A VM area is any part of the process virtual memory
271 * space that has a special rule for the page-fault handlers (ie a shared
272 * library, the executable area etc).
273 */
274struct vm_area_struct {
e4c6bfd2
RR
275 /* The first cache line has the info for VMA tree walking. */
276
c92ff1bd
MS
277 unsigned long vm_start; /* Our start address within vm_mm. */
278 unsigned long vm_end; /* The first byte after our end address
279 within vm_mm. */
280
281 /* linked list of VM areas per task, sorted by address */
297c5eee 282 struct vm_area_struct *vm_next, *vm_prev;
c92ff1bd 283
c92ff1bd
MS
284 struct rb_node vm_rb;
285
d3737187
ML
286 /*
287 * Largest free memory gap in bytes to the left of this VMA.
288 * Either between this VMA and vma->vm_prev, or between one of the
289 * VMAs below us in the VMA rbtree and its ->vm_prev. This helps
290 * get_unmapped_area find a free area of the right size.
291 */
292 unsigned long rb_subtree_gap;
293
e4c6bfd2
RR
294 /* Second cache line starts here. */
295
296 struct mm_struct *vm_mm; /* The address space we belong to. */
297 pgprot_t vm_page_prot; /* Access permissions of this VMA. */
298 unsigned long vm_flags; /* Flags, see mm.h. */
299
c92ff1bd
MS
300 /*
301 * For areas with an address space and backing store,
27ba0644 302 * linkage into the address_space->i_mmap interval tree.
c92ff1bd 303 */
ac51b934
KS
304 struct {
305 struct rb_node rb;
306 unsigned long rb_subtree_last;
c92ff1bd
MS
307 } shared;
308
309 /*
310 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
311 * list, after a COW of one of the file pages. A MAP_SHARED vma
312 * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
313 * or brk vma (with NULL file) can only be in an anon_vma list.
314 */
5beb4930
RR
315 struct list_head anon_vma_chain; /* Serialized by mmap_sem &
316 * page_table_lock */
c92ff1bd
MS
317 struct anon_vma *anon_vma; /* Serialized by page_table_lock */
318
319 /* Function pointers to deal with this struct. */
f0f37e2f 320 const struct vm_operations_struct *vm_ops;
c92ff1bd
MS
321
322 /* Information about our backing store: */
323 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
324 units, *not* PAGE_CACHE_SIZE */
325 struct file * vm_file; /* File we map to (can be NULL). */
326 void * vm_private_data; /* was vm_pte (shared mem) */
c92ff1bd
MS
327
328#ifndef CONFIG_MMU
8feae131 329 struct vm_region *vm_region; /* NOMMU mapping region */
c92ff1bd
MS
330#endif
331#ifdef CONFIG_NUMA
332 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
333#endif
745f234b 334 struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
c92ff1bd
MS
335};
336
b564daf8
ON
337struct core_thread {
338 struct task_struct *task;
339 struct core_thread *next;
340};
341
32ecb1f2 342struct core_state {
c5f1cc8c 343 atomic_t nr_threads;
b564daf8 344 struct core_thread dumper;
32ecb1f2
ON
345 struct completion startup;
346};
347
d559db08
KH
348enum {
349 MM_FILEPAGES,
350 MM_ANONPAGES,
b084d435 351 MM_SWAPENTS,
d559db08
KH
352 NR_MM_COUNTERS
353};
354
57c1ffce 355#if USE_SPLIT_PTE_PTLOCKS && defined(CONFIG_MMU)
34e55232 356#define SPLIT_RSS_COUNTING
34e55232
KH
357/* per-thread cached information, */
358struct task_rss_stat {
359 int events; /* for synchronization threshold */
360 int count[NR_MM_COUNTERS];
361};
57c1ffce 362#endif /* USE_SPLIT_PTE_PTLOCKS */
172703b0 363
d559db08 364struct mm_rss_stat {
172703b0 365 atomic_long_t count[NR_MM_COUNTERS];
d559db08 366};
d559db08 367
db446a08 368struct kioctx_table;
c92ff1bd 369struct mm_struct {
615d6e87 370 struct vm_area_struct *mmap; /* list of VMAs */
c92ff1bd 371 struct rb_root mm_rb;
615d6e87 372 u32 vmacache_seqnum; /* per-thread vmacache */
efc1a3b1 373#ifdef CONFIG_MMU
c92ff1bd
MS
374 unsigned long (*get_unmapped_area) (struct file *filp,
375 unsigned long addr, unsigned long len,
376 unsigned long pgoff, unsigned long flags);
efc1a3b1 377#endif
c92ff1bd 378 unsigned long mmap_base; /* base of mmap area */
41aacc1e 379 unsigned long mmap_legacy_base; /* base of mmap area in bottom-up allocations */
c92ff1bd 380 unsigned long task_size; /* size of task vm space */
d3737187 381 unsigned long highest_vm_end; /* highest vma end address */
c92ff1bd
MS
382 pgd_t * pgd;
383 atomic_t mm_users; /* How many users with user space? */
384 atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
dc6c9a35 385 atomic_long_t nr_ptes; /* PTE page table pages */
5a3fbef3 386#if CONFIG_PGTABLE_LEVELS > 2
dc6c9a35 387 atomic_long_t nr_pmds; /* PMD page table pages */
5a3fbef3 388#endif
c92ff1bd 389 int map_count; /* number of VMAs */
481b4bb5 390
c92ff1bd 391 spinlock_t page_table_lock; /* Protects page tables and some counters */
481b4bb5 392 struct rw_semaphore mmap_sem;
c92ff1bd
MS
393
394 struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
395 * together off init_mm.mmlist, and are protected
396 * by mmlist_lock
397 */
398
c92ff1bd
MS
399
400 unsigned long hiwater_rss; /* High-watermark of RSS usage */
401 unsigned long hiwater_vm; /* High-water virtual memory usage */
402
e10d59f2
CL
403 unsigned long total_vm; /* Total pages mapped */
404 unsigned long locked_vm; /* Pages that have PG_mlocked set */
405 unsigned long pinned_vm; /* Refcount permanently increased */
406 unsigned long shared_vm; /* Shared pages (files) */
407 unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE */
408 unsigned long stack_vm; /* VM_GROWSUP/DOWN */
e10d59f2 409 unsigned long def_flags;
c92ff1bd
MS
410 unsigned long start_code, end_code, start_data, end_data;
411 unsigned long start_brk, brk, start_stack;
412 unsigned long arg_start, arg_end, env_start, env_end;
413
414 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
415
d559db08
KH
416 /*
417 * Special counters, in some configurations protected by the
418 * page_table_lock, in other configurations by being atomic.
419 */
420 struct mm_rss_stat rss_stat;
421
801460d0
HS
422 struct linux_binfmt *binfmt;
423
6345d24d
LT
424 cpumask_var_t cpu_vm_mask_var;
425
c92ff1bd
MS
426 /* Architecture-specific MM context */
427 mm_context_t context;
428
c92ff1bd
MS
429 unsigned long flags; /* Must use atomic bitops to access the bits */
430
a94e2d40 431 struct core_state *core_state; /* coredumping support */
858f0993 432#ifdef CONFIG_AIO
db446a08
BL
433 spinlock_t ioctx_lock;
434 struct kioctx_table __rcu *ioctx_table;
858f0993 435#endif
f98bafa0 436#ifdef CONFIG_MEMCG
4cd1a8fc
KM
437 /*
438 * "owner" points to a task that is regarded as the canonical
439 * user/owner of this mm. All of the following must be true in
440 * order for it to be changed:
441 *
442 * current == mm->owner
443 * current->mm != mm
444 * new_owner->mm == mm
445 * new_owner->alloc_lock is held
446 */
4d2deb40 447 struct task_struct __rcu *owner;
78fb7466 448#endif
925d1c40 449
925d1c40 450 /* store ref to file /proc/<pid>/exe symlink points to */
90f31d0e 451 struct file __rcu *exe_file;
cddb8a5c
AA
452#ifdef CONFIG_MMU_NOTIFIER
453 struct mmu_notifier_mm *mmu_notifier_mm;
e7a00c45 454#endif
e009bb30 455#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
e7a00c45 456 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
cddb8a5c 457#endif
6345d24d
LT
458#ifdef CONFIG_CPUMASK_OFFSTACK
459 struct cpumask cpumask_allocation;
cbee9f88
PZ
460#endif
461#ifdef CONFIG_NUMA_BALANCING
462 /*
34f0315a
MG
463 * numa_next_scan is the next time that the PTEs will be marked
464 * pte_numa. NUMA hinting faults will gather statistics and migrate
465 * pages to new nodes if necessary.
cbee9f88
PZ
466 */
467 unsigned long numa_next_scan;
468
6e5fb223
PZ
469 /* Restart point for scanning and setting pte_numa */
470 unsigned long numa_scan_offset;
471
cbee9f88
PZ
472 /* numa_scan_seq prevents two threads setting pte_numa */
473 int numa_scan_seq;
20841405
RR
474#endif
475#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
476 /*
477 * An operation with batched TLB flushing is going on. Anything that
478 * can move process memory needs to flush the TLB when moving a
479 * PROT_NONE or PROT_NUMA mapped page.
480 */
481 bool tlb_flush_pending;
6345d24d 482#endif
d4b3b638 483 struct uprobes_state uprobes_state;
fe3d197f
DH
484#ifdef CONFIG_X86_INTEL_MPX
485 /* address of the bounds directory */
486 void __user *bd_addr;
487#endif
5d317b2b
NH
488#ifdef CONFIG_HUGETLB_PAGE
489 atomic_long_t hugetlb_usage;
490#endif
c92ff1bd
MS
491};
492
6345d24d
LT
493static inline void mm_init_cpumask(struct mm_struct *mm)
494{
495#ifdef CONFIG_CPUMASK_OFFSTACK
496 mm->cpu_vm_mask_var = &mm->cpumask_allocation;
497#endif
41f727fd 498 cpumask_clear(mm->cpu_vm_mask_var);
6345d24d
LT
499}
500
45e575ab 501/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
de03c72c
KM
502static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
503{
504 return mm->cpu_vm_mask_var;
505}
45e575ab 506
20841405
RR
507#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
508/*
509 * Memory barriers to keep this state in sync are graciously provided by
510 * the page table locks, outside of which no page table modifications happen.
511 * The barriers below prevent the compiler from re-ordering the instructions
512 * around the memory barriers that are already present in the code.
513 */
514static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
515{
516 barrier();
517 return mm->tlb_flush_pending;
518}
519static inline void set_tlb_flush_pending(struct mm_struct *mm)
520{
521 mm->tlb_flush_pending = true;
af2c1401
MG
522
523 /*
524 * Guarantee that the tlb_flush_pending store does not leak into the
525 * critical section updating the page tables
526 */
527 smp_mb__before_spinlock();
20841405
RR
528}
529/* Clearing is done after a TLB flush, which also provides a barrier. */
530static inline void clear_tlb_flush_pending(struct mm_struct *mm)
531{
532 barrier();
533 mm->tlb_flush_pending = false;
534}
535#else
536static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
537{
538 return false;
539}
540static inline void set_tlb_flush_pending(struct mm_struct *mm)
541{
542}
543static inline void clear_tlb_flush_pending(struct mm_struct *mm)
544{
545}
546#endif
547
a62c34bd
AL
548struct vm_special_mapping
549{
550 const char *name;
551 struct page **pages;
552};
553
d17d8f9d
DH
554enum tlb_flush_reason {
555 TLB_FLUSH_ON_TASK_SWITCH,
556 TLB_REMOTE_SHOOTDOWN,
557 TLB_LOCAL_SHOOTDOWN,
558 TLB_LOCAL_MM_SHOOTDOWN,
5b74283a 559 TLB_REMOTE_SEND_IPI,
d17d8f9d
DH
560 NR_TLB_FLUSH_REASONS,
561};
562
bd6dace7
TH
563 /*
564 * A swap entry has to fit into a "unsigned long", as the entry is hidden
565 * in the "index" field of the swapper address space.
566 */
567typedef struct {
568 unsigned long val;
569} swp_entry_t;
570
5b99cd0e 571#endif /* _LINUX_MM_TYPES_H */