page-writeback.c (82ffd0454bd9bd57780966d47bfd56d579dd4fb3) | page-writeback.c (a862f68a8b360086f248cbc3606029441b5f5197) |
---|---|
1/* 2 * mm/page-writeback.c 3 * 4 * Copyright (C) 2002, Linus Torvalds. 5 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra 6 * 7 * Contains functions related to writing back dirty pages at the 8 * address_space level. --- 256 unchanged lines hidden (view full) --- 265 * require translating the configured limit into a percentage of 266 * global dirtyable memory first. 267 */ 268 269/** 270 * node_dirtyable_memory - number of dirtyable pages in a node 271 * @pgdat: the node 272 * | 1/* 2 * mm/page-writeback.c 3 * 4 * Copyright (C) 2002, Linus Torvalds. 5 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra 6 * 7 * Contains functions related to writing back dirty pages at the 8 * address_space level. --- 256 unchanged lines hidden (view full) --- 265 * require translating the configured limit into a percentage of 266 * global dirtyable memory first. 267 */ 268 269/** 270 * node_dirtyable_memory - number of dirtyable pages in a node 271 * @pgdat: the node 272 * |
273 * Returns the node's number of pages potentially available for dirty | 273 * Return: the node's number of pages potentially available for dirty |
274 * page cache. This is the base value for the per-node dirty limits. 275 */ 276static unsigned long node_dirtyable_memory(struct pglist_data *pgdat) 277{ 278 unsigned long nr_pages = 0; 279 int z; 280 281 for (z = 0; z < MAX_NR_ZONES; z++) { --- 68 unchanged lines hidden (view full) --- 350#else 351 return 0; 352#endif 353} 354 355/** 356 * global_dirtyable_memory - number of globally dirtyable pages 357 * | 274 * page cache. This is the base value for the per-node dirty limits. 275 */ 276static unsigned long node_dirtyable_memory(struct pglist_data *pgdat) 277{ 278 unsigned long nr_pages = 0; 279 int z; 280 281 for (z = 0; z < MAX_NR_ZONES; z++) { --- 68 unchanged lines hidden (view full) --- 350#else 351 return 0; 352#endif 353} 354 355/** 356 * global_dirtyable_memory - number of globally dirtyable pages 357 * |
358 * Returns the global number of pages potentially available for dirty | 358 * Return: the global number of pages potentially available for dirty |
359 * page cache. This is the base value for the global dirty limits. 360 */ 361static unsigned long global_dirtyable_memory(void) 362{ 363 unsigned long x; 364 365 x = global_zone_page_state(NR_FREE_PAGES); 366 /* --- 98 unchanged lines hidden (view full) --- 465 *pbackground = gdtc.bg_thresh; 466 *pdirty = gdtc.thresh; 467} 468 469/** 470 * node_dirty_limit - maximum number of dirty pages allowed in a node 471 * @pgdat: the node 472 * | 359 * page cache. This is the base value for the global dirty limits. 360 */ 361static unsigned long global_dirtyable_memory(void) 362{ 363 unsigned long x; 364 365 x = global_zone_page_state(NR_FREE_PAGES); 366 /* --- 98 unchanged lines hidden (view full) --- 465 *pbackground = gdtc.bg_thresh; 466 *pdirty = gdtc.thresh; 467} 468 469/** 470 * node_dirty_limit - maximum number of dirty pages allowed in a node 471 * @pgdat: the node 472 * |
473 * Returns the maximum number of dirty pages allowed in a node, based | 473 * Return: the maximum number of dirty pages allowed in a node, based |
474 * on the node's dirtyable memory. 475 */ 476static unsigned long node_dirty_limit(struct pglist_data *pgdat) 477{ 478 unsigned long node_memory = node_dirtyable_memory(pgdat); 479 struct task_struct *tsk = current; 480 unsigned long dirty; 481 --- 8 unchanged lines hidden (view full) --- 490 491 return dirty; 492} 493 494/** 495 * node_dirty_ok - tells whether a node is within its dirty limits 496 * @pgdat: the node to check 497 * | 474 * on the node's dirtyable memory. 475 */ 476static unsigned long node_dirty_limit(struct pglist_data *pgdat) 477{ 478 unsigned long node_memory = node_dirtyable_memory(pgdat); 479 struct task_struct *tsk = current; 480 unsigned long dirty; 481 --- 8 unchanged lines hidden (view full) --- 490 491 return dirty; 492} 493 494/** 495 * node_dirty_ok - tells whether a node is within its dirty limits 496 * @pgdat: the node to check 497 * |
498 * Returns %true when the dirty pages in @pgdat are within the node's | 498 * Return: %true when the dirty pages in @pgdat are within the node's |
499 * dirty limit, %false if the limit is exceeded. 500 */ 501bool node_dirty_ok(struct pglist_data *pgdat) 502{ 503 unsigned long limit = node_dirty_limit(pgdat); 504 unsigned long nr_pages = 0; 505 506 nr_pages += node_page_state(pgdat, NR_FILE_DIRTY); --- 231 unchanged lines hidden (view full) --- 738 739 mdtc->avail = filepages + min(headroom, other_clean); 740} 741 742/** 743 * __wb_calc_thresh - @wb's share of dirty throttling threshold 744 * @dtc: dirty_throttle_context of interest 745 * | 499 * dirty limit, %false if the limit is exceeded. 500 */ 501bool node_dirty_ok(struct pglist_data *pgdat) 502{ 503 unsigned long limit = node_dirty_limit(pgdat); 504 unsigned long nr_pages = 0; 505 506 nr_pages += node_page_state(pgdat, NR_FILE_DIRTY); --- 231 unchanged lines hidden (view full) --- 738 739 mdtc->avail = filepages + min(headroom, other_clean); 740} 741 742/** 743 * __wb_calc_thresh - @wb's share of dirty throttling threshold 744 * @dtc: dirty_throttle_context of interest 745 * |
746 * Returns @wb's dirty limit in pages. The term "dirty" in the context of 747 * dirty balancing includes all PG_dirty, PG_writeback and NFS unstable pages. 748 * | |
749 * Note that balance_dirty_pages() will only seriously take it as a hard limit 750 * when sleeping max_pause per page is not enough to keep the dirty pages under 751 * control. For example, when the device is completely stalled due to some error 752 * conditions, or when there are 1000 dd tasks writing to a slow 10MB/s USB key. 753 * In the other normal situations, it acts more gently by throttling the tasks 754 * more (rather than completely block them) when the wb dirty pages go high. 755 * 756 * It allocates high/low dirty limits to fast/slow devices, in order to prevent 757 * - starving fast devices 758 * - piling up dirty pages (that will take long time to sync) on slow devices 759 * 760 * The wb's share of dirty limit will be adapting to its throughput and 761 * bounded by the bdi->min_ratio and/or bdi->max_ratio parameters, if set. | 746 * Note that balance_dirty_pages() will only seriously take it as a hard limit 747 * when sleeping max_pause per page is not enough to keep the dirty pages under 748 * control. For example, when the device is completely stalled due to some error 749 * conditions, or when there are 1000 dd tasks writing to a slow 10MB/s USB key. 750 * In the other normal situations, it acts more gently by throttling the tasks 751 * more (rather than completely block them) when the wb dirty pages go high. 752 * 753 * It allocates high/low dirty limits to fast/slow devices, in order to prevent 754 * - starving fast devices 755 * - piling up dirty pages (that will take long time to sync) on slow devices 756 * 757 * The wb's share of dirty limit will be adapting to its throughput and 758 * bounded by the bdi->min_ratio and/or bdi->max_ratio parameters, if set. |
759 * 760 * Return: @wb's dirty limit in pages. The term "dirty" in the context of 761 * dirty balancing includes all PG_dirty, PG_writeback and NFS unstable pages. |
|
762 */ 763static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc) 764{ 765 struct wb_domain *dom = dtc_dom(dtc); 766 unsigned long thresh = dtc->thresh; 767 u64 wb_thresh; 768 long numerator, denominator; 769 unsigned long wb_min_ratio, wb_max_ratio; --- 1143 unchanged lines hidden (view full) --- 1913} 1914EXPORT_SYMBOL(balance_dirty_pages_ratelimited); 1915 1916/** 1917 * wb_over_bg_thresh - does @wb need to be written back? 1918 * @wb: bdi_writeback of interest 1919 * 1920 * Determines whether background writeback should keep writing @wb or it's | 762 */ 763static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc) 764{ 765 struct wb_domain *dom = dtc_dom(dtc); 766 unsigned long thresh = dtc->thresh; 767 u64 wb_thresh; 768 long numerator, denominator; 769 unsigned long wb_min_ratio, wb_max_ratio; --- 1143 unchanged lines hidden (view full) --- 1913} 1914EXPORT_SYMBOL(balance_dirty_pages_ratelimited); 1915 1916/** 1917 * wb_over_bg_thresh - does @wb need to be written back? 1918 * @wb: bdi_writeback of interest 1919 * 1920 * Determines whether background writeback should keep writing @wb or it's |
1921 * clean enough. Returns %true if writeback should continue. | 1921 * clean enough. 1922 * 1923 * Return: %true if writeback should continue. |
1922 */ 1923bool wb_over_bg_thresh(struct bdi_writeback *wb) 1924{ 1925 struct dirty_throttle_control gdtc_stor = { GDTC_INIT(wb) }; 1926 struct dirty_throttle_control mdtc_stor = { MDTC_INIT(wb, &gdtc_stor) }; 1927 struct dirty_throttle_control * const gdtc = &gdtc_stor; 1928 struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ? 1929 &mdtc_stor : NULL; --- 212 unchanged lines hidden (view full) --- 2142 * by the process clearing the DIRTY tag (and submitting the page for IO). 2143 * 2144 * To avoid deadlocks between range_cyclic writeback and callers that hold 2145 * pages in PageWriteback to aggregate IO until write_cache_pages() returns, 2146 * we do not loop back to the start of the file. Doing so causes a page 2147 * lock/page writeback access order inversion - we should only ever lock 2148 * multiple pages in ascending page->index order, and looping back to the start 2149 * of the file violates that rule and causes deadlocks. | 1924 */ 1925bool wb_over_bg_thresh(struct bdi_writeback *wb) 1926{ 1927 struct dirty_throttle_control gdtc_stor = { GDTC_INIT(wb) }; 1928 struct dirty_throttle_control mdtc_stor = { MDTC_INIT(wb, &gdtc_stor) }; 1929 struct dirty_throttle_control * const gdtc = &gdtc_stor; 1930 struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ? 1931 &mdtc_stor : NULL; --- 212 unchanged lines hidden (view full) --- 2144 * by the process clearing the DIRTY tag (and submitting the page for IO). 2145 * 2146 * To avoid deadlocks between range_cyclic writeback and callers that hold 2147 * pages in PageWriteback to aggregate IO until write_cache_pages() returns, 2148 * we do not loop back to the start of the file. Doing so causes a page 2149 * lock/page writeback access order inversion - we should only ever lock 2150 * multiple pages in ascending page->index order, and looping back to the start 2151 * of the file violates that rule and causes deadlocks. |
2152 * 2153 * Return: %0 on success, negative error code otherwise |
|
2150 */ 2151int write_cache_pages(struct address_space *mapping, 2152 struct writeback_control *wbc, writepage_t writepage, 2153 void *data) 2154{ 2155 int ret = 0; 2156 int done = 0; 2157 int error; --- 142 unchanged lines hidden (view full) --- 2300 2301/** 2302 * generic_writepages - walk the list of dirty pages of the given address space and writepage() all of them. 2303 * @mapping: address space structure to write 2304 * @wbc: subtract the number of written pages from *@wbc->nr_to_write 2305 * 2306 * This is a library function, which implements the writepages() 2307 * address_space_operation. | 2154 */ 2155int write_cache_pages(struct address_space *mapping, 2156 struct writeback_control *wbc, writepage_t writepage, 2157 void *data) 2158{ 2159 int ret = 0; 2160 int done = 0; 2161 int error; --- 142 unchanged lines hidden (view full) --- 2304 2305/** 2306 * generic_writepages - walk the list of dirty pages of the given address space and writepage() all of them. 2307 * @mapping: address space structure to write 2308 * @wbc: subtract the number of written pages from *@wbc->nr_to_write 2309 * 2310 * This is a library function, which implements the writepages() 2311 * address_space_operation. |
2312 * 2313 * Return: %0 on success, negative error code otherwise |
|
2308 */ 2309int generic_writepages(struct address_space *mapping, 2310 struct writeback_control *wbc) 2311{ 2312 struct blk_plug plug; 2313 int ret; 2314 2315 /* deal with chardevs and other special file */ --- 30 unchanged lines hidden (view full) --- 2346/** 2347 * write_one_page - write out a single page and wait on I/O 2348 * @page: the page to write 2349 * 2350 * The page must be locked by the caller and will be unlocked upon return. 2351 * 2352 * Note that the mapping's AS_EIO/AS_ENOSPC flags will be cleared when this 2353 * function returns. | 2314 */ 2315int generic_writepages(struct address_space *mapping, 2316 struct writeback_control *wbc) 2317{ 2318 struct blk_plug plug; 2319 int ret; 2320 2321 /* deal with chardevs and other special file */ --- 30 unchanged lines hidden (view full) --- 2352/** 2353 * write_one_page - write out a single page and wait on I/O 2354 * @page: the page to write 2355 * 2356 * The page must be locked by the caller and will be unlocked upon return. 2357 * 2358 * Note that the mapping's AS_EIO/AS_ENOSPC flags will be cleared when this 2359 * function returns. |
2360 * 2361 * Return: %0 on success, negative error code otherwise |
|
2354 */ 2355int write_one_page(struct page *page) 2356{ 2357 struct address_space *mapping = page->mapping; 2358 int ret = 0; 2359 struct writeback_control wbc = { 2360 .sync_mode = WB_SYNC_ALL, 2361 .nr_to_write = 1, --- 455 unchanged lines hidden --- | 2362 */ 2363int write_one_page(struct page *page) 2364{ 2365 struct address_space *mapping = page->mapping; 2366 int ret = 0; 2367 struct writeback_control wbc = { 2368 .sync_mode = WB_SYNC_ALL, 2369 .nr_to_write = 1, --- 455 unchanged lines hidden --- |