1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_MM_TYPES_H
3 #define _LINUX_MM_TYPES_H
5 #include <linux/mm_types_task.h>
7 #include <linux/auxvec.h>
8 #include <linux/kref.h>
9 #include <linux/list.h>
10 #include <linux/spinlock.h>
11 #include <linux/rbtree.h>
12 #include <linux/maple_tree.h>
13 #include <linux/rwsem.h>
14 #include <linux/completion.h>
15 #include <linux/cpumask.h>
16 #include <linux/uprobes.h>
17 #include <linux/rcupdate.h>
18 #include <linux/page-flags-layout.h>
19 #include <linux/workqueue.h>
20 #include <linux/seqlock.h>
21 #include <linux/percpu_counter.h>
25 #ifndef AT_VECTOR_SIZE_ARCH
26 #define AT_VECTOR_SIZE_ARCH 0
28 #define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
36 * Each physical page in the system has a struct page associated with
37 * it to keep track of whatever it is we are using the page for at the
38 * moment. Note that we have no way to track which tasks are using
39 * a page, though if it is a pagecache page, rmap structures can tell us
42 * If you allocate the page using alloc_pages(), you can use some of the
43 * space in struct page for your own purposes. The five words in the main
44 * union are available, except for bit 0 of the first word which must be
45 * kept clear. Many users use this word to store a pointer to an object
46 * which is guaranteed to be aligned. If you use the same storage as
47 * page->mapping, you must restore it to NULL before freeing the page.
49 * The mapcount field must not be used for own purposes.
51 * If you want to use the refcount field, it must be used in such a way
52 * that other CPUs temporarily incrementing and then decrementing the
53 * refcount does not cause problems. On receiving the page from
54 * alloc_pages(), the refcount will be positive.
56 * If you allocate pages of order > 0, you can use some of the fields
57 * in each subpage, but you may need to restore some of their values
60 * SLUB uses cmpxchg_double() to atomically update its freelist and counters.
61 * That requires that freelist & counters in struct slab be adjacent and
62 * double-word aligned. Because struct slab currently just reinterprets the
63 * bits of struct page, we align all struct pages to double-word boundaries,
64 * and ensure that 'freelist' is aligned within struct slab.
66 #ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
67 #define _struct_page_alignment __aligned(2 * sizeof(unsigned long))
69 #define _struct_page_alignment __aligned(sizeof(unsigned long))
73 unsigned long flags
; /* Atomic flags, some possibly
74 * updated asynchronously */
76 * Five words (20/40 bytes) are available in this union.
77 * WARNING: bit 0 of the first word is used for PageTail(). That
78 * means the other users of this union MUST NOT use the bit to
79 * avoid collision and false-positive PageTail().
82 struct { /* Page cache and anonymous pages */
84 * @lru: Pageout list, eg. active_list protected by
85 * lruvec->lru_lock. Sometimes used as a generic list
91 /* Or, for the Unevictable "LRU list" slot */
93 /* Always even, to negate PageTail */
95 /* Count page's or folio's mlocks */
96 unsigned int mlock_count
;
100 struct list_head buddy_list
;
101 struct list_head pcp_list
;
103 /* See page-flags.h for PAGE_MAPPING_FLAGS */
104 struct address_space
*mapping
;
106 pgoff_t index
; /* Our offset within mapping. */
107 unsigned long share
; /* share count for fsdax */
110 * @private: Mapping-private opaque data.
111 * Usually used for buffer_heads if PagePrivate.
112 * Used for swp_entry_t if swapcache flag set.
113 * Indicates order in the buddy system if PageBuddy.
115 unsigned long private;
117 struct { /* page_pool used by netstack */
119 * @pp_magic: magic value to avoid recycling non
120 * page_pool allocated pages.
122 unsigned long pp_magic
;
123 struct page_pool
*pp
;
124 unsigned long _pp_mapping_pad
;
125 unsigned long dma_addr
;
126 atomic_long_t pp_ref_count
;
128 struct { /* Tail pages of compound page */
129 unsigned long compound_head
; /* Bit zero is set */
131 struct { /* ZONE_DEVICE pages */
132 /** @pgmap: Points to the hosting device page map. */
133 struct dev_pagemap
*pgmap
;
134 void *zone_device_data
;
136 * ZONE_DEVICE private pages are counted as being
137 * mapped so the next 3 words hold the mapping, index,
138 * and private fields from the source anonymous or
139 * page cache page while the page is migrated to device
141 * ZONE_DEVICE MEMORY_DEVICE_FS_DAX pages also
142 * use the mapping, index, and private fields when
143 * pmem backed DAX files are mapped.
147 /** @rcu_head: You can use this to free a page by RCU. */
148 struct rcu_head rcu_head
;
151 union { /* This union is 4 bytes in size. */
153 * For head pages of typed folios, the value stored here
154 * allows for determining what this page is used for. The
155 * tail pages of typed folios will not store a type
156 * (page_type == _mapcount == -1).
158 * See page-flags.h for a list of page types which are currently
161 * Owners of typed folios may reuse the lower 16 bit of the
162 * head page page_type field after setting the page type,
163 * but must reset these 16 bit to -1 before clearing the
166 unsigned int page_type
;
169 * For pages that are part of non-typed folios for which mappings
170 * are tracked via the RMAP, encodes the number of times this page
171 * is directly referenced by a page table.
173 * Note that the mapcount is always initialized to -1, so that
174 * transitions both from it and to it can be tracked, using
175 * atomic_inc_and_test() and atomic_add_negative(-1).
180 /* Usage count. *DO NOT USE DIRECTLY*. See page_ref.h */
184 unsigned long memcg_data
;
185 #elif defined(CONFIG_SLAB_OBJ_EXT)
186 unsigned long _unused_slab_obj_exts
;
190 * On machines where all RAM is mapped into kernel address space,
191 * we can simply calculate the virtual address. On machines with
192 * highmem some memory is mapped into kernel virtual memory
193 * dynamically, so we need a place to store that address.
194 * Note that this field could be 16 bits on x86 ... ;)
196 * Architectures with slow multiplication can define
197 * WANT_PAGE_VIRTUAL in asm/page.h
199 #if defined(WANT_PAGE_VIRTUAL)
200 void *virtual; /* Kernel virtual address (NULL if
201 not kmapped, ie. highmem) */
202 #endif /* WANT_PAGE_VIRTUAL */
204 #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
210 * KMSAN metadata for this page:
211 * - shadow page: every bit indicates whether the corresponding
212 * bit of the original page is initialized (0) or not (1);
213 * - origin page: every 4 bytes contain an id of the stack trace
214 * where the uninitialized value was created.
216 struct page
*kmsan_shadow
;
217 struct page
*kmsan_origin
;
219 } _struct_page_alignment
;
222 * struct encoded_page - a nonexistent type marking this pointer
224 * An 'encoded_page' pointer is a pointer to a regular 'struct page', but
225 * with the low bits of the pointer indicating extra context-dependent
226 * information. Only used in mmu_gather handling, and this acts as a type
227 * system check on that use.
229 * We only really have two guaranteed bits in general, although you could
230 * play with 'struct page' alignment (see CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
233 * Use the supplied helper functions to endcode/decode the pointer and bits.
237 #define ENCODED_PAGE_BITS 3ul
239 /* Perform rmap removal after we have flushed the TLB. */
240 #define ENCODED_PAGE_BIT_DELAY_RMAP 1ul
243 * The next item in an encoded_page array is the "nr_pages" argument, specifying
244 * the number of consecutive pages starting from this page, that all belong to
245 * the same folio. For example, "nr_pages" corresponds to the number of folio
246 * references that must be dropped. If this bit is not set, "nr_pages" is
249 #define ENCODED_PAGE_BIT_NR_PAGES_NEXT 2ul
251 static __always_inline
struct encoded_page
*encode_page(struct page
*page
, unsigned long flags
)
253 BUILD_BUG_ON(flags
> ENCODED_PAGE_BITS
);
254 return (struct encoded_page
*)(flags
| (unsigned long)page
);
257 static inline unsigned long encoded_page_flags(struct encoded_page
*page
)
259 return ENCODED_PAGE_BITS
& (unsigned long)page
;
262 static inline struct page
*encoded_page_ptr(struct encoded_page
*page
)
264 return (struct page
*)(~ENCODED_PAGE_BITS
& (unsigned long)page
);
267 static __always_inline
struct encoded_page
*encode_nr_pages(unsigned long nr
)
269 VM_WARN_ON_ONCE((nr
<< 2) >> 2 != nr
);
270 return (struct encoded_page
*)(nr
<< 2);
273 static __always_inline
unsigned long encoded_nr_pages(struct encoded_page
*page
)
275 return ((unsigned long)page
) >> 2;
279 * A swap entry has to fit into a "unsigned long", as the entry is hidden
280 * in the "index" field of the swapper address space.
287 * struct folio - Represents a contiguous set of bytes.
288 * @flags: Identical to the page flags.
289 * @lru: Least Recently Used list; tracks how recently this folio was used.
290 * @mlock_count: Number of times this folio has been pinned by mlock().
291 * @mapping: The file this page belongs to, or refers to the anon_vma for
293 * @index: Offset within the file, in units of pages. For anonymous memory,
294 * this is the index from the beginning of the mmap.
295 * @private: Filesystem per-folio data (see folio_attach_private()).
296 * @swap: Used for swp_entry_t if folio_test_swapcache().
297 * @_mapcount: Do not access this member directly. Use folio_mapcount() to
298 * find out how many times this folio is mapped by userspace.
299 * @_refcount: Do not access this member directly. Use folio_ref_count()
300 * to find how many references there are to this folio.
301 * @memcg_data: Memory Control Group data.
302 * @virtual: Virtual address in the kernel direct map.
303 * @_last_cpupid: IDs of last CPU and last process that accessed the folio.
304 * @_entire_mapcount: Do not use directly, call folio_entire_mapcount().
305 * @_large_mapcount: Do not use directly, call folio_mapcount().
306 * @_nr_pages_mapped: Do not use outside of rmap and debug code.
307 * @_pincount: Do not use directly, call folio_maybe_dma_pinned().
308 * @_folio_nr_pages: Do not use directly, call folio_nr_pages().
309 * @_hugetlb_subpool: Do not use directly, use accessor in hugetlb.h.
310 * @_hugetlb_cgroup: Do not use directly, use accessor in hugetlb_cgroup.h.
311 * @_hugetlb_cgroup_rsvd: Do not use directly, use accessor in hugetlb_cgroup.h.
312 * @_hugetlb_hwpoison: Do not use directly, call raw_hwp_list_head().
313 * @_deferred_list: Folios to be split under memory pressure.
314 * @_unused_slab_obj_exts: Placeholder to match obj_exts in struct slab.
316 * A folio is a physically, virtually and logically contiguous set
317 * of bytes. It is a power-of-two in size, and it is aligned to that
318 * same power-of-two. It is at least as large as %PAGE_SIZE. If it is
319 * in the page cache, it is at a file offset which is a multiple of that
320 * power-of-two. It may be mapped into userspace at an address which is
321 * at an arbitrary page offset, but its kernel virtual address is aligned
325 /* private: don't document the anon union */
331 struct list_head lru
;
332 /* private: avoid cluttering the output */
336 unsigned int mlock_count
;
341 struct address_space
*mapping
;
350 unsigned long memcg_data
;
351 #elif defined(CONFIG_SLAB_OBJ_EXT)
352 unsigned long _unused_slab_obj_exts
;
354 #if defined(WANT_PAGE_VIRTUAL)
357 #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
360 /* private: the union with struct page is transitional */
366 unsigned long _flags_1
;
367 unsigned long _head_1
;
369 atomic_t _large_mapcount
;
370 atomic_t _entire_mapcount
;
371 atomic_t _nr_pages_mapped
;
374 unsigned int _folio_nr_pages
;
376 /* private: the union with struct page is transitional */
378 struct page __page_1
;
382 unsigned long _flags_2
;
383 unsigned long _head_2
;
385 void *_hugetlb_subpool
;
386 void *_hugetlb_cgroup
;
387 void *_hugetlb_cgroup_rsvd
;
388 void *_hugetlb_hwpoison
;
389 /* private: the union with struct page is transitional */
392 unsigned long _flags_2a
;
393 unsigned long _head_2a
;
395 struct list_head _deferred_list
;
396 /* private: the union with struct page is transitional */
398 struct page __page_2
;
402 #define FOLIO_MATCH(pg, fl) \
403 static_assert(offsetof(struct page, pg) == offsetof(struct folio, fl))
404 FOLIO_MATCH(flags
, flags
);
405 FOLIO_MATCH(lru
, lru
);
406 FOLIO_MATCH(mapping
, mapping
);
407 FOLIO_MATCH(compound_head
, lru
);
408 FOLIO_MATCH(index
, index
);
409 FOLIO_MATCH(private, private);
410 FOLIO_MATCH(_mapcount
, _mapcount
);
411 FOLIO_MATCH(_refcount
, _refcount
);
413 FOLIO_MATCH(memcg_data
, memcg_data
);
415 #if defined(WANT_PAGE_VIRTUAL)
416 FOLIO_MATCH(virtual, virtual);
418 #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
419 FOLIO_MATCH(_last_cpupid
, _last_cpupid
);
422 #define FOLIO_MATCH(pg, fl) \
423 static_assert(offsetof(struct folio, fl) == \
424 offsetof(struct page, pg) + sizeof(struct page))
425 FOLIO_MATCH(flags
, _flags_1
);
426 FOLIO_MATCH(compound_head
, _head_1
);
428 #define FOLIO_MATCH(pg, fl) \
429 static_assert(offsetof(struct folio, fl) == \
430 offsetof(struct page, pg) + 2 * sizeof(struct page))
431 FOLIO_MATCH(flags
, _flags_2
);
432 FOLIO_MATCH(compound_head
, _head_2
);
433 FOLIO_MATCH(flags
, _flags_2a
);
434 FOLIO_MATCH(compound_head
, _head_2a
);
438 * struct ptdesc - Memory descriptor for page tables.
439 * @__page_flags: Same as page flags. Powerpc only.
440 * @pt_rcu_head: For freeing page table pages.
441 * @pt_list: List of used page tables. Used for s390 and x86.
442 * @_pt_pad_1: Padding that aliases with page's compound head.
443 * @pmd_huge_pte: Protected by ptdesc->ptl, used for THPs.
444 * @__page_mapping: Aliases with page->mapping. Unused for page tables.
445 * @pt_index: Used for s390 gmap.
446 * @pt_mm: Used for x86 pgds.
447 * @pt_frag_refcount: For fragmented page table tracking. Powerpc only.
448 * @_pt_pad_2: Padding to ensure proper alignment.
449 * @ptl: Lock for the page table.
450 * @__page_type: Same as page->page_type. Unused for page tables.
451 * @__page_refcount: Same as page refcount.
452 * @pt_memcg_data: Memcg data. Tracked for page tables here.
454 * This struct overlays struct page for now. Do not modify without a good
455 * understanding of the issues.
458 unsigned long __page_flags
;
461 struct rcu_head pt_rcu_head
;
462 struct list_head pt_list
;
464 unsigned long _pt_pad_1
;
465 pgtable_t pmd_huge_pte
;
468 unsigned long __page_mapping
;
472 struct mm_struct
*pt_mm
;
473 atomic_t pt_frag_refcount
;
477 unsigned long _pt_pad_2
;
478 #if ALLOC_SPLIT_PTLOCKS
484 unsigned int __page_type
;
485 atomic_t __page_refcount
;
487 unsigned long pt_memcg_data
;
491 #define TABLE_MATCH(pg, pt) \
492 static_assert(offsetof(struct page, pg) == offsetof(struct ptdesc, pt))
493 TABLE_MATCH(flags
, __page_flags
);
494 TABLE_MATCH(compound_head
, pt_list
);
495 TABLE_MATCH(compound_head
, _pt_pad_1
);
496 TABLE_MATCH(mapping
, __page_mapping
);
497 TABLE_MATCH(index
, pt_index
);
498 TABLE_MATCH(rcu_head
, pt_rcu_head
);
499 TABLE_MATCH(page_type
, __page_type
);
500 TABLE_MATCH(_refcount
, __page_refcount
);
502 TABLE_MATCH(memcg_data
, pt_memcg_data
);
505 static_assert(sizeof(struct ptdesc
) <= sizeof(struct page
));
507 #define ptdesc_page(pt) (_Generic((pt), \
508 const struct ptdesc *: (const struct page *)(pt), \
509 struct ptdesc *: (struct page *)(pt)))
511 #define ptdesc_folio(pt) (_Generic((pt), \
512 const struct ptdesc *: (const struct folio *)(pt), \
513 struct ptdesc *: (struct folio *)(pt)))
515 #define page_ptdesc(p) (_Generic((p), \
516 const struct page *: (const struct ptdesc *)(p), \
517 struct page *: (struct ptdesc *)(p)))
520 * Used for sizing the vmemmap region on some architectures
522 #define STRUCT_PAGE_MAX_SHIFT (order_base_2(sizeof(struct page)))
524 #define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK)
525 #define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE)
528 * page_private can be used on tail pages. However, PagePrivate is only
529 * checked by the VM on the head page. So page_private on the tail pages
530 * should be used for data that's ancillary to the head page (eg attaching
531 * buffer heads to tail pages after attaching buffer heads to the head page)
533 #define page_private(page) ((page)->private)
535 static inline void set_page_private(struct page
*page
, unsigned long private)
537 page
->private = private;
540 static inline void *folio_get_private(struct folio
*folio
)
542 return folio
->private;
545 struct page_frag_cache
{
547 #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
553 /* we maintain a pagecount bias, so that we dont dirty cache line
554 * containing page->_refcount every time we allocate a fragment.
556 unsigned int pagecnt_bias
;
560 typedef unsigned long vm_flags_t
;
563 * A region containing a mapping of a non-memory backed file under NOMMU
564 * conditions. These are held in a global tree and are pinned by the VMAs that
568 struct rb_node vm_rb
; /* link in global region tree */
569 vm_flags_t vm_flags
; /* VMA vm_flags */
570 unsigned long vm_start
; /* start address of region */
571 unsigned long vm_end
; /* region initialised to here */
572 unsigned long vm_top
; /* region allocated to here */
573 unsigned long vm_pgoff
; /* the offset in vm_file corresponding to vm_start */
574 struct file
*vm_file
; /* the backing file or NULL */
576 int vm_usage
; /* region usage count (access under nommu_region_sem) */
577 bool vm_icache_flushed
: 1; /* true if the icache has been flushed for
581 #ifdef CONFIG_USERFAULTFD
582 #define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
583 struct vm_userfaultfd_ctx
{
584 struct userfaultfd_ctx
*ctx
;
586 #else /* CONFIG_USERFAULTFD */
587 #define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
588 struct vm_userfaultfd_ctx
{};
589 #endif /* CONFIG_USERFAULTFD */
591 struct anon_vma_name
{
593 /* The name needs to be at the end because it is dynamically sized. */
597 #ifdef CONFIG_ANON_VMA_NAME
599 * mmap_lock should be read-locked when calling anon_vma_name(). Caller should
600 * either keep holding the lock while using the returned pointer or it should
601 * raise anon_vma_name refcount before releasing the lock.
603 struct anon_vma_name
*anon_vma_name(struct vm_area_struct
*vma
);
604 struct anon_vma_name
*anon_vma_name_alloc(const char *name
);
605 void anon_vma_name_free(struct kref
*kref
);
606 #else /* CONFIG_ANON_VMA_NAME */
607 static inline struct anon_vma_name
*anon_vma_name(struct vm_area_struct
*vma
)
612 static inline struct anon_vma_name
*anon_vma_name_alloc(const char *name
)
619 struct rw_semaphore lock
;
622 struct vma_numab_state
{
624 * Initialised as time in 'jiffies' after which VMA
625 * should be scanned. Delays first scan of new VMA by at
626 * least sysctl_numa_balancing_scan_delay:
628 unsigned long next_scan
;
631 * Time in jiffies when pids_active[] is reset to
632 * detect phase change behaviour:
634 unsigned long pids_active_reset
;
637 * Approximate tracking of PIDs that trapped a NUMA hinting
638 * fault. May produce false positives due to hash collisions.
640 * [0] Previous PID tracking
641 * [1] Current PID tracking
643 * Window moves after next_pid_reset has expired approximately
644 * every VMA_PID_RESET_PERIOD jiffies:
646 unsigned long pids_active
[2];
648 /* MM scan sequence ID when scan first started after VMA creation */
652 * MM scan sequence ID when the VMA was last completely scanned.
653 * A VMA is not eligible for scanning if prev_scan_seq == numa_scan_seq
659 * This struct describes a virtual memory area. There is one of these
660 * per VM-area/task. A VM area is any part of the process virtual memory
661 * space that has a special rule for the page-fault handlers (ie a shared
662 * library, the executable area etc).
664 * Only explicitly marked struct members may be accessed by RCU readers before
665 * getting a stable reference.
667 struct vm_area_struct
{
668 /* The first cache line has the info for VMA tree walking. */
672 /* VMA covers [vm_start; vm_end) addresses within mm */
673 unsigned long vm_start
;
674 unsigned long vm_end
;
676 #ifdef CONFIG_PER_VMA_LOCK
677 struct rcu_head vm_rcu
; /* Used for deferred freeing. */
682 * The address space we belong to.
683 * Unstable RCU readers are allowed to read this.
685 struct mm_struct
*vm_mm
;
686 pgprot_t vm_page_prot
; /* Access permissions of this VMA. */
690 * To modify use vm_flags_{init|reset|set|clear|mod} functions.
693 const vm_flags_t vm_flags
;
694 vm_flags_t __private __vm_flags
;
697 #ifdef CONFIG_PER_VMA_LOCK
699 * Flag to indicate areas detached from the mm->mm_mt tree.
700 * Unstable RCU readers are allowed to read this.
705 * Can only be written (using WRITE_ONCE()) while holding both:
706 * - mmap_lock (in write mode)
707 * - vm_lock->lock (in write mode)
708 * Can be read reliably while holding one of:
709 * - mmap_lock (in read or write mode)
710 * - vm_lock->lock (in read or write mode)
711 * Can be read unreliably (using READ_ONCE()) for pessimistic bailout
712 * while holding nothing (except RCU to keep the VMA struct allocated).
714 * This sequence counter is explicitly allowed to overflow; sequence
715 * counter reuse can only lead to occasional unnecessary use of the
719 /* Unstable RCU readers are allowed to read this. */
720 struct vma_lock
*vm_lock
;
724 * For areas with an address space and backing store,
725 * linkage into the address_space->i_mmap interval tree.
730 unsigned long rb_subtree_last
;
734 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
735 * list, after a COW of one of the file pages. A MAP_SHARED vma
736 * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
737 * or brk vma (with NULL file) can only be in an anon_vma list.
739 struct list_head anon_vma_chain
; /* Serialized by mmap_lock &
741 struct anon_vma
*anon_vma
; /* Serialized by page_table_lock */
743 /* Function pointers to deal with this struct. */
744 const struct vm_operations_struct
*vm_ops
;
746 /* Information about our backing store: */
747 unsigned long vm_pgoff
; /* Offset (within vm_file) in PAGE_SIZE
749 struct file
* vm_file
; /* File we map to (can be NULL). */
750 void * vm_private_data
; /* was vm_pte (shared mem) */
752 #ifdef CONFIG_ANON_VMA_NAME
754 * For private and shared anonymous mappings, a pointer to a null
755 * terminated string containing the name given to the vma, or NULL if
756 * unnamed. Serialized by mmap_lock. Use anon_vma_name to access.
758 struct anon_vma_name
*anon_name
;
761 atomic_long_t swap_readahead_info
;
764 struct vm_region
*vm_region
; /* NOMMU mapping region */
767 struct mempolicy
*vm_policy
; /* NUMA policy for the VMA */
769 #ifdef CONFIG_NUMA_BALANCING
770 struct vma_numab_state
*numab_state
; /* NUMA Balancing state */
772 struct vm_userfaultfd_ctx vm_userfaultfd_ctx
;
773 } __randomize_layout
;
776 #define vma_policy(vma) ((vma)->vm_policy)
778 #define vma_policy(vma) NULL
781 #ifdef CONFIG_SCHED_MM_CID
789 struct iommu_mm_data
;
793 * Fields which are often written to are placed in a separate
798 * @mm_count: The number of references to &struct
799 * mm_struct (@mm_users count as 1).
801 * Use mmgrab()/mmdrop() to modify. When this drops to
802 * 0, the &struct mm_struct is freed.
805 } ____cacheline_aligned_in_smp
;
807 struct maple_tree mm_mt
;
809 unsigned long mmap_base
; /* base of mmap area */
810 unsigned long mmap_legacy_base
; /* base of mmap area in bottom-up allocations */
811 #ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
812 /* Base addresses for compatible mmap() */
813 unsigned long mmap_compat_base
;
814 unsigned long mmap_compat_legacy_base
;
816 unsigned long task_size
; /* size of task vm space */
819 #ifdef CONFIG_MEMBARRIER
821 * @membarrier_state: Flags controlling membarrier behavior.
823 * This field is close to @pgd to hopefully fit in the same
824 * cache-line, which needs to be touched by switch_mm().
826 atomic_t membarrier_state
;
830 * @mm_users: The number of users including userspace.
832 * Use mmget()/mmget_not_zero()/mmput() to modify. When this
833 * drops to 0 (i.e. when the task exits and there are no other
834 * temporary reference holders), we also release a reference on
835 * @mm_count (which may then free the &struct mm_struct if
836 * @mm_count also drops to 0).
840 #ifdef CONFIG_SCHED_MM_CID
842 * @pcpu_cid: Per-cpu current cid.
844 * Keep track of the currently allocated mm_cid for each cpu.
845 * The per-cpu mm_cid values are serialized by their respective
848 struct mm_cid __percpu
*pcpu_cid
;
850 * @mm_cid_next_scan: Next mm_cid scan (in jiffies).
852 * When the next mm_cid scan is due (in jiffies).
854 unsigned long mm_cid_next_scan
;
857 atomic_long_t pgtables_bytes
; /* size of all page tables */
859 int map_count
; /* number of VMAs */
861 spinlock_t page_table_lock
; /* Protects page tables and some
865 * With some kernel config, the current mmap_lock's offset
866 * inside 'mm_struct' is at 0x120, which is very optimal, as
867 * its two hot fields 'count' and 'owner' sit in 2 different
868 * cachelines, and when mmap_lock is highly contended, both
869 * of the 2 fields will be accessed frequently, current layout
870 * will help to reduce cache bouncing.
872 * So please be careful with adding new fields before
873 * mmap_lock, which can easily push the 2 fields into one
876 struct rw_semaphore mmap_lock
;
878 struct list_head mmlist
; /* List of maybe swapped mm's. These
879 * are globally strung together off
880 * init_mm.mmlist, and are protected
883 #ifdef CONFIG_PER_VMA_LOCK
885 * This field has lock-like semantics, meaning it is sometimes
886 * accessed with ACQUIRE/RELEASE semantics.
887 * Roughly speaking, incrementing the sequence number is
888 * equivalent to releasing locks on VMAs; reading the sequence
889 * number can be part of taking a read lock on a VMA.
891 * Can be modified under write mmap_lock using RELEASE
893 * Can be read with no other protection when holding write
895 * Can be read with ACQUIRE semantics if not holding write
902 unsigned long hiwater_rss
; /* High-watermark of RSS usage */
903 unsigned long hiwater_vm
; /* High-water virtual memory usage */
905 unsigned long total_vm
; /* Total pages mapped */
906 unsigned long locked_vm
; /* Pages that have PG_mlocked set */
907 atomic64_t pinned_vm
; /* Refcount permanently increased */
908 unsigned long data_vm
; /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
909 unsigned long exec_vm
; /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
910 unsigned long stack_vm
; /* VM_STACK */
911 unsigned long def_flags
;
914 * @write_protect_seq: Locked when any thread is write
915 * protecting pages mapped by this mm to enforce a later COW,
916 * for instance during page table copying for fork().
918 seqcount_t write_protect_seq
;
920 spinlock_t arg_lock
; /* protect the below fields */
922 unsigned long start_code
, end_code
, start_data
, end_data
;
923 unsigned long start_brk
, brk
, start_stack
;
924 unsigned long arg_start
, arg_end
, env_start
, env_end
;
926 unsigned long saved_auxv
[AT_VECTOR_SIZE
]; /* for /proc/PID/auxv */
928 struct percpu_counter rss_stat
[NR_MM_COUNTERS
];
930 struct linux_binfmt
*binfmt
;
932 /* Architecture-specific MM context */
933 mm_context_t context
;
935 unsigned long flags
; /* Must use atomic bitops to access */
938 spinlock_t ioctx_lock
;
939 struct kioctx_table __rcu
*ioctx_table
;
943 * "owner" points to a task that is regarded as the canonical
944 * user/owner of this mm. All of the following must be true in
945 * order for it to be changed:
947 * current == mm->owner
949 * new_owner->mm == mm
950 * new_owner->alloc_lock is held
952 struct task_struct __rcu
*owner
;
954 struct user_namespace
*user_ns
;
956 /* store ref to file /proc/<pid>/exe symlink points to */
957 struct file __rcu
*exe_file
;
958 #ifdef CONFIG_MMU_NOTIFIER
959 struct mmu_notifier_subscriptions
*notifier_subscriptions
;
961 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !defined(CONFIG_SPLIT_PMD_PTLOCKS)
962 pgtable_t pmd_huge_pte
; /* protected by page_table_lock */
964 #ifdef CONFIG_NUMA_BALANCING
966 * numa_next_scan is the next time that PTEs will be remapped
967 * PROT_NONE to trigger NUMA hinting faults; such faults gather
968 * statistics and migrate pages to new nodes if necessary.
970 unsigned long numa_next_scan
;
972 /* Restart point for scanning and remapping PTEs. */
973 unsigned long numa_scan_offset
;
975 /* numa_scan_seq prevents two threads remapping PTEs. */
979 * An operation with batched TLB flushing is going on. Anything
980 * that can move process memory needs to flush the TLB when
981 * moving a PROT_NONE mapped page.
983 atomic_t tlb_flush_pending
;
984 #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
985 /* See flush_tlb_batched_pending() */
986 atomic_t tlb_flush_batched
;
988 struct uprobes_state uprobes_state
;
989 #ifdef CONFIG_PREEMPT_RT
990 struct rcu_head delayed_drop
;
992 #ifdef CONFIG_HUGETLB_PAGE
993 atomic_long_t hugetlb_usage
;
995 struct work_struct async_put_work
;
997 #ifdef CONFIG_IOMMU_MM_DATA
998 struct iommu_mm_data
*iommu_mm
;
1002 * Represent how many pages of this process are involved in KSM
1003 * merging (not including ksm_zero_pages).
1005 unsigned long ksm_merging_pages
;
1007 * Represent how many pages are checked for ksm merging
1008 * including merged and not merged.
1010 unsigned long ksm_rmap_items
;
1012 * Represent how many empty pages are merged with kernel zero
1013 * pages when enabling KSM use_zero_pages.
1015 atomic_long_t ksm_zero_pages
;
1016 #endif /* CONFIG_KSM */
1017 #ifdef CONFIG_LRU_GEN_WALKS_MMU
1019 /* this mm_struct is on lru_gen_mm_list */
1020 struct list_head list
;
1022 * Set when switching to this mm_struct, as a hint of
1023 * whether it has been used since the last time per-node
1024 * page table walkers cleared the corresponding bits.
1026 unsigned long bitmap
;
1028 /* points to the memcg of "owner" above */
1029 struct mem_cgroup
*memcg
;
1032 #endif /* CONFIG_LRU_GEN_WALKS_MMU */
1033 } __randomize_layout
;
1036 * The mm_cpumask needs to be at the end of mm_struct, because it
1037 * is dynamically sized based on nr_cpu_ids.
1039 unsigned long cpu_bitmap
[];
1042 #define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \
1044 extern struct mm_struct init_mm
;
1046 /* Pointer magic because the dynamic array size confuses some compilers. */
1047 static inline void mm_init_cpumask(struct mm_struct
*mm
)
1049 unsigned long cpu_bitmap
= (unsigned long)mm
;
1051 cpu_bitmap
+= offsetof(struct mm_struct
, cpu_bitmap
);
1052 cpumask_clear((struct cpumask
*)cpu_bitmap
);
1055 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
1056 static inline cpumask_t
*mm_cpumask(struct mm_struct
*mm
)
1058 return (struct cpumask
*)&mm
->cpu_bitmap
;
1061 #ifdef CONFIG_LRU_GEN
1063 struct lru_gen_mm_list
{
1064 /* mm_struct list for page table walkers */
1065 struct list_head fifo
;
1066 /* protects the list above */
1070 #endif /* CONFIG_LRU_GEN */
1072 #ifdef CONFIG_LRU_GEN_WALKS_MMU
1074 void lru_gen_add_mm(struct mm_struct
*mm
);
1075 void lru_gen_del_mm(struct mm_struct
*mm
);
1076 void lru_gen_migrate_mm(struct mm_struct
*mm
);
1078 static inline void lru_gen_init_mm(struct mm_struct
*mm
)
1080 INIT_LIST_HEAD(&mm
->lru_gen
.list
);
1081 mm
->lru_gen
.bitmap
= 0;
1083 mm
->lru_gen
.memcg
= NULL
;
1087 static inline void lru_gen_use_mm(struct mm_struct
*mm
)
1090 * When the bitmap is set, page reclaim knows this mm_struct has been
1091 * used since the last time it cleared the bitmap. So it might be worth
1092 * walking the page tables of this mm_struct to clear the accessed bit.
1094 WRITE_ONCE(mm
->lru_gen
.bitmap
, -1);
1097 #else /* !CONFIG_LRU_GEN_WALKS_MMU */
1099 static inline void lru_gen_add_mm(struct mm_struct
*mm
)
1103 static inline void lru_gen_del_mm(struct mm_struct
*mm
)
1107 static inline void lru_gen_migrate_mm(struct mm_struct
*mm
)
1111 static inline void lru_gen_init_mm(struct mm_struct
*mm
)
1115 static inline void lru_gen_use_mm(struct mm_struct
*mm
)
1119 #endif /* CONFIG_LRU_GEN_WALKS_MMU */
1121 struct vma_iterator
{
1122 struct ma_state mas
;
1125 #define VMA_ITERATOR(name, __mm, __addr) \
1126 struct vma_iterator name = { \
1128 .tree = &(__mm)->mm_mt, \
1131 .status = ma_start, \
1135 static inline void vma_iter_init(struct vma_iterator
*vmi
,
1136 struct mm_struct
*mm
, unsigned long addr
)
1138 mas_init(&vmi
->mas
, &mm
->mm_mt
, addr
);
1141 #ifdef CONFIG_SCHED_MM_CID
1144 MM_CID_UNSET
= -1U, /* Unset state has lazy_put flag set. */
1145 MM_CID_LAZY_PUT
= (1U << 31),
1148 static inline bool mm_cid_is_unset(int cid
)
1150 return cid
== MM_CID_UNSET
;
1153 static inline bool mm_cid_is_lazy_put(int cid
)
1155 return !mm_cid_is_unset(cid
) && (cid
& MM_CID_LAZY_PUT
);
1158 static inline bool mm_cid_is_valid(int cid
)
1160 return !(cid
& MM_CID_LAZY_PUT
);
1163 static inline int mm_cid_set_lazy_put(int cid
)
1165 return cid
| MM_CID_LAZY_PUT
;
1168 static inline int mm_cid_clear_lazy_put(int cid
)
1170 return cid
& ~MM_CID_LAZY_PUT
;
1173 /* Accessor for struct mm_struct's cidmask. */
1174 static inline cpumask_t
*mm_cidmask(struct mm_struct
*mm
)
1176 unsigned long cid_bitmap
= (unsigned long)mm
;
1178 cid_bitmap
+= offsetof(struct mm_struct
, cpu_bitmap
);
1179 /* Skip cpu_bitmap */
1180 cid_bitmap
+= cpumask_size();
1181 return (struct cpumask
*)cid_bitmap
;
1184 static inline void mm_init_cid(struct mm_struct
*mm
)
1188 for_each_possible_cpu(i
) {
1189 struct mm_cid
*pcpu_cid
= per_cpu_ptr(mm
->pcpu_cid
, i
);
1191 pcpu_cid
->cid
= MM_CID_UNSET
;
1194 cpumask_clear(mm_cidmask(mm
));
1197 static inline int mm_alloc_cid_noprof(struct mm_struct
*mm
)
1199 mm
->pcpu_cid
= alloc_percpu_noprof(struct mm_cid
);
1205 #define mm_alloc_cid(...) alloc_hooks(mm_alloc_cid_noprof(__VA_ARGS__))
1207 static inline void mm_destroy_cid(struct mm_struct
*mm
)
1209 free_percpu(mm
->pcpu_cid
);
1210 mm
->pcpu_cid
= NULL
;
1213 static inline unsigned int mm_cid_size(void)
1215 return cpumask_size();
1217 #else /* CONFIG_SCHED_MM_CID */
1218 static inline void mm_init_cid(struct mm_struct
*mm
) { }
1219 static inline int mm_alloc_cid(struct mm_struct
*mm
) { return 0; }
1220 static inline void mm_destroy_cid(struct mm_struct
*mm
) { }
1221 static inline unsigned int mm_cid_size(void)
1225 #endif /* CONFIG_SCHED_MM_CID */
1228 extern void tlb_gather_mmu(struct mmu_gather
*tlb
, struct mm_struct
*mm
);
1229 extern void tlb_gather_mmu_fullmm(struct mmu_gather
*tlb
, struct mm_struct
*mm
);
1230 extern void tlb_finish_mmu(struct mmu_gather
*tlb
);
1235 * typedef vm_fault_t - Return type for page fault handlers.
1237 * Page fault handlers return a bitmask of %VM_FAULT values.
1239 typedef __bitwise
unsigned int vm_fault_t
;
1242 * enum vm_fault_reason - Page fault handlers return a bitmask of
1243 * these values to tell the core VM what happened when handling the
1244 * fault. Used to decide whether a process gets delivered SIGBUS or
1245 * just gets major/minor fault counters bumped up.
1247 * @VM_FAULT_OOM: Out Of Memory
1248 * @VM_FAULT_SIGBUS: Bad access
1249 * @VM_FAULT_MAJOR: Page read from storage
1250 * @VM_FAULT_HWPOISON: Hit poisoned small page
1251 * @VM_FAULT_HWPOISON_LARGE: Hit poisoned large page. Index encoded
1253 * @VM_FAULT_SIGSEGV: segmentation fault
1254 * @VM_FAULT_NOPAGE: ->fault installed the pte, not return page
1255 * @VM_FAULT_LOCKED: ->fault locked the returned page
1256 * @VM_FAULT_RETRY: ->fault blocked, must retry
1257 * @VM_FAULT_FALLBACK: huge page fault failed, fall back to small
1258 * @VM_FAULT_DONE_COW: ->fault has fully handled COW
1259 * @VM_FAULT_NEEDDSYNC: ->fault did not modify page tables and needs
1260 * fsync() to complete (for synchronous page faults
1262 * @VM_FAULT_COMPLETED: ->fault completed, meanwhile mmap lock released
1263 * @VM_FAULT_HINDEX_MASK: mask HINDEX value
1266 enum vm_fault_reason
{
1267 VM_FAULT_OOM
= (__force vm_fault_t
)0x000001,
1268 VM_FAULT_SIGBUS
= (__force vm_fault_t
)0x000002,
1269 VM_FAULT_MAJOR
= (__force vm_fault_t
)0x000004,
1270 VM_FAULT_HWPOISON
= (__force vm_fault_t
)0x000010,
1271 VM_FAULT_HWPOISON_LARGE
= (__force vm_fault_t
)0x000020,
1272 VM_FAULT_SIGSEGV
= (__force vm_fault_t
)0x000040,
1273 VM_FAULT_NOPAGE
= (__force vm_fault_t
)0x000100,
1274 VM_FAULT_LOCKED
= (__force vm_fault_t
)0x000200,
1275 VM_FAULT_RETRY
= (__force vm_fault_t
)0x000400,
1276 VM_FAULT_FALLBACK
= (__force vm_fault_t
)0x000800,
1277 VM_FAULT_DONE_COW
= (__force vm_fault_t
)0x001000,
1278 VM_FAULT_NEEDDSYNC
= (__force vm_fault_t
)0x002000,
1279 VM_FAULT_COMPLETED
= (__force vm_fault_t
)0x004000,
1280 VM_FAULT_HINDEX_MASK
= (__force vm_fault_t
)0x0f0000,
1283 /* Encode hstate index for a hwpoisoned large page */
1284 #define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
1285 #define VM_FAULT_GET_HINDEX(x) (((__force unsigned int)(x) >> 16) & 0xf)
1287 #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | \
1288 VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON | \
1289 VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
1291 #define VM_FAULT_RESULT_TRACE \
1292 { VM_FAULT_OOM, "OOM" }, \
1293 { VM_FAULT_SIGBUS, "SIGBUS" }, \
1294 { VM_FAULT_MAJOR, "MAJOR" }, \
1295 { VM_FAULT_HWPOISON, "HWPOISON" }, \
1296 { VM_FAULT_HWPOISON_LARGE, "HWPOISON_LARGE" }, \
1297 { VM_FAULT_SIGSEGV, "SIGSEGV" }, \
1298 { VM_FAULT_NOPAGE, "NOPAGE" }, \
1299 { VM_FAULT_LOCKED, "LOCKED" }, \
1300 { VM_FAULT_RETRY, "RETRY" }, \
1301 { VM_FAULT_FALLBACK, "FALLBACK" }, \
1302 { VM_FAULT_DONE_COW, "DONE_COW" }, \
1303 { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }, \
1304 { VM_FAULT_COMPLETED, "COMPLETED" }
1306 struct vm_special_mapping
{
1307 const char *name
; /* The name, e.g. "[vdso]". */
1310 * If .fault is not provided, this points to a
1311 * NULL-terminated array of pages that back the special mapping.
1313 * This must not be NULL unless .fault is provided.
1315 struct page
**pages
;
1318 * If non-NULL, then this is called to resolve page faults
1319 * on the special mapping. If used, .pages is not checked.
1321 vm_fault_t (*fault
)(const struct vm_special_mapping
*sm
,
1322 struct vm_area_struct
*vma
,
1323 struct vm_fault
*vmf
);
1325 int (*mremap
)(const struct vm_special_mapping
*sm
,
1326 struct vm_area_struct
*new_vma
);
1328 void (*close
)(const struct vm_special_mapping
*sm
,
1329 struct vm_area_struct
*vma
);
1332 enum tlb_flush_reason
{
1333 TLB_FLUSH_ON_TASK_SWITCH
,
1334 TLB_REMOTE_SHOOTDOWN
,
1335 TLB_LOCAL_SHOOTDOWN
,
1336 TLB_LOCAL_MM_SHOOTDOWN
,
1337 TLB_REMOTE_SEND_IPI
,
1338 NR_TLB_FLUSH_REASONS
,
1342 * enum fault_flag - Fault flag definitions.
1343 * @FAULT_FLAG_WRITE: Fault was a write fault.
1344 * @FAULT_FLAG_MKWRITE: Fault was mkwrite of existing PTE.
1345 * @FAULT_FLAG_ALLOW_RETRY: Allow to retry the fault if blocked.
1346 * @FAULT_FLAG_RETRY_NOWAIT: Don't drop mmap_lock and wait when retrying.
1347 * @FAULT_FLAG_KILLABLE: The fault task is in SIGKILL killable region.
1348 * @FAULT_FLAG_TRIED: The fault has been tried once.
1349 * @FAULT_FLAG_USER: The fault originated in userspace.
1350 * @FAULT_FLAG_REMOTE: The fault is not for current task/mm.
1351 * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch.
1352 * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals.
1353 * @FAULT_FLAG_UNSHARE: The fault is an unsharing request to break COW in a
1354 * COW mapping, making sure that an exclusive anon page is
1355 * mapped after the fault.
1356 * @FAULT_FLAG_ORIG_PTE_VALID: whether the fault has vmf->orig_pte cached.
1357 * We should only access orig_pte if this flag set.
1358 * @FAULT_FLAG_VMA_LOCK: The fault is handled under VMA lock.
1360 * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify
1361 * whether we would allow page faults to retry by specifying these two
1362 * fault flags correctly. Currently there can be three legal combinations:
1364 * (a) ALLOW_RETRY and !TRIED: this means the page fault allows retry, and
1365 * this is the first try
1367 * (b) ALLOW_RETRY and TRIED: this means the page fault allows retry, and
1368 * we've already tried at least once
1370 * (c) !ALLOW_RETRY and !TRIED: this means the page fault does not allow retry
1372 * The unlisted combination (!ALLOW_RETRY && TRIED) is illegal and should never
1373 * be used. Note that page faults can be allowed to retry for multiple times,
1374 * in which case we'll have an initial fault with flags (a) then later on
1375 * continuous faults with flags (b). We should always try to detect pending
1376 * signals before a retry to make sure the continuous page faults can still be
1377 * interrupted if necessary.
1379 * The combination FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE is illegal.
1380 * FAULT_FLAG_UNSHARE is ignored and treated like an ordinary read fault when
1381 * applied to mappings that are not COW mappings.
1384 FAULT_FLAG_WRITE
= 1 << 0,
1385 FAULT_FLAG_MKWRITE
= 1 << 1,
1386 FAULT_FLAG_ALLOW_RETRY
= 1 << 2,
1387 FAULT_FLAG_RETRY_NOWAIT
= 1 << 3,
1388 FAULT_FLAG_KILLABLE
= 1 << 4,
1389 FAULT_FLAG_TRIED
= 1 << 5,
1390 FAULT_FLAG_USER
= 1 << 6,
1391 FAULT_FLAG_REMOTE
= 1 << 7,
1392 FAULT_FLAG_INSTRUCTION
= 1 << 8,
1393 FAULT_FLAG_INTERRUPTIBLE
= 1 << 9,
1394 FAULT_FLAG_UNSHARE
= 1 << 10,
1395 FAULT_FLAG_ORIG_PTE_VALID
= 1 << 11,
1396 FAULT_FLAG_VMA_LOCK
= 1 << 12,
1399 typedef unsigned int __bitwise zap_flags_t
;
1401 /* Flags for clear_young_dirty_ptes(). */
1402 typedef int __bitwise cydp_t
;
1404 /* Clear the access bit */
1405 #define CYDP_CLEAR_YOUNG ((__force cydp_t)BIT(0))
1407 /* Clear the dirty bit */
1408 #define CYDP_CLEAR_DIRTY ((__force cydp_t)BIT(1))
1411 * FOLL_PIN and FOLL_LONGTERM may be used in various combinations with each
1412 * other. Here is what they mean, and how to use them:
1415 * FIXME: For pages which are part of a filesystem, mappings are subject to the
1416 * lifetime enforced by the filesystem and we need guarantees that longterm
1417 * users like RDMA and V4L2 only establish mappings which coordinate usage with
1418 * the filesystem. Ideas for this coordination include revoking the longterm
1419 * pin, delaying writeback, bounce buffer page writeback, etc. As FS DAX was
1420 * added after the problem with filesystems was found FS DAX VMAs are
1421 * specifically failed. Filesystem pages are still subject to bugs and use of
1422 * FOLL_LONGTERM should be avoided on those pages.
1424 * In the CMA case: long term pins in a CMA region would unnecessarily fragment
1425 * that region. And so, CMA attempts to migrate the page before pinning, when
1426 * FOLL_LONGTERM is specified.
1428 * FOLL_PIN indicates that a special kind of tracking (not just page->_refcount,
1429 * but an additional pin counting system) will be invoked. This is intended for
1430 * anything that gets a page reference and then touches page data (for example,
1431 * Direct IO). This lets the filesystem know that some non-file-system entity is
1432 * potentially changing the pages' data. In contrast to FOLL_GET (whose pages
1433 * are released via put_page()), FOLL_PIN pages must be released, ultimately, by
1434 * a call to unpin_user_page().
1436 * FOLL_PIN is similar to FOLL_GET: both of these pin pages. They use different
1437 * and separate refcounting mechanisms, however, and that means that each has
1438 * its own acquire and release mechanisms:
1440 * FOLL_GET: get_user_pages*() to acquire, and put_page() to release.
1442 * FOLL_PIN: pin_user_pages*() to acquire, and unpin_user_pages to release.
1444 * FOLL_PIN and FOLL_GET are mutually exclusive for a given function call.
1445 * (The underlying pages may experience both FOLL_GET-based and FOLL_PIN-based
1446 * calls applied to them, and that's perfectly OK. This is a constraint on the
1447 * callers, not on the pages.)
1449 * FOLL_PIN should be set internally by the pin_user_pages*() APIs, never
1450 * directly by the caller. That's in order to help avoid mismatches when
1451 * releasing pages: get_user_pages*() pages must be released via put_page(),
1452 * while pin_user_pages*() pages must be released via unpin_user_page().
1454 * Please see Documentation/core-api/pin_user_pages.rst for more information.
1458 /* check pte is writable */
1459 FOLL_WRITE
= 1 << 0,
1460 /* do get_page on page */
1462 /* give error on hole if it would be zero */
1464 /* get_user_pages read/write w/o permission */
1465 FOLL_FORCE
= 1 << 3,
1467 * if a disk transfer is needed, start the IO and return without waiting
1470 FOLL_NOWAIT
= 1 << 4,
1471 /* do not fault in pages */
1472 FOLL_NOFAULT
= 1 << 5,
1473 /* check page is hwpoisoned */
1474 FOLL_HWPOISON
= 1 << 6,
1475 /* don't do file mappings */
1478 * FOLL_LONGTERM indicates that the page will be held for an indefinite
1479 * time period _often_ under userspace control. This is in contrast to
1480 * iov_iter_get_pages(), whose usages are transient.
1482 FOLL_LONGTERM
= 1 << 8,
1483 /* split huge pmd before returning */
1484 FOLL_SPLIT_PMD
= 1 << 9,
1485 /* allow returning PCI P2PDMA pages */
1486 FOLL_PCI_P2PDMA
= 1 << 10,
1487 /* allow interrupts from generic signals */
1488 FOLL_INTERRUPTIBLE
= 1 << 11,
1490 * Always honor (trigger) NUMA hinting faults.
1492 * FOLL_WRITE implicitly honors NUMA hinting faults because a
1493 * PROT_NONE-mapped page is not writable (exceptions with FOLL_FORCE
1494 * apply). get_user_pages_fast_only() always implicitly honors NUMA
1497 FOLL_HONOR_NUMA_FAULT
= 1 << 12,
1499 /* See also internal only FOLL flags in mm/internal.h */
1502 #endif /* _LINUX_MM_TYPES_H */