Skip to content

Commit

Permalink
bdi: separate out congested state into a separate struct
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Tejun Heo authored and Jens Axboe committed Jun 2, 2015
1 parent 8395cd9 commit 4aa9c69
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 12 additions & 2 deletions include/linux/backing-dev-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ struct dentry;
* Bits in bdi_writeback.state
*/
enum wb_state {
WB_async_congested, /* The async (write) queue is getting full */
WB_sync_congested, /* The sync queue is getting full */
WB_registered, /* bdi_register() was done */
WB_writeback_running, /* Writeback is in progress */
};

enum wb_congested_state {
WB_async_congested, /* The async (write) queue is getting full */
WB_sync_congested, /* The sync queue is getting full */
};

typedef int (congested_fn)(void *, int);

enum wb_stat_item {
Expand All @@ -34,6 +37,10 @@ enum wb_stat_item {

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

struct bdi_writeback_congested {
unsigned long state; /* WB_[a]sync_congested flags */
};

struct bdi_writeback {
struct backing_dev_info *bdi; /* our parent bdi */

Expand All @@ -48,6 +55,8 @@ struct bdi_writeback {

struct percpu_counter stat[NR_WB_STAT_ITEMS];

struct bdi_writeback_congested *congested;

unsigned long bw_time_stamp; /* last time write bw is updated */
unsigned long dirtied_stamp;
unsigned long written_stamp; /* pages written at bw_time_stamp */
Expand Down Expand Up @@ -84,6 +93,7 @@ struct backing_dev_info {
unsigned int max_ratio, max_prop_frac;

struct bdi_writeback wb; /* default writeback info for this bdi */
struct bdi_writeback_congested wb_congested;

struct device *dev;

Expand Down
2 changes: 1 addition & 1 deletion include/linux/backing-dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ 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->wb.state & bdi_bits);
return (bdi->wb.congested->state & bdi_bits);
}

static inline int bdi_read_congested(struct backing_dev_info *bdi)
Expand Down
7 changes: 5 additions & 2 deletions mm/backing-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ int bdi_init(struct backing_dev_info *bdi)
if (err)
return err;

bdi->wb_congested.state = 0;
bdi->wb.congested = &bdi->wb_congested;

return 0;
}
EXPORT_SYMBOL(bdi_init);
Expand Down Expand Up @@ -504,7 +507,7 @@ void clear_bdi_congested(struct backing_dev_info *bdi, int sync)
wait_queue_head_t *wqh = &congestion_wqh[sync];

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

bit = sync ? WB_sync_congested : WB_async_congested;
if (!test_and_set_bit(bit, &bdi->wb.state))
if (!test_and_set_bit(bit, &bdi->wb.congested->state))
atomic_inc(&nr_bdi_congested[sync]);
}
EXPORT_SYMBOL(set_bdi_congested);
Expand Down

0 comments on commit 4aa9c69

Please sign in to comment.