RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / mm / backing-dev.c
blob8fd767bd013a107f937efc8a5230aa3f314dfb70
2 #include <linux/wait.h>
3 #include <linux/backing-dev.h>
4 #include <linux/fs.h>
5 #include <linux/sched.h>
6 #include <linux/module.h>
8 int bdi_init(struct backing_dev_info *bdi)
10 int i;
11 int err;
13 for (i = 0; i < NR_BDI_STAT_ITEMS; i++) {
14 percpu_counter_init(&bdi->bdi_stat[i], 0);
17 bdi->dirty_exceeded = 0;
18 err = prop_local_init_percpu(&bdi->completions);
21 return err;
23 EXPORT_SYMBOL(bdi_init);
25 void bdi_destroy(struct backing_dev_info *bdi)
27 int i;
29 for (i = 0; i < NR_BDI_STAT_ITEMS; i++)
30 percpu_counter_destroy(&bdi->bdi_stat[i]);
32 prop_local_destroy_percpu(&bdi->completions);
34 EXPORT_SYMBOL(bdi_destroy);
36 static wait_queue_head_t congestion_wqh[2] = {
37 __WAIT_QUEUE_HEAD_INITIALIZER(congestion_wqh[0]),
38 __WAIT_QUEUE_HEAD_INITIALIZER(congestion_wqh[1])
42 void clear_bdi_congested(struct backing_dev_info *bdi, int rw)
44 enum bdi_state bit;
45 wait_queue_head_t *wqh = &congestion_wqh[rw];
47 bit = (rw == WRITE) ? BDI_write_congested : BDI_read_congested;
48 clear_bit(bit, &bdi->state);
49 smp_mb__after_clear_bit();
50 if (waitqueue_active(wqh))
51 wake_up(wqh);
53 EXPORT_SYMBOL(clear_bdi_congested);
55 void set_bdi_congested(struct backing_dev_info *bdi, int rw)
57 enum bdi_state bit;
59 bit = (rw == WRITE) ? BDI_write_congested : BDI_read_congested;
60 set_bit(bit, &bdi->state);
62 EXPORT_SYMBOL(set_bdi_congested);
64 /**
65 * congestion_wait - wait for a backing_dev to become uncongested
66 * @rw: READ or WRITE
67 * @timeout: timeout in jiffies
69 * Waits for up to @timeout jiffies for a backing_dev (any backing_dev) to exit
70 * write congestion. If no backing_devs are congested then just wait for the
71 * next write to be completed.
73 long congestion_wait(int rw, long timeout)
75 long ret;
76 DEFINE_WAIT(wait);
77 wait_queue_head_t *wqh = &congestion_wqh[rw];
79 prepare_to_wait(wqh, &wait, TASK_UNINTERRUPTIBLE);
80 ret = io_schedule_timeout(timeout);
81 finish_wait(wqh, &wait);
82 return ret;
84 EXPORT_SYMBOL(congestion_wait);