page-writeback.c (04fbfdc14e5f48463820d6b9807daa5e9c92c51f) | page-writeback.c (3e26c149c358529b1605f8959341d34bc4b880a3) |
---|---|
1/* 2 * mm/page-writeback.c 3 * 4 * Copyright (C) 2002, Linus Torvalds. 5 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com> 6 * 7 * Contains functions related to writing back dirty pages at the 8 * address_space level. --- 104 unchanged lines hidden (view full) --- 113 * dirty pages. Having them written out is the primary goal. 114 * 115 * We introduce a concept of time, a period over which we measure these events, 116 * because demand can/will vary over time. The length of this period itself is 117 * measured in page writeback completions. 118 * 119 */ 120static struct prop_descriptor vm_completions; | 1/* 2 * mm/page-writeback.c 3 * 4 * Copyright (C) 2002, Linus Torvalds. 5 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com> 6 * 7 * Contains functions related to writing back dirty pages at the 8 * address_space level. --- 104 unchanged lines hidden (view full) --- 113 * dirty pages. Having them written out is the primary goal. 114 * 115 * We introduce a concept of time, a period over which we measure these events, 116 * because demand can/will vary over time. The length of this period itself is 117 * measured in page writeback completions. 118 * 119 */ 120static struct prop_descriptor vm_completions; |
121static struct prop_descriptor vm_dirties; |
|
121 122static unsigned long determine_dirtyable_memory(void); 123 124/* 125 * couple the period to the dirty_ratio: 126 * 127 * period/2 ~ roundup_pow_of_two(dirty limit) 128 */ --- 12 unchanged lines hidden (view full) --- 141 struct file *filp, void __user *buffer, size_t *lenp, 142 loff_t *ppos) 143{ 144 int old_ratio = vm_dirty_ratio; 145 int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos); 146 if (ret == 0 && write && vm_dirty_ratio != old_ratio) { 147 int shift = calc_period_shift(); 148 prop_change_shift(&vm_completions, shift); | 122 123static unsigned long determine_dirtyable_memory(void); 124 125/* 126 * couple the period to the dirty_ratio: 127 * 128 * period/2 ~ roundup_pow_of_two(dirty limit) 129 */ --- 12 unchanged lines hidden (view full) --- 142 struct file *filp, void __user *buffer, size_t *lenp, 143 loff_t *ppos) 144{ 145 int old_ratio = vm_dirty_ratio; 146 int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos); 147 if (ret == 0 && write && vm_dirty_ratio != old_ratio) { 148 int shift = calc_period_shift(); 149 prop_change_shift(&vm_completions, shift); |
150 prop_change_shift(&vm_dirties, shift); |
|
149 } 150 return ret; 151} 152 153/* 154 * Increment the BDI's writeout completion count and the global writeout 155 * completion count. Called from test_clear_page_writeback(). 156 */ 157static inline void __bdi_writeout_inc(struct backing_dev_info *bdi) 158{ 159 __prop_inc_percpu(&vm_completions, &bdi->completions); 160} 161 | 151 } 152 return ret; 153} 154 155/* 156 * Increment the BDI's writeout completion count and the global writeout 157 * completion count. Called from test_clear_page_writeback(). 158 */ 159static inline void __bdi_writeout_inc(struct backing_dev_info *bdi) 160{ 161 __prop_inc_percpu(&vm_completions, &bdi->completions); 162} 163 |
164static inline void task_dirty_inc(struct task_struct *tsk) 165{ 166 prop_inc_single(&vm_dirties, &tsk->dirties); 167} 168 |
|
162/* 163 * Obtain an accurate fraction of the BDI's portion. 164 */ 165static void bdi_writeout_fraction(struct backing_dev_info *bdi, 166 long *numerator, long *denominator) 167{ 168 if (bdi_cap_writeback_dirty(bdi)) { 169 prop_fraction_percpu(&vm_completions, &bdi->completions, --- 23 unchanged lines hidden (view full) --- 193 avail_dirty = 0; 194 195 avail_dirty += bdi_stat(bdi, BDI_RECLAIMABLE) + 196 bdi_stat(bdi, BDI_WRITEBACK); 197 198 *pbdi_dirty = min(*pbdi_dirty, avail_dirty); 199} 200 | 169/* 170 * Obtain an accurate fraction of the BDI's portion. 171 */ 172static void bdi_writeout_fraction(struct backing_dev_info *bdi, 173 long *numerator, long *denominator) 174{ 175 if (bdi_cap_writeback_dirty(bdi)) { 176 prop_fraction_percpu(&vm_completions, &bdi->completions, --- 23 unchanged lines hidden (view full) --- 200 avail_dirty = 0; 201 202 avail_dirty += bdi_stat(bdi, BDI_RECLAIMABLE) + 203 bdi_stat(bdi, BDI_WRITEBACK); 204 205 *pbdi_dirty = min(*pbdi_dirty, avail_dirty); 206} 207 |
208static inline void task_dirties_fraction(struct task_struct *tsk, 209 long *numerator, long *denominator) 210{ 211 prop_fraction_single(&vm_dirties, &tsk->dirties, 212 numerator, denominator); 213} 214 |
|
201/* | 215/* |
216 * scale the dirty limit 217 * 218 * task specific dirty limit: 219 * 220 * dirty -= (dirty/8) * p_{t} 221 */ 222void task_dirty_limit(struct task_struct *tsk, long *pdirty) 223{ 224 long numerator, denominator; 225 long dirty = *pdirty; 226 u64 inv = dirty >> 3; 227 228 task_dirties_fraction(tsk, &numerator, &denominator); 229 inv *= numerator; 230 do_div(inv, denominator); 231 232 dirty -= inv; 233 if (dirty < *pdirty/2) 234 dirty = *pdirty/2; 235 236 *pdirty = dirty; 237} 238 239/* |
|
202 * Work out the current dirty-memory clamping and background writeout 203 * thresholds. 204 * 205 * The main aim here is to lower them aggressively if there is a lot of mapped 206 * memory around. To avoid stressing page reclaim with lots of unreclaimable 207 * pages. It is better to clamp down on writers than to start swapping, and 208 * performing lots of scanning. 209 * --- 89 unchanged lines hidden (view full) --- 299 */ 300 bdi_writeout_fraction(bdi, &numerator, &denominator); 301 302 bdi_dirty *= numerator; 303 do_div(bdi_dirty, denominator); 304 305 *pbdi_dirty = bdi_dirty; 306 clip_bdi_dirty_limit(bdi, dirty, pbdi_dirty); | 240 * Work out the current dirty-memory clamping and background writeout 241 * thresholds. 242 * 243 * The main aim here is to lower them aggressively if there is a lot of mapped 244 * memory around. To avoid stressing page reclaim with lots of unreclaimable 245 * pages. It is better to clamp down on writers than to start swapping, and 246 * performing lots of scanning. 247 * --- 89 unchanged lines hidden (view full) --- 337 */ 338 bdi_writeout_fraction(bdi, &numerator, &denominator); 339 340 bdi_dirty *= numerator; 341 do_div(bdi_dirty, denominator); 342 343 *pbdi_dirty = bdi_dirty; 344 clip_bdi_dirty_limit(bdi, dirty, pbdi_dirty); |
345 task_dirty_limit(current, pbdi_dirty); |
|
307 } 308} 309 310/* 311 * balance_dirty_pages() must be called by processes which are generating dirty 312 * data. It looks at the number of dirty pages in the machine and will force 313 * the caller to perform writeback if the system is over `vm_dirty_ratio'. 314 * If we're over `background_thresh' then pdflush is woken to perform some --- 400 unchanged lines hidden (view full) --- 715 int shift; 716 717 mod_timer(&wb_timer, jiffies + dirty_writeback_interval); 718 writeback_set_ratelimit(); 719 register_cpu_notifier(&ratelimit_nb); 720 721 shift = calc_period_shift(); 722 prop_descriptor_init(&vm_completions, shift); | 346 } 347} 348 349/* 350 * balance_dirty_pages() must be called by processes which are generating dirty 351 * data. It looks at the number of dirty pages in the machine and will force 352 * the caller to perform writeback if the system is over `vm_dirty_ratio'. 353 * If we're over `background_thresh' then pdflush is woken to perform some --- 400 unchanged lines hidden (view full) --- 754 int shift; 755 756 mod_timer(&wb_timer, jiffies + dirty_writeback_interval); 757 writeback_set_ratelimit(); 758 register_cpu_notifier(&ratelimit_nb); 759 760 shift = calc_period_shift(); 761 prop_descriptor_init(&vm_completions, shift); |
762 prop_descriptor_init(&vm_dirties, shift); |
|
723} 724 725/** 726 * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. 727 * @mapping: address space structure to write 728 * @wbc: subtract the number of written pages from *@wbc->nr_to_write 729 * @writepage: function called for each page 730 * @data: data passed to writepage function --- 262 unchanged lines hidden (view full) --- 993 return __set_page_dirty_nobuffers(page); 994} 995EXPORT_SYMBOL(redirty_page_for_writepage); 996 997/* 998 * If the mapping doesn't provide a set_page_dirty a_op, then 999 * just fall through and assume that it wants buffer_heads. 1000 */ | 763} 764 765/** 766 * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. 767 * @mapping: address space structure to write 768 * @wbc: subtract the number of written pages from *@wbc->nr_to_write 769 * @writepage: function called for each page 770 * @data: data passed to writepage function --- 262 unchanged lines hidden (view full) --- 1033 return __set_page_dirty_nobuffers(page); 1034} 1035EXPORT_SYMBOL(redirty_page_for_writepage); 1036 1037/* 1038 * If the mapping doesn't provide a set_page_dirty a_op, then 1039 * just fall through and assume that it wants buffer_heads. 1040 */ |
1001int fastcall set_page_dirty(struct page *page) | 1041static int __set_page_dirty(struct page *page) |
1002{ 1003 struct address_space *mapping = page_mapping(page); 1004 1005 if (likely(mapping)) { 1006 int (*spd)(struct page *) = mapping->a_ops->set_page_dirty; 1007#ifdef CONFIG_BLOCK 1008 if (!spd) 1009 spd = __set_page_dirty_buffers; 1010#endif 1011 return (*spd)(page); 1012 } 1013 if (!PageDirty(page)) { 1014 if (!TestSetPageDirty(page)) 1015 return 1; 1016 } 1017 return 0; 1018} | 1042{ 1043 struct address_space *mapping = page_mapping(page); 1044 1045 if (likely(mapping)) { 1046 int (*spd)(struct page *) = mapping->a_ops->set_page_dirty; 1047#ifdef CONFIG_BLOCK 1048 if (!spd) 1049 spd = __set_page_dirty_buffers; 1050#endif 1051 return (*spd)(page); 1052 } 1053 if (!PageDirty(page)) { 1054 if (!TestSetPageDirty(page)) 1055 return 1; 1056 } 1057 return 0; 1058} |
1059 1060int fastcall set_page_dirty(struct page *page) 1061{ 1062 int ret = __set_page_dirty(page); 1063 if (ret) 1064 task_dirty_inc(current); 1065 return ret; 1066} |
|
1019EXPORT_SYMBOL(set_page_dirty); 1020 1021/* 1022 * set_page_dirty() is racy if the caller has no reference against 1023 * page->mapping->host, and if the page is unlocked. This is because another 1024 * CPU could truncate the page off the mapping and then free the mapping. 1025 * 1026 * Usually, the page _is_ locked, or the caller is a user-space process which --- 161 unchanged lines hidden --- | 1067EXPORT_SYMBOL(set_page_dirty); 1068 1069/* 1070 * set_page_dirty() is racy if the caller has no reference against 1071 * page->mapping->host, and if the page is unlocked. This is because another 1072 * CPU could truncate the page off the mapping and then free the mapping. 1073 * 1074 * Usually, the page _is_ locked, or the caller is a user-space process which --- 161 unchanged lines hidden --- |