mm.h
来自「linux 内核源代码」· C头文件 代码 · 共 1,162 行 · 第 1/3 页
H
1,162 行
#ifndef _LINUX_MM_H#define _LINUX_MM_H#include <linux/errno.h>#ifdef __KERNEL__#include <linux/gfp.h>#include <linux/list.h>#include <linux/mmzone.h>#include <linux/rbtree.h>#include <linux/prio_tree.h>#include <linux/debug_locks.h>#include <linux/mm_types.h>#include <linux/security.h>struct mempolicy;struct anon_vma;struct file_ra_state;struct user_struct;struct writeback_control;#ifndef CONFIG_DISCONTIGMEM /* Don't use mapnrs, do it properly */extern unsigned long max_mapnr;#endifextern unsigned long num_physpages;extern void * high_memory;extern int page_cluster;#ifdef CONFIG_SYSCTLextern int sysctl_legacy_va_layout;#else#define sysctl_legacy_va_layout 0#endif#include <asm/page.h>#include <asm/pgtable.h>#include <asm/processor.h>#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))/* * Linux kernel virtual memory manager primitives. * The idea being to have a "virtual" mm in the same way * we have a virtual fs - giving a cleaner interface to the * mm details, and allowing different kinds of memory mappings * (from shared memory to executable loading to arbitrary * mmap() functions). */extern struct kmem_cache *vm_area_cachep;/* * This struct defines the per-mm list of VMAs for uClinux. If CONFIG_MMU is * disabled, then there's a single shared list of VMAs maintained by the * system, and mm's subscribe to these individually */struct vm_list_struct { struct vm_list_struct *next; struct vm_area_struct *vma;};#ifndef CONFIG_MMUextern struct rb_root nommu_vma_tree;extern struct rw_semaphore nommu_vma_sem;extern unsigned int kobjsize(const void *objp);#endif/* * vm_flags.. */#define VM_READ 0x00000001 /* currently active flags */#define VM_WRITE 0x00000002#define VM_EXEC 0x00000004#define VM_SHARED 0x00000008/* mprotect() hardcodes VM_MAYREAD >> 4 == VM_READ, and so for r/w/x bits. */#define VM_MAYREAD 0x00000010 /* limits for mprotect() etc */#define VM_MAYWRITE 0x00000020#define VM_MAYEXEC 0x00000040#define VM_MAYSHARE 0x00000080#define VM_GROWSDOWN 0x00000100 /* general info on the segment */#define VM_GROWSUP 0x00000200#define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */#define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */#define VM_EXECUTABLE 0x00001000#define VM_LOCKED 0x00002000#define VM_IO 0x00004000 /* Memory mapped I/O or similar */ /* Used by sys_madvise() */#define VM_SEQ_READ 0x00008000 /* App will access data sequentially */#define VM_RAND_READ 0x00010000 /* App will not benefit from clustered reads */#define VM_DONTCOPY 0x00020000 /* Do not copy this vma on fork */#define VM_DONTEXPAND 0x00040000 /* Cannot expand with mremap() */#define VM_RESERVED 0x00080000 /* Count as reserved_vm like IO */#define VM_ACCOUNT 0x00100000 /* Is a VM accounted object */#define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */#define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */#define VM_MAPPED_COPY 0x01000000 /* T if mapped copy of data (nommu mmap) */#define VM_INSERTPAGE 0x02000000 /* The vma has had "vm_insert_page()" done on it */#define VM_ALWAYSDUMP 0x04000000 /* Always include in core dumps */#define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */#ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */#define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS#endif#ifdef CONFIG_STACK_GROWSUP#define VM_STACK_FLAGS (VM_GROWSUP | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)#else#define VM_STACK_FLAGS (VM_GROWSDOWN | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)#endif#define VM_READHINTMASK (VM_SEQ_READ | VM_RAND_READ)#define VM_ClearReadHint(v) (v)->vm_flags &= ~VM_READHINTMASK#define VM_NormalReadHint(v) (!((v)->vm_flags & VM_READHINTMASK))#define VM_SequentialReadHint(v) ((v)->vm_flags & VM_SEQ_READ)#define VM_RandomReadHint(v) ((v)->vm_flags & VM_RAND_READ)/* * mapping from the currently active vm_flags protection bits (the * low four bits) to a page protection mask.. */extern pgprot_t protection_map[16];#define FAULT_FLAG_WRITE 0x01 /* Fault was a write access */#define FAULT_FLAG_NONLINEAR 0x02 /* Fault was via a nonlinear mapping *//* * vm_fault is filled by the the pagefault handler and passed to the vma's * ->fault function. The vma's ->fault is responsible for returning a bitmask * of VM_FAULT_xxx flags that give details about how the fault was handled. * * pgoff should be used in favour of virtual_address, if possible. If pgoff * is used, one may set VM_CAN_NONLINEAR in the vma->vm_flags to get nonlinear * mapping support. */struct vm_fault { unsigned int flags; /* FAULT_FLAG_xxx flags */ pgoff_t pgoff; /* Logical page offset based on vma */ void __user *virtual_address; /* Faulting virtual address */ struct page *page; /* ->fault handlers should return a * page here, unless VM_FAULT_NOPAGE * is set (which is also implied by * VM_FAULT_ERROR). */};/* * These are the virtual MM functions - opening of an area, closing and * unmapping it (needed to keep files on disk up-to-date etc), pointer * to the functions called when a no-page or a wp-page exception occurs. */struct vm_operations_struct { void (*open)(struct vm_area_struct * area); void (*close)(struct vm_area_struct * area); int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf); struct page *(*nopage)(struct vm_area_struct *area, unsigned long address, int *type); unsigned long (*nopfn)(struct vm_area_struct *area, unsigned long address); /* notification that a previously read-only page is about to become * writable, if an error is returned it will cause a SIGBUS */ int (*page_mkwrite)(struct vm_area_struct *vma, struct page *page);#ifdef CONFIG_NUMA int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new); struct mempolicy *(*get_policy)(struct vm_area_struct *vma, unsigned long addr); int (*migrate)(struct vm_area_struct *vma, const nodemask_t *from, const nodemask_t *to, unsigned long flags);#endif};struct mmu_gather;struct inode;#define page_private(page) ((page)->private)#define set_page_private(page, v) ((page)->private = (v))/* * FIXME: take this include out, include page-flags.h in * files which need it (119 of them) */#include <linux/page-flags.h>#ifdef CONFIG_DEBUG_VM#define VM_BUG_ON(cond) BUG_ON(cond)#else#define VM_BUG_ON(condition) do { } while(0)#endif/* * Methods to modify the page usage count. * * What counts for a page usage: * - cache mapping (page->mapping) * - private data (page->private) * - page mapped in a task's page tables, each mapping * is counted separately * * Also, many kernel routines increase the page count before a critical * routine so they can be sure the page doesn't go away from under them. *//* * Drop a ref, return true if the refcount fell to zero (the page has no users) */static inline int put_page_testzero(struct page *page){ VM_BUG_ON(atomic_read(&page->_count) == 0); return atomic_dec_and_test(&page->_count);}/* * Try to grab a ref unless the page has a refcount of zero, return false if * that is the case. */static inline int get_page_unless_zero(struct page *page){ VM_BUG_ON(PageCompound(page)); return atomic_inc_not_zero(&page->_count);}static inline struct page *compound_head(struct page *page){ if (unlikely(PageTail(page))) return page->first_page; return page;}static inline int page_count(struct page *page){ return atomic_read(&compound_head(page)->_count);}static inline void get_page(struct page *page){ page = compound_head(page); VM_BUG_ON(atomic_read(&page->_count) == 0); atomic_inc(&page->_count);}static inline struct page *virt_to_head_page(const void *x){ struct page *page = virt_to_page(x); return compound_head(page);}/* * Setup the page count before being freed into the page allocator for * the first time (boot or memory hotplug) */static inline void init_page_count(struct page *page){ atomic_set(&page->_count, 1);}void put_page(struct page *page);void put_pages_list(struct list_head *pages);void split_page(struct page *page, unsigned int order);/* * Compound pages have a destructor function. Provide a * prototype for that function and accessor functions. * These are _only_ valid on the head of a PG_compound page. */typedef void compound_page_dtor(struct page *);static inline void set_compound_page_dtor(struct page *page, compound_page_dtor *dtor){ page[1].lru.next = (void *)dtor;}static inline compound_page_dtor *get_compound_page_dtor(struct page *page){ return (compound_page_dtor *)page[1].lru.next;}static inline int compound_order(struct page *page){ if (!PageHead(page)) return 0; return (unsigned long)page[1].lru.prev;}static inline void set_compound_order(struct page *page, unsigned long order){ page[1].lru.prev = (void *)order;}/* * Multiple processes may "see" the same page. E.g. for untouched * mappings of /dev/null, all processes see the same page full of * zeroes, and text pages of executables and shared libraries have * only one copy in memory, at most, normally. * * For the non-reserved pages, page_count(page) denotes a reference count. * page_count() == 0 means the page is free. page->lru is then used for * freelist management in the buddy allocator. * page_count() > 0 means the page has been allocated. * * Pages are allocated by the slab allocator in order to provide memory * to kmalloc and kmem_cache_alloc. In this case, the management of the * page, and the fields in 'struct page' are the responsibility of mm/slab.c * unless a particular usage is carefully commented. (the responsibility of * freeing the kmalloc memory is the caller's, of course). * * A page may be used by anyone else who does a __get_free_page(). * In this case, page_count still tracks the references, and should only * be used through the normal accessor functions. The top bits of page->flags * and page->virtual store page management information, but all other fields * are unused and could be used privately, carefully. The management of this * page is the responsibility of the one who allocated it, and those who have * subsequently been given references to it. * * The other pages (we may call them "pagecache pages") are completely * managed by the Linux memory manager: I/O, buffers, swapping etc. * The following discussion applies only to them. * * A pagecache page contains an opaque `private' member, which belongs to the * page's address_space. Usually, this is the address of a circular list of * the page's disk buffers. PG_private must be set to tell the VM to call * into the filesystem to release these pages. * * A page may belong to an inode's memory mapping. In this case, page->mapping * is the pointer to the inode, and page->index is the file offset of the page, * in units of PAGE_CACHE_SIZE. * * If pagecache pages are not associated with an inode, they are said to be * anonymous pages. These may become associated with the swapcache, and in that * case PG_swapcache is set, and page->private is an offset into the swapcache. * * In either case (swapcache or inode backed), the pagecache itself holds one * reference to the page. Setting PG_private should also increment the * refcount. The each user mapping also has a reference to the page. * * The pagecache pages are stored in a per-mapping radix tree, which is * rooted at mapping->page_tree, and indexed by offset. * Where 2.4 and early 2.6 kernels kept dirty/clean pages in per-address_space * lists, we instead now tag pages as dirty/writeback in the radix tree. * * All pagecache pages may be subject to I/O: * - inode pages may need to be read from disk, * - inode pages which have been modified and are MAP_SHARED may need * to be written back to the inode on disk, * - anonymous pages (including MAP_PRIVATE file mappings) which have been * modified may need to be swapped out to swap space and (later) to be read * back into memory. *//* * The zone field is never updated after free_area_init_core() * sets it, so none of the operations on it need to be atomic. *//* * page->flags layout: * * There are three possibilities for how page->flags get * laid out. The first is for the normal case, without * sparsemem. The second is for sparsemem when there is * plenty of space for node and section. The last is when * we have run out of space and have to fall back to an * alternate (slower) way of determining the node. * * No sparsemem: | NODE | ZONE | ... | FLAGS | * with space for node: | SECTION | NODE | ZONE | ... | FLAGS | * no space for node: | SECTION | ZONE | ... | FLAGS | */#ifdef CONFIG_SPARSEMEM#define SECTIONS_WIDTH SECTIONS_SHIFT#else#define SECTIONS_WIDTH 0#endif#define ZONES_WIDTH ZONES_SHIFT
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?