2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* include/linux/backing-dev.h
|
|
|
|
*
|
|
|
|
* low-level device information and state which is propagated up through
|
|
|
|
* to high-level code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_BACKING_DEV_H
|
|
|
|
#define _LINUX_BACKING_DEV_H
|
|
|
|
|
2007-10-17 00:25:47 -06:00
|
|
|
#include <linux/percpu_counter.h>
|
|
|
|
#include <linux/log2.h>
|
2012-05-24 10:59:11 -06:00
|
|
|
#include <linux/flex_proportions.h>
|
2008-04-30 01:54:32 -06:00
|
|
|
#include <linux/kernel.h>
|
2008-04-30 01:54:37 -06:00
|
|
|
#include <linux/fs.h>
|
2009-09-09 01:08:54 -06:00
|
|
|
#include <linux/sched.h>
|
2010-04-06 06:25:14 -06:00
|
|
|
#include <linux/timer.h>
|
2009-09-09 01:08:54 -06:00
|
|
|
#include <linux/writeback.h>
|
2011-07-26 17:09:06 -06:00
|
|
|
#include <linux/atomic.h>
|
2012-07-31 17:41:52 -06:00
|
|
|
#include <linux/sysctl.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-10-20 00:28:16 -06:00
|
|
|
struct page;
|
2008-04-30 01:54:32 -06:00
|
|
|
struct device;
|
2008-04-30 01:54:36 -06:00
|
|
|
struct dentry;
|
2006-10-20 00:28:16 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Bits in backing_dev_info.state
|
|
|
|
*/
|
|
|
|
enum bdi_state {
|
2009-09-09 01:08:54 -06:00
|
|
|
BDI_pending, /* On its way to being activated */
|
|
|
|
BDI_wb_alloc, /* Default embedded wb allocated */
|
2009-04-06 06:48:01 -06:00
|
|
|
BDI_async_congested, /* The async (write) queue is getting full */
|
|
|
|
BDI_sync_congested, /* The sync queue is getting full */
|
2009-09-09 01:10:25 -06:00
|
|
|
BDI_registered, /* bdi_register() was done */
|
2010-08-11 15:17:44 -06:00
|
|
|
BDI_writeback_running, /* Writeback is in progress */
|
2005-04-16 16:20:36 -06:00
|
|
|
BDI_unused, /* Available bits start here */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef int (congested_fn)(void *, int);
|
|
|
|
|
2007-10-17 00:25:47 -06:00
|
|
|
enum bdi_stat_item {
|
2007-10-17 00:25:47 -06:00
|
|
|
BDI_RECLAIMABLE,
|
2007-10-17 00:25:48 -06:00
|
|
|
BDI_WRITEBACK,
|
2011-01-23 09:07:47 -07:00
|
|
|
BDI_DIRTIED,
|
2010-12-08 21:44:24 -07:00
|
|
|
BDI_WRITTEN,
|
2007-10-17 00:25:47 -06:00
|
|
|
NR_BDI_STAT_ITEMS
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BDI_STAT_BATCH (8*(1+ilog2(nr_cpu_ids)))
|
|
|
|
|
2009-09-09 01:08:54 -06:00
|
|
|
struct bdi_writeback {
|
2010-07-25 05:29:18 -06:00
|
|
|
struct backing_dev_info *bdi; /* our parent bdi */
|
2009-09-09 01:08:54 -06:00
|
|
|
unsigned int nr;
|
|
|
|
|
2010-07-25 05:29:18 -06:00
|
|
|
unsigned long last_old_flush; /* last old data flush */
|
|
|
|
unsigned long last_active; /* last time bdi thread was active */
|
2009-09-09 01:08:54 -06:00
|
|
|
|
2010-07-25 05:29:18 -06:00
|
|
|
struct task_struct *task; /* writeback thread */
|
2010-07-25 05:29:22 -06:00
|
|
|
struct timer_list wakeup_timer; /* used for delayed bdi thread wakeup */
|
2010-07-25 05:29:18 -06:00
|
|
|
struct list_head b_dirty; /* dirty inodes */
|
|
|
|
struct list_head b_io; /* parked for writeback */
|
|
|
|
struct list_head b_more_io; /* parked for more writeback */
|
2011-04-21 18:19:44 -06:00
|
|
|
spinlock_t list_lock; /* protects the b_* lists */
|
2009-09-09 01:08:54 -06:00
|
|
|
};
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
struct backing_dev_info {
|
2009-09-02 01:19:46 -06:00
|
|
|
struct list_head bdi_list;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */
|
|
|
|
unsigned long state; /* Always use atomic bitops on this */
|
|
|
|
unsigned int capabilities; /* Device capabilities */
|
|
|
|
congested_fn *congested_fn; /* Function pointer if device is md/dm */
|
|
|
|
void *congested_data; /* Pointer to aux data for congested func */
|
2007-10-17 00:25:47 -06:00
|
|
|
|
2009-06-12 06:45:52 -06:00
|
|
|
char *name;
|
|
|
|
|
2007-10-17 00:25:47 -06:00
|
|
|
struct percpu_counter bdi_stat[NR_BDI_STAT_ITEMS];
|
2007-10-17 00:25:50 -06:00
|
|
|
|
2010-08-29 11:22:30 -06:00
|
|
|
unsigned long bw_time_stamp; /* last time write bw is updated */
|
writeback: dirty rate control
It's all about bdi->dirty_ratelimit, which aims to be (write_bw / N)
when there are N dd tasks.
On write() syscall, use bdi->dirty_ratelimit
============================================
balance_dirty_pages(pages_dirtied)
{
task_ratelimit = bdi->dirty_ratelimit * bdi_position_ratio();
pause = pages_dirtied / task_ratelimit;
sleep(pause);
}
On every 200ms, update bdi->dirty_ratelimit
===========================================
bdi_update_dirty_ratelimit()
{
task_ratelimit = bdi->dirty_ratelimit * bdi_position_ratio();
balanced_dirty_ratelimit = task_ratelimit * write_bw / dirty_rate;
bdi->dirty_ratelimit = balanced_dirty_ratelimit
}
Estimation of balanced bdi->dirty_ratelimit
===========================================
balanced task_ratelimit
-----------------------
balance_dirty_pages() needs to throttle tasks dirtying pages such that
the total amount of dirty pages stays below the specified dirty limit in
order to avoid memory deadlocks. Furthermore we desire fairness in that
tasks get throttled proportionally to the amount of pages they dirty.
IOW we want to throttle tasks such that we match the dirty rate to the
writeout bandwidth, this yields a stable amount of dirty pages:
dirty_rate == write_bw (1)
The fairness requirement gives us:
task_ratelimit = balanced_dirty_ratelimit
== write_bw / N (2)
where N is the number of dd tasks. We don't know N beforehand, but
still can estimate balanced_dirty_ratelimit within 200ms.
Start by throttling each dd task at rate
task_ratelimit = task_ratelimit_0 (3)
(any non-zero initial value is OK)
After 200ms, we measured
dirty_rate = # of pages dirtied by all dd's / 200ms
write_bw = # of pages written to the disk / 200ms
For the aggressive dd dirtiers, the equality holds
dirty_rate == N * task_rate
== N * task_ratelimit_0 (4)
Or
task_ratelimit_0 == dirty_rate / N (5)
Now we conclude that the balanced task ratelimit can be estimated by
write_bw
balanced_dirty_ratelimit = task_ratelimit_0 * ---------- (6)
dirty_rate
Because with (4) and (5) we can get the desired equality (1):
write_bw
balanced_dirty_ratelimit == (dirty_rate / N) * ----------
dirty_rate
== write_bw / N
Then using the balanced task ratelimit we can compute task pause times like:
task_pause = task->nr_dirtied / task_ratelimit
task_ratelimit with position control
------------------------------------
However, while the above gives us means of matching the dirty rate to
the writeout bandwidth, it at best provides us with a stable dirty page
count (assuming a static system). In order to control the dirty page
count such that it is high enough to provide performance, but does not
exceed the specified limit we need another control.
The dirty position control works by extending (2) to
task_ratelimit = balanced_dirty_ratelimit * pos_ratio (7)
where pos_ratio is a negative feedback function that subjects to
1) f(setpoint) = 1.0
2) df/dx < 0
That is, if the dirty pages are ABOVE the setpoint, we throttle each
task a bit more HEAVY than balanced_dirty_ratelimit, so that the dirty
pages are created less fast than they are cleaned, thus DROP to the
setpoints (and the reverse).
Based on (7) and the assumption that both dirty_ratelimit and pos_ratio
remains CONSTANT for the past 200ms, we get
task_ratelimit_0 = balanced_dirty_ratelimit * pos_ratio (8)
Putting (8) into (6), we get the formula used in
bdi_update_dirty_ratelimit():
write_bw
balanced_dirty_ratelimit *= pos_ratio * ---------- (9)
dirty_rate
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
2011-06-12 10:51:31 -06:00
|
|
|
unsigned long dirtied_stamp;
|
2010-08-29 11:22:30 -06:00
|
|
|
unsigned long written_stamp; /* pages written at bw_time_stamp */
|
|
|
|
unsigned long write_bandwidth; /* the estimated write bandwidth */
|
|
|
|
unsigned long avg_write_bandwidth; /* further smoothed write bw */
|
|
|
|
|
writeback: dirty rate control
It's all about bdi->dirty_ratelimit, which aims to be (write_bw / N)
when there are N dd tasks.
On write() syscall, use bdi->dirty_ratelimit
============================================
balance_dirty_pages(pages_dirtied)
{
task_ratelimit = bdi->dirty_ratelimit * bdi_position_ratio();
pause = pages_dirtied / task_ratelimit;
sleep(pause);
}
On every 200ms, update bdi->dirty_ratelimit
===========================================
bdi_update_dirty_ratelimit()
{
task_ratelimit = bdi->dirty_ratelimit * bdi_position_ratio();
balanced_dirty_ratelimit = task_ratelimit * write_bw / dirty_rate;
bdi->dirty_ratelimit = balanced_dirty_ratelimit
}
Estimation of balanced bdi->dirty_ratelimit
===========================================
balanced task_ratelimit
-----------------------
balance_dirty_pages() needs to throttle tasks dirtying pages such that
the total amount of dirty pages stays below the specified dirty limit in
order to avoid memory deadlocks. Furthermore we desire fairness in that
tasks get throttled proportionally to the amount of pages they dirty.
IOW we want to throttle tasks such that we match the dirty rate to the
writeout bandwidth, this yields a stable amount of dirty pages:
dirty_rate == write_bw (1)
The fairness requirement gives us:
task_ratelimit = balanced_dirty_ratelimit
== write_bw / N (2)
where N is the number of dd tasks. We don't know N beforehand, but
still can estimate balanced_dirty_ratelimit within 200ms.
Start by throttling each dd task at rate
task_ratelimit = task_ratelimit_0 (3)
(any non-zero initial value is OK)
After 200ms, we measured
dirty_rate = # of pages dirtied by all dd's / 200ms
write_bw = # of pages written to the disk / 200ms
For the aggressive dd dirtiers, the equality holds
dirty_rate == N * task_rate
== N * task_ratelimit_0 (4)
Or
task_ratelimit_0 == dirty_rate / N (5)
Now we conclude that the balanced task ratelimit can be estimated by
write_bw
balanced_dirty_ratelimit = task_ratelimit_0 * ---------- (6)
dirty_rate
Because with (4) and (5) we can get the desired equality (1):
write_bw
balanced_dirty_ratelimit == (dirty_rate / N) * ----------
dirty_rate
== write_bw / N
Then using the balanced task ratelimit we can compute task pause times like:
task_pause = task->nr_dirtied / task_ratelimit
task_ratelimit with position control
------------------------------------
However, while the above gives us means of matching the dirty rate to
the writeout bandwidth, it at best provides us with a stable dirty page
count (assuming a static system). In order to control the dirty page
count such that it is high enough to provide performance, but does not
exceed the specified limit we need another control.
The dirty position control works by extending (2) to
task_ratelimit = balanced_dirty_ratelimit * pos_ratio (7)
where pos_ratio is a negative feedback function that subjects to
1) f(setpoint) = 1.0
2) df/dx < 0
That is, if the dirty pages are ABOVE the setpoint, we throttle each
task a bit more HEAVY than balanced_dirty_ratelimit, so that the dirty
pages are created less fast than they are cleaned, thus DROP to the
setpoints (and the reverse).
Based on (7) and the assumption that both dirty_ratelimit and pos_ratio
remains CONSTANT for the past 200ms, we get
task_ratelimit_0 = balanced_dirty_ratelimit * pos_ratio (8)
Putting (8) into (6), we get the formula used in
bdi_update_dirty_ratelimit():
write_bw
balanced_dirty_ratelimit *= pos_ratio * ---------- (9)
dirty_rate
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
2011-06-12 10:51:31 -06:00
|
|
|
/*
|
|
|
|
* The base dirty throttle rate, re-calculated on every 200ms.
|
|
|
|
* All the bdi tasks' dirty rate will be curbed under it.
|
writeback: stabilize bdi->dirty_ratelimit
There are some imperfections in balanced_dirty_ratelimit.
1) large fluctuations
The dirty_rate used for computing balanced_dirty_ratelimit is merely
averaged in the past 200ms (very small comparing to the 3s estimation
period for write_bw), which makes rather dispersed distribution of
balanced_dirty_ratelimit.
It's pretty hard to average out the singular points by increasing the
estimation period. Considering that the averaging technique will
introduce very undesirable time lags, I give it up totally. (btw, the 3s
write_bw averaging time lag is much more acceptable because its impact
is one-way and therefore won't lead to oscillations.)
The more practical way is filtering -- most singular
balanced_dirty_ratelimit points can be filtered out by remembering some
prev_balanced_rate and prev_prev_balanced_rate. However the more
reliable way is to guard balanced_dirty_ratelimit with task_ratelimit.
2) due to truncates and fs redirties, the (write_bw <=> dirty_rate)
match could become unbalanced, which may lead to large systematical
errors in balanced_dirty_ratelimit. The truncates, due to its possibly
bumpy nature, can hardly be compensated smoothly. So let's face it. When
some over-estimated balanced_dirty_ratelimit brings dirty_ratelimit
high, dirty pages will go higher than the setpoint. task_ratelimit will
in turn become lower than dirty_ratelimit. So if we consider both
balanced_dirty_ratelimit and task_ratelimit and update dirty_ratelimit
only when they are on the same side of dirty_ratelimit, the systematical
errors in balanced_dirty_ratelimit won't be able to bring
dirty_ratelimit far away.
The balanced_dirty_ratelimit estimation may also be inaccurate near
@limit or @freerun, however is less an issue.
3) since we ultimately want to
- keep the fluctuations of task ratelimit as small as possible
- keep the dirty pages around the setpoint as long time as possible
the update policy used for (2) also serves the above goals nicely:
if for some reason the dirty pages are high (task_ratelimit < dirty_ratelimit),
and dirty_ratelimit is low (dirty_ratelimit < balanced_dirty_ratelimit),
there is no point to bring up dirty_ratelimit in a hurry only to hurt
both the above two goals.
So, we make use of task_ratelimit to limit the update of dirty_ratelimit
in two ways:
1) avoid changing dirty rate when it's against the position control target
(the adjusted rate will slow down the progress of dirty pages going
back to setpoint).
2) limit the step size. task_ratelimit is changing values step by step,
leaving a consistent trace comparing to the randomly jumping
balanced_dirty_ratelimit. task_ratelimit also has the nice smaller
errors in stable state and typically larger errors when there are big
errors in rate. So it's a pretty good limiting factor for the step
size of dirty_ratelimit.
Note that bdi->dirty_ratelimit is always tracking balanced_dirty_ratelimit.
task_ratelimit is merely used as a limiting factor.
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
2011-08-26 15:53:24 -06:00
|
|
|
* @dirty_ratelimit tracks the estimated @balanced_dirty_ratelimit
|
|
|
|
* in small steps and is much more smooth/stable than the latter.
|
writeback: dirty rate control
It's all about bdi->dirty_ratelimit, which aims to be (write_bw / N)
when there are N dd tasks.
On write() syscall, use bdi->dirty_ratelimit
============================================
balance_dirty_pages(pages_dirtied)
{
task_ratelimit = bdi->dirty_ratelimit * bdi_position_ratio();
pause = pages_dirtied / task_ratelimit;
sleep(pause);
}
On every 200ms, update bdi->dirty_ratelimit
===========================================
bdi_update_dirty_ratelimit()
{
task_ratelimit = bdi->dirty_ratelimit * bdi_position_ratio();
balanced_dirty_ratelimit = task_ratelimit * write_bw / dirty_rate;
bdi->dirty_ratelimit = balanced_dirty_ratelimit
}
Estimation of balanced bdi->dirty_ratelimit
===========================================
balanced task_ratelimit
-----------------------
balance_dirty_pages() needs to throttle tasks dirtying pages such that
the total amount of dirty pages stays below the specified dirty limit in
order to avoid memory deadlocks. Furthermore we desire fairness in that
tasks get throttled proportionally to the amount of pages they dirty.
IOW we want to throttle tasks such that we match the dirty rate to the
writeout bandwidth, this yields a stable amount of dirty pages:
dirty_rate == write_bw (1)
The fairness requirement gives us:
task_ratelimit = balanced_dirty_ratelimit
== write_bw / N (2)
where N is the number of dd tasks. We don't know N beforehand, but
still can estimate balanced_dirty_ratelimit within 200ms.
Start by throttling each dd task at rate
task_ratelimit = task_ratelimit_0 (3)
(any non-zero initial value is OK)
After 200ms, we measured
dirty_rate = # of pages dirtied by all dd's / 200ms
write_bw = # of pages written to the disk / 200ms
For the aggressive dd dirtiers, the equality holds
dirty_rate == N * task_rate
== N * task_ratelimit_0 (4)
Or
task_ratelimit_0 == dirty_rate / N (5)
Now we conclude that the balanced task ratelimit can be estimated by
write_bw
balanced_dirty_ratelimit = task_ratelimit_0 * ---------- (6)
dirty_rate
Because with (4) and (5) we can get the desired equality (1):
write_bw
balanced_dirty_ratelimit == (dirty_rate / N) * ----------
dirty_rate
== write_bw / N
Then using the balanced task ratelimit we can compute task pause times like:
task_pause = task->nr_dirtied / task_ratelimit
task_ratelimit with position control
------------------------------------
However, while the above gives us means of matching the dirty rate to
the writeout bandwidth, it at best provides us with a stable dirty page
count (assuming a static system). In order to control the dirty page
count such that it is high enough to provide performance, but does not
exceed the specified limit we need another control.
The dirty position control works by extending (2) to
task_ratelimit = balanced_dirty_ratelimit * pos_ratio (7)
where pos_ratio is a negative feedback function that subjects to
1) f(setpoint) = 1.0
2) df/dx < 0
That is, if the dirty pages are ABOVE the setpoint, we throttle each
task a bit more HEAVY than balanced_dirty_ratelimit, so that the dirty
pages are created less fast than they are cleaned, thus DROP to the
setpoints (and the reverse).
Based on (7) and the assumption that both dirty_ratelimit and pos_ratio
remains CONSTANT for the past 200ms, we get
task_ratelimit_0 = balanced_dirty_ratelimit * pos_ratio (8)
Putting (8) into (6), we get the formula used in
bdi_update_dirty_ratelimit():
write_bw
balanced_dirty_ratelimit *= pos_ratio * ---------- (9)
dirty_rate
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
2011-06-12 10:51:31 -06:00
|
|
|
*/
|
|
|
|
unsigned long dirty_ratelimit;
|
writeback: stabilize bdi->dirty_ratelimit
There are some imperfections in balanced_dirty_ratelimit.
1) large fluctuations
The dirty_rate used for computing balanced_dirty_ratelimit is merely
averaged in the past 200ms (very small comparing to the 3s estimation
period for write_bw), which makes rather dispersed distribution of
balanced_dirty_ratelimit.
It's pretty hard to average out the singular points by increasing the
estimation period. Considering that the averaging technique will
introduce very undesirable time lags, I give it up totally. (btw, the 3s
write_bw averaging time lag is much more acceptable because its impact
is one-way and therefore won't lead to oscillations.)
The more practical way is filtering -- most singular
balanced_dirty_ratelimit points can be filtered out by remembering some
prev_balanced_rate and prev_prev_balanced_rate. However the more
reliable way is to guard balanced_dirty_ratelimit with task_ratelimit.
2) due to truncates and fs redirties, the (write_bw <=> dirty_rate)
match could become unbalanced, which may lead to large systematical
errors in balanced_dirty_ratelimit. The truncates, due to its possibly
bumpy nature, can hardly be compensated smoothly. So let's face it. When
some over-estimated balanced_dirty_ratelimit brings dirty_ratelimit
high, dirty pages will go higher than the setpoint. task_ratelimit will
in turn become lower than dirty_ratelimit. So if we consider both
balanced_dirty_ratelimit and task_ratelimit and update dirty_ratelimit
only when they are on the same side of dirty_ratelimit, the systematical
errors in balanced_dirty_ratelimit won't be able to bring
dirty_ratelimit far away.
The balanced_dirty_ratelimit estimation may also be inaccurate near
@limit or @freerun, however is less an issue.
3) since we ultimately want to
- keep the fluctuations of task ratelimit as small as possible
- keep the dirty pages around the setpoint as long time as possible
the update policy used for (2) also serves the above goals nicely:
if for some reason the dirty pages are high (task_ratelimit < dirty_ratelimit),
and dirty_ratelimit is low (dirty_ratelimit < balanced_dirty_ratelimit),
there is no point to bring up dirty_ratelimit in a hurry only to hurt
both the above two goals.
So, we make use of task_ratelimit to limit the update of dirty_ratelimit
in two ways:
1) avoid changing dirty rate when it's against the position control target
(the adjusted rate will slow down the progress of dirty pages going
back to setpoint).
2) limit the step size. task_ratelimit is changing values step by step,
leaving a consistent trace comparing to the randomly jumping
balanced_dirty_ratelimit. task_ratelimit also has the nice smaller
errors in stable state and typically larger errors when there are big
errors in rate. So it's a pretty good limiting factor for the step
size of dirty_ratelimit.
Note that bdi->dirty_ratelimit is always tracking balanced_dirty_ratelimit.
task_ratelimit is merely used as a limiting factor.
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
2011-08-26 15:53:24 -06:00
|
|
|
unsigned long balanced_dirty_ratelimit;
|
writeback: dirty rate control
It's all about bdi->dirty_ratelimit, which aims to be (write_bw / N)
when there are N dd tasks.
On write() syscall, use bdi->dirty_ratelimit
============================================
balance_dirty_pages(pages_dirtied)
{
task_ratelimit = bdi->dirty_ratelimit * bdi_position_ratio();
pause = pages_dirtied / task_ratelimit;
sleep(pause);
}
On every 200ms, update bdi->dirty_ratelimit
===========================================
bdi_update_dirty_ratelimit()
{
task_ratelimit = bdi->dirty_ratelimit * bdi_position_ratio();
balanced_dirty_ratelimit = task_ratelimit * write_bw / dirty_rate;
bdi->dirty_ratelimit = balanced_dirty_ratelimit
}
Estimation of balanced bdi->dirty_ratelimit
===========================================
balanced task_ratelimit
-----------------------
balance_dirty_pages() needs to throttle tasks dirtying pages such that
the total amount of dirty pages stays below the specified dirty limit in
order to avoid memory deadlocks. Furthermore we desire fairness in that
tasks get throttled proportionally to the amount of pages they dirty.
IOW we want to throttle tasks such that we match the dirty rate to the
writeout bandwidth, this yields a stable amount of dirty pages:
dirty_rate == write_bw (1)
The fairness requirement gives us:
task_ratelimit = balanced_dirty_ratelimit
== write_bw / N (2)
where N is the number of dd tasks. We don't know N beforehand, but
still can estimate balanced_dirty_ratelimit within 200ms.
Start by throttling each dd task at rate
task_ratelimit = task_ratelimit_0 (3)
(any non-zero initial value is OK)
After 200ms, we measured
dirty_rate = # of pages dirtied by all dd's / 200ms
write_bw = # of pages written to the disk / 200ms
For the aggressive dd dirtiers, the equality holds
dirty_rate == N * task_rate
== N * task_ratelimit_0 (4)
Or
task_ratelimit_0 == dirty_rate / N (5)
Now we conclude that the balanced task ratelimit can be estimated by
write_bw
balanced_dirty_ratelimit = task_ratelimit_0 * ---------- (6)
dirty_rate
Because with (4) and (5) we can get the desired equality (1):
write_bw
balanced_dirty_ratelimit == (dirty_rate / N) * ----------
dirty_rate
== write_bw / N
Then using the balanced task ratelimit we can compute task pause times like:
task_pause = task->nr_dirtied / task_ratelimit
task_ratelimit with position control
------------------------------------
However, while the above gives us means of matching the dirty rate to
the writeout bandwidth, it at best provides us with a stable dirty page
count (assuming a static system). In order to control the dirty page
count such that it is high enough to provide performance, but does not
exceed the specified limit we need another control.
The dirty position control works by extending (2) to
task_ratelimit = balanced_dirty_ratelimit * pos_ratio (7)
where pos_ratio is a negative feedback function that subjects to
1) f(setpoint) = 1.0
2) df/dx < 0
That is, if the dirty pages are ABOVE the setpoint, we throttle each
task a bit more HEAVY than balanced_dirty_ratelimit, so that the dirty
pages are created less fast than they are cleaned, thus DROP to the
setpoints (and the reverse).
Based on (7) and the assumption that both dirty_ratelimit and pos_ratio
remains CONSTANT for the past 200ms, we get
task_ratelimit_0 = balanced_dirty_ratelimit * pos_ratio (8)
Putting (8) into (6), we get the formula used in
bdi_update_dirty_ratelimit():
write_bw
balanced_dirty_ratelimit *= pos_ratio * ---------- (9)
dirty_rate
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
2011-06-12 10:51:31 -06:00
|
|
|
|
2012-05-24 10:59:11 -06:00
|
|
|
struct fprop_local_percpu completions;
|
2007-10-17 00:25:50 -06:00
|
|
|
int dirty_exceeded;
|
2008-04-30 01:54:32 -06:00
|
|
|
|
2008-04-30 01:54:35 -06:00
|
|
|
unsigned int min_ratio;
|
2008-04-30 01:54:36 -06:00
|
|
|
unsigned int max_ratio, max_prop_frac;
|
2008-04-30 01:54:35 -06:00
|
|
|
|
2009-09-09 01:08:54 -06:00
|
|
|
struct bdi_writeback wb; /* default writeback info for this bdi */
|
2010-06-19 15:08:06 -06:00
|
|
|
spinlock_t wb_lock; /* protects work_list */
|
2008-04-30 01:54:36 -06:00
|
|
|
|
2009-09-09 01:08:54 -06:00
|
|
|
struct list_head work_list;
|
|
|
|
|
|
|
|
struct device *dev;
|
2009-09-02 01:19:46 -06:00
|
|
|
|
2010-04-06 06:25:14 -06:00
|
|
|
struct timer_list laptop_mode_wb_timer;
|
|
|
|
|
2008-04-30 01:54:36 -06:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
struct dentry *debug_dir;
|
|
|
|
struct dentry *debug_stats;
|
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2007-10-17 00:25:47 -06:00
|
|
|
int bdi_init(struct backing_dev_info *bdi);
|
|
|
|
void bdi_destroy(struct backing_dev_info *bdi);
|
|
|
|
|
2008-04-30 01:54:32 -06:00
|
|
|
int bdi_register(struct backing_dev_info *bdi, struct device *parent,
|
|
|
|
const char *fmt, ...);
|
|
|
|
int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev);
|
|
|
|
void bdi_unregister(struct backing_dev_info *bdi);
|
2010-04-22 03:37:01 -06:00
|
|
|
int bdi_setup_and_register(struct backing_dev_info *, char *, unsigned int);
|
2011-10-07 21:54:10 -06:00
|
|
|
void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
|
|
|
|
enum wb_reason reason);
|
2010-06-08 10:15:15 -06:00
|
|
|
void bdi_start_background_writeback(struct backing_dev_info *bdi);
|
2010-06-19 15:08:22 -06:00
|
|
|
int bdi_writeback_thread(void *data);
|
2009-09-09 01:08:54 -06:00
|
|
|
int bdi_has_dirty_io(struct backing_dev_info *bdi);
|
2010-07-25 05:29:22 -06:00
|
|
|
void bdi_wakeup_thread_delayed(struct backing_dev_info *bdi);
|
2011-04-21 18:19:44 -06:00
|
|
|
void bdi_lock_two(struct bdi_writeback *wb1, struct bdi_writeback *wb2);
|
2008-04-30 01:54:32 -06:00
|
|
|
|
2009-09-09 01:08:54 -06:00
|
|
|
extern spinlock_t bdi_lock;
|
2009-09-02 01:19:46 -06:00
|
|
|
extern struct list_head bdi_list;
|
2010-10-26 15:22:03 -06:00
|
|
|
extern struct list_head bdi_pending_list;
|
2009-09-02 01:19:46 -06:00
|
|
|
|
2009-09-09 01:08:54 -06:00
|
|
|
static inline int wb_has_dirty_io(struct bdi_writeback *wb)
|
|
|
|
{
|
|
|
|
return !list_empty(&wb->b_dirty) ||
|
|
|
|
!list_empty(&wb->b_io) ||
|
|
|
|
!list_empty(&wb->b_more_io);
|
|
|
|
}
|
|
|
|
|
2007-10-17 00:25:47 -06:00
|
|
|
static inline void __add_bdi_stat(struct backing_dev_info *bdi,
|
|
|
|
enum bdi_stat_item item, s64 amount)
|
|
|
|
{
|
|
|
|
__percpu_counter_add(&bdi->bdi_stat[item], amount, BDI_STAT_BATCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __inc_bdi_stat(struct backing_dev_info *bdi,
|
|
|
|
enum bdi_stat_item item)
|
|
|
|
{
|
|
|
|
__add_bdi_stat(bdi, item, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void inc_bdi_stat(struct backing_dev_info *bdi,
|
|
|
|
enum bdi_stat_item item)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
__inc_bdi_stat(bdi, item);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __dec_bdi_stat(struct backing_dev_info *bdi,
|
|
|
|
enum bdi_stat_item item)
|
|
|
|
{
|
|
|
|
__add_bdi_stat(bdi, item, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void dec_bdi_stat(struct backing_dev_info *bdi,
|
|
|
|
enum bdi_stat_item item)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
__dec_bdi_stat(bdi, item);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline s64 bdi_stat(struct backing_dev_info *bdi,
|
|
|
|
enum bdi_stat_item item)
|
|
|
|
{
|
|
|
|
return percpu_counter_read_positive(&bdi->bdi_stat[item]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline s64 __bdi_stat_sum(struct backing_dev_info *bdi,
|
|
|
|
enum bdi_stat_item item)
|
|
|
|
{
|
|
|
|
return percpu_counter_sum_positive(&bdi->bdi_stat[item]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline s64 bdi_stat_sum(struct backing_dev_info *bdi,
|
|
|
|
enum bdi_stat_item item)
|
2007-10-17 00:25:46 -06:00
|
|
|
{
|
2007-10-17 00:25:47 -06:00
|
|
|
s64 sum;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
sum = __bdi_stat_sum(bdi, item);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return sum;
|
2007-10-17 00:25:46 -06:00
|
|
|
}
|
|
|
|
|
2008-04-30 01:54:37 -06:00
|
|
|
extern void bdi_writeout_inc(struct backing_dev_info *bdi);
|
|
|
|
|
2007-10-17 00:25:47 -06:00
|
|
|
/*
|
|
|
|
* maximal error of a stat counter.
|
|
|
|
*/
|
|
|
|
static inline unsigned long bdi_stat_error(struct backing_dev_info *bdi)
|
2007-10-17 00:25:46 -06:00
|
|
|
{
|
2007-10-17 00:25:47 -06:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
return nr_cpu_ids * BDI_STAT_BATCH;
|
|
|
|
#else
|
|
|
|
return 1;
|
|
|
|
#endif
|
2007-10-17 00:25:46 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-04-30 01:54:35 -06:00
|
|
|
int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio);
|
2008-04-30 01:54:36 -06:00
|
|
|
int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
|
2008-04-30 01:54:35 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Flags in backing_dev_info::capability
|
2008-04-30 01:54:37 -06:00
|
|
|
*
|
|
|
|
* The first three flags control whether dirty pages will contribute to the
|
|
|
|
* VM's accounting and whether writepages() should be called for dirty pages
|
|
|
|
* (something that would not, for example, be appropriate for ramfs)
|
|
|
|
*
|
|
|
|
* WARNING: these flags are closely related and should not normally be
|
|
|
|
* used separately. The BDI_CAP_NO_ACCT_AND_WRITEBACK combines these
|
|
|
|
* three flags into a single convenience macro.
|
|
|
|
*
|
|
|
|
* BDI_CAP_NO_ACCT_DIRTY: Dirty pages shouldn't contribute to accounting
|
|
|
|
* BDI_CAP_NO_WRITEBACK: Don't write pages back
|
|
|
|
* BDI_CAP_NO_ACCT_WB: Don't automatically account writeback pages
|
|
|
|
*
|
|
|
|
* These flags let !MMU mmap() govern direct device mapping vs immediate
|
|
|
|
* copying more easily for MAP_PRIVATE, especially for ROM filesystems.
|
|
|
|
*
|
|
|
|
* BDI_CAP_MAP_COPY: Copy can be mapped (MAP_PRIVATE)
|
|
|
|
* BDI_CAP_MAP_DIRECT: Can be mapped directly (MAP_SHARED)
|
|
|
|
* BDI_CAP_READ_MAP: Can be mapped for reading
|
|
|
|
* BDI_CAP_WRITE_MAP: Can be mapped for writing
|
|
|
|
* BDI_CAP_EXEC_MAP: Can be mapped for execution
|
2008-10-18 21:26:32 -06:00
|
|
|
*
|
|
|
|
* BDI_CAP_SWAP_BACKED: Count shmem/tmpfs objects as swap-backed.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2008-04-30 01:54:37 -06:00
|
|
|
#define BDI_CAP_NO_ACCT_DIRTY 0x00000001
|
|
|
|
#define BDI_CAP_NO_WRITEBACK 0x00000002
|
|
|
|
#define BDI_CAP_MAP_COPY 0x00000004
|
|
|
|
#define BDI_CAP_MAP_DIRECT 0x00000008
|
|
|
|
#define BDI_CAP_READ_MAP 0x00000010
|
|
|
|
#define BDI_CAP_WRITE_MAP 0x00000020
|
|
|
|
#define BDI_CAP_EXEC_MAP 0x00000040
|
|
|
|
#define BDI_CAP_NO_ACCT_WB 0x00000080
|
2008-10-18 21:26:32 -06:00
|
|
|
#define BDI_CAP_SWAP_BACKED 0x00000100
|
2008-04-30 01:54:37 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#define BDI_CAP_VMFLAGS \
|
|
|
|
(BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP)
|
|
|
|
|
2008-04-30 01:54:37 -06:00
|
|
|
#define BDI_CAP_NO_ACCT_AND_WRITEBACK \
|
|
|
|
(BDI_CAP_NO_WRITEBACK | BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_ACCT_WB)
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#if defined(VM_MAYREAD) && \
|
|
|
|
(BDI_CAP_READ_MAP != VM_MAYREAD || \
|
|
|
|
BDI_CAP_WRITE_MAP != VM_MAYWRITE || \
|
|
|
|
BDI_CAP_EXEC_MAP != VM_MAYEXEC)
|
|
|
|
#error please change backing_dev_info::capabilities flags
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern struct backing_dev_info default_backing_dev_info;
|
2010-04-25 00:54:42 -06:00
|
|
|
extern struct backing_dev_info noop_backing_dev_info;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
int writeback_in_progress(struct backing_dev_info *bdi);
|
|
|
|
|
|
|
|
static inline int bdi_congested(struct backing_dev_info *bdi, int bdi_bits)
|
|
|
|
{
|
|
|
|
if (bdi->congested_fn)
|
|
|
|
return bdi->congested_fn(bdi->congested_data, bdi_bits);
|
|
|
|
return (bdi->state & bdi_bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int bdi_read_congested(struct backing_dev_info *bdi)
|
|
|
|
{
|
2009-04-06 06:48:01 -06:00
|
|
|
return bdi_congested(bdi, 1 << BDI_sync_congested);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int bdi_write_congested(struct backing_dev_info *bdi)
|
|
|
|
{
|
2009-04-06 06:48:01 -06:00
|
|
|
return bdi_congested(bdi, 1 << BDI_async_congested);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int bdi_rw_congested(struct backing_dev_info *bdi)
|
|
|
|
{
|
2009-04-06 06:48:01 -06:00
|
|
|
return bdi_congested(bdi, (1 << BDI_sync_congested) |
|
|
|
|
(1 << BDI_async_congested));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-07-11 08:06:54 -06:00
|
|
|
enum {
|
|
|
|
BLK_RW_ASYNC = 0,
|
|
|
|
BLK_RW_SYNC = 1,
|
|
|
|
};
|
|
|
|
|
2009-07-09 06:52:32 -06:00
|
|
|
void clear_bdi_congested(struct backing_dev_info *bdi, int sync);
|
|
|
|
void set_bdi_congested(struct backing_dev_info *bdi, int sync);
|
|
|
|
long congestion_wait(int sync, long timeout);
|
2010-10-26 15:21:45 -06:00
|
|
|
long wait_iff_congested(struct zone *zone, int sync, long timeout);
|
2012-07-31 17:41:52 -06:00
|
|
|
int pdflush_proc_obsolete(struct ctl_table *table, int write,
|
|
|
|
void __user *buffer, size_t *lenp, loff_t *ppos);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-04-30 01:54:37 -06:00
|
|
|
static inline bool bdi_cap_writeback_dirty(struct backing_dev_info *bdi)
|
|
|
|
{
|
|
|
|
return !(bdi->capabilities & BDI_CAP_NO_WRITEBACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool bdi_cap_account_dirty(struct backing_dev_info *bdi)
|
|
|
|
{
|
|
|
|
return !(bdi->capabilities & BDI_CAP_NO_ACCT_DIRTY);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-04-30 01:54:37 -06:00
|
|
|
static inline bool bdi_cap_account_writeback(struct backing_dev_info *bdi)
|
|
|
|
{
|
|
|
|
/* Paranoia: BDI_CAP_NO_WRITEBACK implies BDI_CAP_NO_ACCT_WB */
|
|
|
|
return !(bdi->capabilities & (BDI_CAP_NO_ACCT_WB |
|
|
|
|
BDI_CAP_NO_WRITEBACK));
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-10-18 21:26:32 -06:00
|
|
|
static inline bool bdi_cap_swap_backed(struct backing_dev_info *bdi)
|
|
|
|
{
|
|
|
|
return bdi->capabilities & BDI_CAP_SWAP_BACKED;
|
|
|
|
}
|
|
|
|
|
2009-09-09 01:08:54 -06:00
|
|
|
static inline bool bdi_cap_flush_forker(struct backing_dev_info *bdi)
|
|
|
|
{
|
|
|
|
return bdi == &default_backing_dev_info;
|
|
|
|
}
|
|
|
|
|
2008-04-30 01:54:37 -06:00
|
|
|
static inline bool mapping_cap_writeback_dirty(struct address_space *mapping)
|
|
|
|
{
|
|
|
|
return bdi_cap_writeback_dirty(mapping->backing_dev_info);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-04-30 01:54:37 -06:00
|
|
|
static inline bool mapping_cap_account_dirty(struct address_space *mapping)
|
|
|
|
{
|
|
|
|
return bdi_cap_account_dirty(mapping->backing_dev_info);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-10-18 21:26:32 -06:00
|
|
|
static inline bool mapping_cap_swap_backed(struct address_space *mapping)
|
|
|
|
{
|
|
|
|
return bdi_cap_swap_backed(mapping->backing_dev_info);
|
|
|
|
}
|
|
|
|
|
2009-09-09 01:08:54 -06:00
|
|
|
static inline int bdi_sched_wait(void *word)
|
|
|
|
{
|
|
|
|
schedule();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif /* _LINUX_BACKING_DEV_H */
|