PageCache writeback
出自DebianWiki
目錄 |
[編輯] Chapter 14 The Page Cache and Page Writeback
Linux Kernel Study Group, Taiwan by Shounan Chiou: snchiou@nanya.edu.tw, frank.chiou@msa.hinet.net
[編輯] 1 introduction
(refer to chap 12, and chap 10, chap 16)
- buffer : map one block to memory
- sector : the smallest addressable unit to the device
- block : the smallest addressable unit to the filesystem
- page : basic unit of the memory management
- page cache: a cache of pages
[編輯] 2 page cache
- Prior to a page I/O operations, the kernel checks if the data resides in the page cache. if yes, the kernel can quickly return the requested page.
- Linux page cache use struct address_space to identify pages in the page cache.
- Among the fileds in the above struct,
- clean_pages contains all the page descriptors associated with this address_space that are neither dirty nor locked.
- dirty_pages contains all the page descriptors associated with this address_space that its in-memory page has been updated, but not written back to disk yet, also not locked.
- locked_pages caontains all the page descriptors associated with this address_space that it currently undergoing disk I/O.
- a_ops fields points to the operations table.
- struct address_space_operations:
- read operation with (* readpage())
- write operation with (* writepage())
- Radix tree
- page existence check in the oage cache must be quick enough. address_space object use radix tree stored page_tree to make very quick searching with radix_tree_lookup().
- Before v2.6 kernel, hash table was used to search page instead of radix tree.
[編輯] 3 Buffer Cache
- history traceback:
- In v 2.2 kernel, there were 2 caches:page cache, and buffer cache.
- Today, we have only one disk cache--the page cache. The *assoc_mapping field in the struct address_space describe the associated buffers.
[編輯] 4 Page Writeback
- pdflush daemon
- dirty page write back occures in 2 situations:
- When free memory shrinks below a theshold, the kernel write dirty data back to disk to release memory.
- When dirty data grows older than a theshold, the kernel write dirty data back to disk to avoid dirty data remain in memory indefinitely.
- Congestion Avoidance:
- bdflush consisted of only one thread which led to possible congestion.
- pdflush introduces multithreaded with MAX_PDFLUSH_THREADS and MIN_PDFLUSH_THREADS. Each thread flushs dirty pages to disk individually allowing concontrate on different device queues.
![[Main Page]](/upload/4/49/Debian_taiwan_out.png)