2 #include <linux/wait.h>
3 #include <linux/backing-dev.h>
5 #include <linux/sched.h>
6 #include <linux/module.h>
8 int bdi_init(struct backing_dev_info
*bdi
)
13 for (i
= 0; i
< NR_BDI_STAT_ITEMS
; i
++) {
14 err
= percpu_counter_init_irq(&bdi
->bdi_stat
[i
], 0);
19 bdi
->dirty_exceeded
= 0;
20 err
= prop_local_init_percpu(&bdi
->completions
);
25 percpu_counter_destroy(&bdi
->bdi_stat
[i
]);
30 EXPORT_SYMBOL(bdi_init
);
32 void bdi_destroy(struct backing_dev_info
*bdi
)
36 for (i
= 0; i
< NR_BDI_STAT_ITEMS
; i
++)
37 percpu_counter_destroy(&bdi
->bdi_stat
[i
]);
39 prop_local_destroy_percpu(&bdi
->completions
);
41 EXPORT_SYMBOL(bdi_destroy
);
43 static wait_queue_head_t congestion_wqh
[2] = {
44 __WAIT_QUEUE_HEAD_INITIALIZER(congestion_wqh
[0]),
45 __WAIT_QUEUE_HEAD_INITIALIZER(congestion_wqh
[1])
49 void clear_bdi_congested(struct backing_dev_info
*bdi
, int rw
)
52 wait_queue_head_t
*wqh
= &congestion_wqh
[rw
];
54 bit
= (rw
== WRITE
) ? BDI_write_congested
: BDI_read_congested
;
55 clear_bit(bit
, &bdi
->state
);
56 smp_mb__after_clear_bit();
57 if (waitqueue_active(wqh
))
60 EXPORT_SYMBOL(clear_bdi_congested
);
62 void set_bdi_congested(struct backing_dev_info
*bdi
, int rw
)
66 bit
= (rw
== WRITE
) ? BDI_write_congested
: BDI_read_congested
;
67 set_bit(bit
, &bdi
->state
);
69 EXPORT_SYMBOL(set_bdi_congested
);
72 * congestion_wait - wait for a backing_dev to become uncongested
74 * @timeout: timeout in jiffies
76 * Waits for up to @timeout jiffies for a backing_dev (any backing_dev) to exit
77 * write congestion. If no backing_devs are congested then just wait for the
78 * next write to be completed.
80 long congestion_wait(int rw
, long timeout
)
84 wait_queue_head_t
*wqh
= &congestion_wqh
[rw
];
86 prepare_to_wait(wqh
, &wait
, TASK_UNINTERRUPTIBLE
);
87 ret
= io_schedule_timeout(timeout
);
88 finish_wait(wqh
, &wait
);
91 EXPORT_SYMBOL(congestion_wait
);