Skip to content

Commit 4aa9c69

Browse files
htejunaxboe
authored andcommitted
bdi: separate out congested state into a separate struct
Currently, a wb's (bdi_writeback) congestion state is carried in its ->state field; however, cgroup writeback support will require multiple wb's sharing the same congestion state. This patch separates out congestion state into its own struct - struct bdi_writeback_congested. A new field wb field, wb_congested, points to its associated congested struct. The default wb, bdi->wb, always points to bdi->wb_congested. While this patch adds a layer of indirection, it doesn't introduce any behavior changes. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 8395cd9 commit 4aa9c69

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

include/linux/backing-dev-defs.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ struct dentry;
1616
* Bits in bdi_writeback.state
1717
*/
1818
enum wb_state {
19-
WB_async_congested, /* The async (write) queue is getting full */
20-
WB_sync_congested, /* The sync queue is getting full */
2119
WB_registered, /* bdi_register() was done */
2220
WB_writeback_running, /* Writeback is in progress */
2321
};
2422

23+
enum wb_congested_state {
24+
WB_async_congested, /* The async (write) queue is getting full */
25+
WB_sync_congested, /* The sync queue is getting full */
26+
};
27+
2528
typedef int (congested_fn)(void *, int);
2629

2730
enum wb_stat_item {
@@ -34,6 +37,10 @@ enum wb_stat_item {
3437

3538
#define WB_STAT_BATCH (8*(1+ilog2(nr_cpu_ids)))
3639

40+
struct bdi_writeback_congested {
41+
unsigned long state; /* WB_[a]sync_congested flags */
42+
};
43+
3744
struct bdi_writeback {
3845
struct backing_dev_info *bdi; /* our parent bdi */
3946

@@ -48,6 +55,8 @@ struct bdi_writeback {
4855

4956
struct percpu_counter stat[NR_WB_STAT_ITEMS];
5057

58+
struct bdi_writeback_congested *congested;
59+
5160
unsigned long bw_time_stamp; /* last time write bw is updated */
5261
unsigned long dirtied_stamp;
5362
unsigned long written_stamp; /* pages written at bw_time_stamp */
@@ -84,6 +93,7 @@ struct backing_dev_info {
8493
unsigned int max_ratio, max_prop_frac;
8594

8695
struct bdi_writeback wb; /* default writeback info for this bdi */
96+
struct bdi_writeback_congested wb_congested;
8797

8898
struct device *dev;
8999

include/linux/backing-dev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static inline int bdi_congested(struct backing_dev_info *bdi, int bdi_bits)
167167
{
168168
if (bdi->congested_fn)
169169
return bdi->congested_fn(bdi->congested_data, bdi_bits);
170-
return (bdi->wb.state & bdi_bits);
170+
return (bdi->wb.congested->state & bdi_bits);
171171
}
172172

173173
static inline int bdi_read_congested(struct backing_dev_info *bdi)

mm/backing-dev.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ int bdi_init(struct backing_dev_info *bdi)
383383
if (err)
384384
return err;
385385

386+
bdi->wb_congested.state = 0;
387+
bdi->wb.congested = &bdi->wb_congested;
388+
386389
return 0;
387390
}
388391
EXPORT_SYMBOL(bdi_init);
@@ -504,7 +507,7 @@ void clear_bdi_congested(struct backing_dev_info *bdi, int sync)
504507
wait_queue_head_t *wqh = &congestion_wqh[sync];
505508

506509
bit = sync ? WB_sync_congested : WB_async_congested;
507-
if (test_and_clear_bit(bit, &bdi->wb.state))
510+
if (test_and_clear_bit(bit, &bdi->wb.congested->state))
508511
atomic_dec(&nr_bdi_congested[sync]);
509512
smp_mb__after_atomic();
510513
if (waitqueue_active(wqh))
@@ -517,7 +520,7 @@ void set_bdi_congested(struct backing_dev_info *bdi, int sync)
517520
enum wb_state bit;
518521

519522
bit = sync ? WB_sync_congested : WB_async_congested;
520-
if (!test_and_set_bit(bit, &bdi->wb.state))
523+
if (!test_and_set_bit(bit, &bdi->wb.congested->state))
521524
atomic_inc(&nr_bdi_congested[sync]);
522525
}
523526
EXPORT_SYMBOL(set_bdi_congested);

0 commit comments

Comments
 (0)