1. The state transition relationship of Page_attrs
Previously said, bitmap optimization core is: Bitmap set after the batch write; bitmap delay cleanup. Write bit with bitmap_statrwrite () + bitmap_unplug () two functions, to Achieve the bitmap set after the batch write; Bitmap_endwrite () + Two-wheel bitmap_deamon_work () enables bitmap delay cleanup.
2. An example analysis
The following is a write request instance for analysis. Assuming that the previous chunk data are consistent, or to write 3*4096*8 (3 page) chunk data, the entire disk array only 1 write requests, the analysis example is as follows 5 steps:
1. RAID1 make_request () receives this write request, executes Bitmap_startwrite (), and then activates the daemon after the write bio is hung on the pending_list. Bitmap_startwrite () Set Bitmap File of this 3 a page the page property is Bitmap_page_dirty, each bit corresponds to the *BMC set to 2, immediately *bmc++, at this time these *BMC = 3.
2. After activating the daemon, execute bitmap_unplug ()and traverse all the page of the bitmap file cache before the daemon sends a write request, because only these 3 page properties are bitmap_page_dirty. So just manipulate these 3 page. In page, swipe the 3 - page bit to disk Bitmap file, clears page Property bitmap_page_dirtyfor each page. wait bit after the brush disk is completely finished, write Bio issued .
3, when the last write bio successful callback, execute bitmap_endwrite (), for the 3 page corresponding to each bit of *BMC decrement, at this time these *BMC = 2. will be 3 a page the page property is set to Bitmap_page_clean.
4. When the daemon executes, call bitmap_daemon_work ()and traverse the entire bitmap file cache. Set the *bmc for each bit of the 3 page to 1, and then add bitmap_page_needwrite to the 3 page. Page Properties .
5. When the daemon executes again, call bitmap_daemon_work ()again to traverse the entire bitmap file cache. For these 3 page properties bitmap_page_clean cleared , the corresponding *BMC for each bit is set to 0,bit Clear 0 , 3 page Properties bitmap_page_ needwrite erase , BITMAP to disk for 3-page bit .
Reprint Please specify source: http://www.cnblogs.com/fangpei/
Bitmap source code Analysis in MD--state machine instance