📄 mm.h
字号:
#ifndef _LINUX_MM_H#define _LINUX_MM_H#include <linux/sched.h>#include <linux/errno.h>#ifdef __KERNEL__#include <linux/config.h>#include <linux/string.h>#include <linux/list.h>#include <linux/mmzone.h>#include <linux/swap.h>#include <linux/rbtree.h>extern unsigned long max_mapnr;extern unsigned long num_physpages;extern unsigned long num_mappedpages;extern void * high_memory;extern int page_cluster;/* The inactive_clean lists are per zone. */extern struct list_head active_list;extern struct list_head inactive_list;#include <asm/page.h>#include <asm/pgtable.h>#include <asm/atomic.h>#include <asm/mmu.h>/* * 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. */ rb_node_t vm_rb; /* * For areas with an address space and backing store, * one of the address_space->i_mmap{,shared} lists, * for shm areas, the list of attaches, otherwise unused. */ struct vm_area_struct *vm_next_share; struct vm_area_struct **vm_pprev_share; /* 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). */ unsigned long vm_raend; /* XXX: put full readahead info here. */ void * vm_private_data; /* was vm_pte (shared mem) */};/* * 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_XIP 0x00200000#define VM_STACK_FLAGS (0x00000177 | VM_ACCOUNT)#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)/* read ahead limits */extern int vm_min_readahead;extern int vm_max_readahead;/* * 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 ZPR_MAX_BYTES 256*PAGE_SIZE#define ZPR_NORMAL 0 /* perform zap_page_range request in one walk */#define ZPR_PARTITION 1 /* partition into a series of smaller operations *//* * 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 unused);};/* * 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. * * Try to keep the most commonly accessed fields in single cache lines * here (16 bytes or greater). This ordering should be particularly * beneficial on 32-bit processors. * * The first line is data used in page cache lookup, the second line * is used for linear searches (eg. clock algorithm scans). * * TODO: make this structure smaller, it could be as small as 32 bytes. */typedef struct page { struct list_head list; /* ->mapping has some page lists. */ struct address_space *mapping; /* The inode (or ...) we belong to. */ unsigned long index; /* Our offset within mapping. */ struct page *next_hash; /* Next page sharing our hash bucket in the pagecache hash table. */ atomic_t count; /* Usage count, see below. */ unsigned long flags; /* atomic flags, some possibly updated asynchronously */ struct list_head lru; /* Pageout list, eg. active_list; protected by pagemap_lru_lock !! */ struct page **pprev_hash; /* Complement to *next_hash. */ struct buffer_head * buffers; /* Buffer maps us to a disk block. */ /* * 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(CONFIG_HIGHMEM) || defined(WANT_PAGE_VIRTUAL) void *virtual; /* Kernel virtual address (NULL if not kmapped, ie. highmem) */#endif /* CONFIG_HIGMEM || WANT_PAGE_VIRTUAL */} mem_map_t;/* * Methods to modify the page usage count. * * What counts for a page usage: * - cache mapping (page->mapping) * - disk mapping (page->buffers) * - 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. */#define get_page(p) atomic_inc(&(p)->count)#define put_page(p) __free_page(p)#define put_page_testzero(p) atomic_dec_and_test(&(p)->count)#define page_count(p) atomic_read(&(p)->count)#define set_page_count(p,v) atomic_set(&(p)->count, v)/* * Various page->flags bits: * * PG_reserved is set for special pages, which can never be swapped * out. Some of them might not even exist (eg empty_bad_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 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 may have buffers allocated to it. In this case, * page->buffers is a circular list of these buffer heads. Else, * page->buffers == NULL. * * For pages belonging to inodes, the page->count is the number of * attaches, plus 1 if buffers are allocated to the page, 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 hash table mapping (mapping,index) to the page * in memory if present. The lists for this hash table use the fields * page->next_hash and page->pprev_hash. * * 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. * During disk I/O, PG_locked is used. This bit is set before I/O * and reset when I/O completes. page_waitqueue(page) is a wait queue of all * tasks waiting for the I/O on this page to complete. * PG_uptodate tells whether the page's contents is valid. * When a read completes, the page becomes uptodate, unless a disk I/O * error happened. * * For choosing which pages to swap out, inode pages carry a * PG_referenced bit, which is set any time the system accesses * that page through the (mapping,index) hash table. This referenced * bit, together with the referenced bit in the page tables, is used * to manipulate page->age and move the page across the active, * inactive_dirty and inactive_clean lists. * * Note that the referenced bit, the page->lru list_head and the * active, inactive_dirty and inactive_clean lists are protected by * the pagemap_lru_lock, and *NOT* by the usual PG_locked bit! * * PG_skip is used on sparc/sparc64 architectures to "skip" certain * parts of the address space. * * PG_error is set to indicate that an I/O error occurred on this page. * * PG_arch_1 is an architecture specific page state bit. The generic * code guarantees that this bit is cleared for a page when it first * is entered into the page cache. * * PG_highmem pages are not permanently mapped into the kernel virtual * address space, they need to be kmapped separately for doing IO on * the pages. The struct page (these bits with information) are always * mapped into kernel address space... */#define PG_locked 0 /* Page is locked. Don't touch. */#define PG_error 1#define PG_referenced 2#define PG_uptodate 3#define PG_dirty 4#define PG_unused 5#define PG_lru 6#define PG_active 7#define PG_slab 8#define PG_skip 10#define PG_highmem 11#define PG_checked 12 /* kill me in 2.5.<early>. */#define PG_arch_1 13#define PG_reserved 14#define PG_launder 15 /* written out by VM pressure.. *//* Make it prettier to test the above... */#define UnlockPage(page) unlock_page(page)#define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)#define SetPageUptodate(page) set_bit(PG_uptodate, &(page)->flags)#define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags)#define PageDirty(page) test_bit(PG_dirty, &(page)->flags)#define SetPageDirty(page) set_bit(PG_dirty, &(page)->flags)#define ClearPageDirty(page) clear_bit(PG_dirty, &(page)->flags)#define PageLocked(page) test_bit(PG_locked, &(page)->flags)#define LockPage(page) set_bit(PG_locked, &(page)->flags)#define TryLockPage(page) test_and_set_bit(PG_locked, &(page)->flags)#define PageChecked(page) test_bit(PG_checked, &(page)->flags)#define SetPageChecked(page) set_bit(PG_checked, &(page)->flags)#define PageLaunder(page) test_bit(PG_launder, &(page)->flags)#define SetPageLaunder(page) set_bit(PG_launder, &(page)->flags)#define ClearPageLaunder(page) clear_bit(PG_launder, &(page)->flags)#define DelallocPage(page) ((page)->buffers && test_bit(BH_Delay, &(page)->buffers->b_state))/* * The zone field is never updated after free_area_init_core() * sets it, so none of the operations on it need to be atomic. */#define NODE_SHIFT 4#define ZONE_SHIFT (BITS_PER_LONG - 8)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -