mm.h
来自「Linux Kernel 2.6.9 for OMAP1710」· C头文件 代码 · 共 799 行 · 第 1/2 页
H
799 行
#ifndef _LINUX_MM_H#define _LINUX_MM_H#include <linux/sched.h>#include <linux/errno.h>#ifdef __KERNEL__#include <linux/config.h>#include <linux/gfp.h>#include <linux/list.h>#include <linux/mmzone.h>#include <linux/rbtree.h>#include <linux/prio_tree.h>#include <linux/fs.h>struct mempolicy;struct anon_vma;#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 unsigned long vmalloc_earlyreserve;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>#include <asm/atomic.h>#ifndef MM_VM_SIZE#define MM_VM_SIZE(mm) TASK_SIZE#endif/* * 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). *//* * This struct defines a memory VMM memory area. There is one of these * per VM-area/task. A VM area is any part of the process virtual memory * space that has a special rule for the page-fault handlers (ie a shared * library, the executable area etc). */struct vm_area_struct { struct mm_struct * vm_mm; /* The address space we belong to. */ unsigned long vm_start; /* Our start address within vm_mm. */ unsigned long vm_end; /* The first byte after our end address within vm_mm. */ /* linked list of VM areas per task, sorted by address */ struct vm_area_struct *vm_next; pgprot_t vm_page_prot; /* Access permissions of this VMA. */ unsigned long vm_flags; /* Flags, listed below. */ struct rb_node vm_rb; /* * For areas with an address space and backing store, * linkage into the address_space->i_mmap prio tree, or * linkage to the list of like vmas hanging off its node, or * linkage of vma in the address_space->i_mmap_nonlinear list. */ union { struct { struct list_head list; void *parent; /* aligns with prio_tree_node parent */ struct vm_area_struct *head; } vm_set; struct prio_tree_node prio_tree_node; } shared; /* * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma * list, after a COW of one of the file pages. A MAP_SHARED vma * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack * or brk vma (with NULL file) can only be in an anon_vma list. */ struct list_head anon_vma_node; /* Serialized by anon_vma->lock */ struct anon_vma *anon_vma; /* Serialized by page_table_lock */ /* Function pointers to deal with this struct. */ struct vm_operations_struct * vm_ops; /* Information about our backing store: */ unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE units, *not* PAGE_CACHE_SIZE */ struct file * vm_file; /* File we map to (can be NULL). */ void * vm_private_data; /* was vm_pte (shared mem) */#ifdef CONFIG_NUMA struct mempolicy *vm_policy; /* NUMA policy for the VMA */#endif};/* * vm_flags.. */#define VM_READ 0x00000001 /* currently active flags */#define VM_WRITE 0x00000002#define VM_EXEC 0x00000004#define VM_SHARED 0x00000008#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_SHM 0x00000400 /* shared memory area, don't swap out */#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 /* Don't unmap it from swap_out */#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) */#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];/* * 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); struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type); int (*populate)(struct vm_area_struct * area, unsigned long address, unsigned long len, pgprot_t prot, unsigned long pgoff, int nonblock);#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);#endif};struct mmu_gather;struct inode;#ifdef ARCH_HAS_ATOMIC_UNSIGNEDtypedef unsigned page_flags_t;#elsetypedef unsigned long page_flags_t;#endif/* * Each physical page in the system has a struct page associated with * it to keep track of whatever it is we are using the page for at the * moment. Note that we have no way to track which tasks are using * a page. */struct page { page_flags_t flags; /* Atomic flags, some possibly * updated asynchronously */ atomic_t _count; /* Usage count, see below. */ atomic_t _mapcount; /* Count of ptes mapped in mms, * to show when page is mapped * & limit reverse map searches. */ unsigned long private; /* Mapping-private opaque data: * usually used for buffer_heads * if PagePrivate set; used for * swp_entry_t if PageSwapCache */ struct address_space *mapping; /* If low bit clear, points to * inode address_space, or NULL. * If page mapped as anonymous * memory, low bit is set, and * it points to anon_vma object: * see PAGE_MAPPING_ANON below. */ pgoff_t index; /* Our offset within mapping. */ struct list_head lru; /* Pageout list, eg. active_list * protected by zone->lru_lock ! */ /* * On machines where all RAM is mapped into kernel address space, * we can simply calculate the virtual address. On machines with * highmem some memory is mapped into kernel virtual memory * dynamically, so we need a place to store that address. * Note that this field could be 16 bits on x86 ... ;) * * Architectures with slow multiplication can define * WANT_PAGE_VIRTUAL in asm/page.h */#if defined(WANT_PAGE_VIRTUAL) void *virtual; /* Kernel virtual address (NULL if not kmapped, ie. highmem) */#endif /* WANT_PAGE_VIRTUAL */};/* * FIXME: take this include out, include page-flags.h in * files which need it (119 of them) */#include <linux/page-flags.h>/* * 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. * * Since 2.6.6 (approx), a free page has ->_count = -1. This is so that we * can use atomic_add_negative(-1, page->_count) to detect when the page * becomes free and so that we can also use atomic_inc_and_test to atomically * detect when we just tried to grab a ref on a page which some other CPU has * already deemed to be freeable. * * NO code should make assumptions about this internal detail! Use the provided * macros which retain the old rules: page_count(page) == 0 is a free page. *//* * Drop a ref, return true if the logical refcount fell to zero (the page has * no users) */#define put_page_testzero(p) \ ({ \ BUG_ON(page_count(p) == 0); \ atomic_add_negative(-1, &(p)->_count); \ })/* * Grab a ref, return true if the page previously had a logical refcount of * zero. ie: returns true if we just grabbed an already-deemed-to-be-free page */#define get_page_testone(p) atomic_inc_and_test(&(p)->_count)#define set_page_count(p,v) atomic_set(&(p)->_count, v - 1)#define __put_page(p) atomic_dec(&(p)->_count)extern void FASTCALL(__page_cache_release(struct page *));#ifdef CONFIG_HUGETLB_PAGEstatic inline int page_count(struct page *p){ if (PageCompound(p)) p = (struct page *)p->private; return atomic_read(&(p)->_count) + 1;}static inline void get_page(struct page *page){ if (unlikely(PageCompound(page))) page = (struct page *)page->private; atomic_inc(&page->_count);}void put_page(struct page *page);#else /* CONFIG_HUGETLB_PAGE */#define page_count(p) (atomic_read(&(p)->_count) + 1)static inline void get_page(struct page *page){ atomic_inc(&page->_count);}static inline void put_page(struct page *page){ if (!PageReserved(page) && put_page_testzero(page)) __page_cache_release(page);}#endif /* CONFIG_HUGETLB_PAGE *//* * 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_count() == 1 means the page is used for exactly one purpose * (e.g. a private data page of one process). * * A page may be used for kmalloc() or anyone else who does a * __get_free_page(). In this case the page_count() is at least 1, and * all other fields are unused but should be 0 or NULL. The * management of this page is the responsibility of the one who uses * it. * * The other pages (we may call them "process pages") are completely * managed by the Linux memory manager: I/O, buffers, swapping etc. * The following discussion applies only to them. * * 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. * * A 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. * * For pages belonging to inodes, the page_count() is the number of * attaches, plus 1 if `private' contains something, plus one for * the page cache itself. * * All pages belonging to an inode are in these doubly linked lists: * mapping->clean_pages, mapping->dirty_pages and mapping->locked_pages; * using the page->list list_head. These fields are also used for * freelist managemet (when page_count()==0). * * There is also a per-mapping radix tree mapping index to the page * in memory if present. The tree is rooted at mapping->root. * * All process pages can do 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 to disk, * - private pages 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. * We'll have up to (MAX_NUMNODES * MAX_NR_ZONES) zones total, * so we use (MAX_NODES_SHIFT + MAX_ZONES_SHIFT) here to get enough bits. */#define NODEZONE_SHIFT (sizeof(page_flags_t)*8 - MAX_NODES_SHIFT - MAX_ZONES_SHIFT)#define NODEZONE(node, zone) ((node << ZONES_SHIFT) | zone)static inline unsigned long page_zonenum(struct page *page){ return (page->flags >> NODEZONE_SHIFT) & (~(~0UL << ZONES_SHIFT));}static inline unsigned long page_to_nid(struct page *page){ return (page->flags >> (NODEZONE_SHIFT + ZONES_SHIFT));}struct zone;extern struct zone *zone_table[];static inline struct zone *page_zone(struct page *page){ return zone_table[page->flags >> NODEZONE_SHIFT];}static inline void set_page_zone(struct page *page, unsigned long nodezone_num){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?