[Linux Memory] page cache and block caching __linux

Source: Internet
Author: User
1, the kernel provides two common caching scenarios for the device:
A, page caching (pages cache)
B, Block caching


2, the kernel manages the data structure used by the page cache
The kernel manages page caching through the cardinality tree (radix),


3, how the kernel writes back the modified data in memory to the physical device
A, the kernel daemon runs in the background, and for Pdflush, these daemons are periodically activated,
b, the second mode of operation of Pdflush is that if the number of data items modified in the cache increases significantly in the short term, the kernel activates the Pdflush.
C, the kernel provides related system calls, such as sync ()



4, the concept of address space
Pages in the page cache are associated with physical device memory (such as the struct inode structure of the underlying file system) through the address space (Address_space). The struct address_space *mapping member corresponding to the page structure.
(1) If page->mapping equals 0, the page belongs to the swap tell cache swap
(2) If the page->mapping is not equal to 0, but the No. 0 digit is 0, it indicates that the page is anonymous also, at this point the mapping points to a struct ANON_VMA structure variable;
(3) If the page->mapping is not equal to 0, but the No. 0 digit is not 0, then the apping points to a struct address_space address space structure variable;

struct Address_space {struct inode *host;       /* Have node * * struct radix_tree_root page_tree;       /* contains all the pages of the radix tree * * spinlock_t tree_lock;  /* Protect Page_tree spin lock/unsigned int i_mmap_writable;          /* vm_shared Count * * struct prio_tree_root i_mmap; /* Private Mapping list * * struct list_head i_mmap_nonlinear;      /* vm_nonlinear Linked list */spinlock_t i_mmap_lock;   * * Protection I_mmap spin lock/atomic_t Truncate_count;          /* Truncation count */unsigned long nrpages;  * * Total page/pgoff_t writeback_index;     /* Write back the starting offset/struct address_space_operations *a_ops;           /* Operation Table * * unsigned long flags;    /* Gfp_mask Mask and error identification */struct backing_dev_info *backing_dev_info;     /* Pre-read information * * spinlock_t private_lock;    * * Private address_space lock/struct list_head private_list;    /* Private address_space linked list */struct ADDRESS_SPACE     *assoc_mapping; /* Related buffers/*

};
For example, when the owner of the page cache is a file, the I_mapping field of the index node always points to the address_space of the data page owner of the index node. The Address_space object is embedded in the i_ of the VFS index node object The data field. The field host in Address_space points to the Index node object of its owner.



5, the common operation function of page cache

There are several common processing functions for page caching: Find pages, add pages, and delete page update pages.

struct page * find_get_page (struct address_space *mapping, unsigned long offset)
unsigned find_get_pages (struct Address_space *mapping, pgoff_t start,unsigned int nr_pages, struct page **pages)
struct page *find_lock_page (struct Address_space *mapping,unsigned long offset)
struct page *find_trylock_page (struct address_space, unsigned long offset)
struct page *find_or_create_page (struct address_space *mapping,unsigned long index, unsigned int gfp_mask)
int add_to_page_cache (struct page *page, struct address_space *mapping,pgoff_t offset, int gfp_mask) C5/>remove_from_page_cache (struct page *page)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.