2 #include <linux/wait.h>
3 #include <linux/backing-dev.h>
5 #include <linux/sched.h>
6 #include <linux/module.h>
8 static wait_queue_head_t congestion_wqh
[2] = {
9 __WAIT_QUEUE_HEAD_INITIALIZER(congestion_wqh
[0]),
10 __WAIT_QUEUE_HEAD_INITIALIZER(congestion_wqh
[1])
14 void clear_bdi_congested(struct backing_dev_info
*bdi
, int rw
)
17 wait_queue_head_t
*wqh
= &congestion_wqh
[rw
];
19 bit
= (rw
== WRITE
) ? BDI_write_congested
: BDI_read_congested
;
20 clear_bit(bit
, &bdi
->state
);
21 smp_mb__after_clear_bit();
22 if (waitqueue_active(wqh
))
25 EXPORT_SYMBOL(clear_bdi_congested
);
27 void set_bdi_congested(struct backing_dev_info
*bdi
, int rw
)
31 bit
= (rw
== WRITE
) ? BDI_write_congested
: BDI_read_congested
;
32 set_bit(bit
, &bdi
->state
);
34 EXPORT_SYMBOL(set_bdi_congested
);
37 * congestion_wait - wait for a backing_dev to become uncongested
39 * @timeout: timeout in jiffies
41 * Waits for up to @timeout jiffies for a backing_dev (any backing_dev) to exit
42 * write congestion. If no backing_devs are congested then just wait for the
43 * next write to be completed.
45 long congestion_wait(int rw
, long timeout
)
49 wait_queue_head_t
*wqh
= &congestion_wqh
[rw
];
51 prepare_to_wait(wqh
, &wait
, TASK_UNINTERRUPTIBLE
);
52 ret
= io_schedule_timeout(timeout
);
53 finish_wait(wqh
, &wait
);
56 EXPORT_SYMBOL(congestion_wait
);
59 * congestion_end - wake up sleepers on a congested backing_dev_info
62 void congestion_end(int rw
)
64 wait_queue_head_t
*wqh
= &congestion_wqh
[rw
];
66 if (waitqueue_active(wqh
))
69 EXPORT_SYMBOL(congestion_end
);