|
@@ -253,32 +253,6 @@ static void bdi_writeout_fraction(struct backing_dev_info *bdi,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
- * Clip the earned share of dirty pages to that which is actually available.
|
|
|
|
- * This avoids exceeding the total dirty_limit when the floating averages
|
|
|
|
- * fluctuate too quickly.
|
|
|
|
- */
|
|
|
|
-static void clip_bdi_dirty_limit(struct backing_dev_info *bdi,
|
|
|
|
- unsigned long dirty, unsigned long *pbdi_dirty)
|
|
|
|
-{
|
|
|
|
- unsigned long avail_dirty;
|
|
|
|
-
|
|
|
|
- avail_dirty = global_page_state(NR_FILE_DIRTY) +
|
|
|
|
- global_page_state(NR_WRITEBACK) +
|
|
|
|
- global_page_state(NR_UNSTABLE_NFS) +
|
|
|
|
- global_page_state(NR_WRITEBACK_TEMP);
|
|
|
|
-
|
|
|
|
- if (avail_dirty < dirty)
|
|
|
|
- avail_dirty = dirty - avail_dirty;
|
|
|
|
- else
|
|
|
|
- avail_dirty = 0;
|
|
|
|
-
|
|
|
|
- avail_dirty += bdi_stat(bdi, BDI_RECLAIMABLE) +
|
|
|
|
- bdi_stat(bdi, BDI_WRITEBACK);
|
|
|
|
-
|
|
|
|
- *pbdi_dirty = min(*pbdi_dirty, avail_dirty);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static inline void task_dirties_fraction(struct task_struct *tsk,
|
|
static inline void task_dirties_fraction(struct task_struct *tsk,
|
|
long *numerator, long *denominator)
|
|
long *numerator, long *denominator)
|
|
{
|
|
{
|
|
@@ -469,7 +443,6 @@ get_dirty_limits(unsigned long *pbackground, unsigned long *pdirty,
|
|
bdi_dirty = dirty * bdi->max_ratio / 100;
|
|
bdi_dirty = dirty * bdi->max_ratio / 100;
|
|
|
|
|
|
*pbdi_dirty = bdi_dirty;
|
|
*pbdi_dirty = bdi_dirty;
|
|
- clip_bdi_dirty_limit(bdi, dirty, pbdi_dirty);
|
|
|
|
task_dirty_limit(current, pbdi_dirty);
|
|
task_dirty_limit(current, pbdi_dirty);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -491,7 +464,7 @@ static void balance_dirty_pages(struct address_space *mapping,
|
|
unsigned long bdi_thresh;
|
|
unsigned long bdi_thresh;
|
|
unsigned long pages_written = 0;
|
|
unsigned long pages_written = 0;
|
|
unsigned long pause = 1;
|
|
unsigned long pause = 1;
|
|
-
|
|
|
|
|
|
+ bool dirty_exceeded = false;
|
|
struct backing_dev_info *bdi = mapping->backing_dev_info;
|
|
struct backing_dev_info *bdi = mapping->backing_dev_info;
|
|
|
|
|
|
for (;;) {
|
|
for (;;) {
|
|
@@ -509,10 +482,35 @@ static void balance_dirty_pages(struct address_space *mapping,
|
|
global_page_state(NR_UNSTABLE_NFS);
|
|
global_page_state(NR_UNSTABLE_NFS);
|
|
nr_writeback = global_page_state(NR_WRITEBACK);
|
|
nr_writeback = global_page_state(NR_WRITEBACK);
|
|
|
|
|
|
- bdi_nr_reclaimable = bdi_stat(bdi, BDI_RECLAIMABLE);
|
|
|
|
- bdi_nr_writeback = bdi_stat(bdi, BDI_WRITEBACK);
|
|
|
|
|
|
+ /*
|
|
|
|
+ * In order to avoid the stacked BDI deadlock we need
|
|
|
|
+ * to ensure we accurately count the 'dirty' pages when
|
|
|
|
+ * the threshold is low.
|
|
|
|
+ *
|
|
|
|
+ * Otherwise it would be possible to get thresh+n pages
|
|
|
|
+ * reported dirty, even though there are thresh-m pages
|
|
|
|
+ * actually dirty; with m+n sitting in the percpu
|
|
|
|
+ * deltas.
|
|
|
|
+ */
|
|
|
|
+ if (bdi_thresh < 2*bdi_stat_error(bdi)) {
|
|
|
|
+ bdi_nr_reclaimable = bdi_stat_sum(bdi, BDI_RECLAIMABLE);
|
|
|
|
+ bdi_nr_writeback = bdi_stat_sum(bdi, BDI_WRITEBACK);
|
|
|
|
+ } else {
|
|
|
|
+ bdi_nr_reclaimable = bdi_stat(bdi, BDI_RECLAIMABLE);
|
|
|
|
+ bdi_nr_writeback = bdi_stat(bdi, BDI_WRITEBACK);
|
|
|
|
+ }
|
|
|
|
|
|
- if (bdi_nr_reclaimable + bdi_nr_writeback <= bdi_thresh)
|
|
|
|
|
|
+ /*
|
|
|
|
+ * The bdi thresh is somehow "soft" limit derived from the
|
|
|
|
+ * global "hard" limit. The former helps to prevent heavy IO
|
|
|
|
+ * bdi or process from holding back light ones; The latter is
|
|
|
|
+ * the last resort safeguard.
|
|
|
|
+ */
|
|
|
|
+ dirty_exceeded =
|
|
|
|
+ (bdi_nr_reclaimable + bdi_nr_writeback >= bdi_thresh)
|
|
|
|
+ || (nr_reclaimable + nr_writeback >= dirty_thresh);
|
|
|
|
+
|
|
|
|
+ if (!dirty_exceeded)
|
|
break;
|
|
break;
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -540,34 +538,10 @@ static void balance_dirty_pages(struct address_space *mapping,
|
|
if (bdi_nr_reclaimable > bdi_thresh) {
|
|
if (bdi_nr_reclaimable > bdi_thresh) {
|
|
writeback_inodes_wb(&bdi->wb, &wbc);
|
|
writeback_inodes_wb(&bdi->wb, &wbc);
|
|
pages_written += write_chunk - wbc.nr_to_write;
|
|
pages_written += write_chunk - wbc.nr_to_write;
|
|
- get_dirty_limits(&background_thresh, &dirty_thresh,
|
|
|
|
- &bdi_thresh, bdi);
|
|
|
|
trace_wbc_balance_dirty_written(&wbc, bdi);
|
|
trace_wbc_balance_dirty_written(&wbc, bdi);
|
|
|
|
+ if (pages_written >= write_chunk)
|
|
|
|
+ break; /* We've done our duty */
|
|
}
|
|
}
|
|
-
|
|
|
|
- /*
|
|
|
|
- * In order to avoid the stacked BDI deadlock we need
|
|
|
|
- * to ensure we accurately count the 'dirty' pages when
|
|
|
|
- * the threshold is low.
|
|
|
|
- *
|
|
|
|
- * Otherwise it would be possible to get thresh+n pages
|
|
|
|
- * reported dirty, even though there are thresh-m pages
|
|
|
|
- * actually dirty; with m+n sitting in the percpu
|
|
|
|
- * deltas.
|
|
|
|
- */
|
|
|
|
- if (bdi_thresh < 2*bdi_stat_error(bdi)) {
|
|
|
|
- bdi_nr_reclaimable = bdi_stat_sum(bdi, BDI_RECLAIMABLE);
|
|
|
|
- bdi_nr_writeback = bdi_stat_sum(bdi, BDI_WRITEBACK);
|
|
|
|
- } else if (bdi_nr_reclaimable) {
|
|
|
|
- bdi_nr_reclaimable = bdi_stat(bdi, BDI_RECLAIMABLE);
|
|
|
|
- bdi_nr_writeback = bdi_stat(bdi, BDI_WRITEBACK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (bdi_nr_reclaimable + bdi_nr_writeback <= bdi_thresh)
|
|
|
|
- break;
|
|
|
|
- if (pages_written >= write_chunk)
|
|
|
|
- break; /* We've done our duty */
|
|
|
|
-
|
|
|
|
trace_wbc_balance_dirty_wait(&wbc, bdi);
|
|
trace_wbc_balance_dirty_wait(&wbc, bdi);
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
|
io_schedule_timeout(pause);
|
|
io_schedule_timeout(pause);
|
|
@@ -581,8 +555,7 @@ static void balance_dirty_pages(struct address_space *mapping,
|
|
pause = HZ / 10;
|
|
pause = HZ / 10;
|
|
}
|
|
}
|
|
|
|
|
|
- if (bdi_nr_reclaimable + bdi_nr_writeback < bdi_thresh &&
|
|
|
|
- bdi->dirty_exceeded)
|
|
|
|
|
|
+ if (!dirty_exceeded && bdi->dirty_exceeded)
|
|
bdi->dirty_exceeded = 0;
|
|
bdi->dirty_exceeded = 0;
|
|
|
|
|
|
if (writeback_in_progress(bdi))
|
|
if (writeback_in_progress(bdi))
|
|
@@ -597,9 +570,7 @@ static void balance_dirty_pages(struct address_space *mapping,
|
|
* background_thresh, to keep the amount of dirty memory low.
|
|
* background_thresh, to keep the amount of dirty memory low.
|
|
*/
|
|
*/
|
|
if ((laptop_mode && pages_written) ||
|
|
if ((laptop_mode && pages_written) ||
|
|
- (!laptop_mode && ((global_page_state(NR_FILE_DIRTY)
|
|
|
|
- + global_page_state(NR_UNSTABLE_NFS))
|
|
|
|
- > background_thresh)))
|
|
|
|
|
|
+ (!laptop_mode && (nr_reclaimable > background_thresh)))
|
|
bdi_start_background_writeback(bdi);
|
|
bdi_start_background_writeback(bdi);
|
|
}
|
|
}
|
|
|
|
|