writeback: implement backing_dev_info->tot_write_bandwidth
authorTejun Heo <tj@kernel.org>
Fri, 22 May 2015 21:13:46 +0000 (17:13 -0400)
committerJens Axboe <axboe@fb.com>
Tue, 2 Jun 2015 14:33:35 +0000 (08:33 -0600)
cgroup writeback support needs to keep track of the sum of
avg_write_bandwidth of all wb's (bdi_writeback's) with dirty inodes to
distribute write workload.  This patch adds bdi->tot_write_bandwidth
and updates inode_wb_list_move_locked(), inode_wb_list_del_locked()
and wb_update_write_bandwidth() to adjust it as wb's gain and lose
dirty inodes and its avg_write_bandwidth gets updated.

As the update events are not synchronized with each other,
bdi->tot_write_bandwidth is an atomic_long_t.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@fb.com>
fs/fs-writeback.c
include/linux/backing-dev-defs.h
mm/page-writeback.c

index 0a90dc5577486eb8fc864247ee863466edcfa0e0..bbccf68b38dbd57ceb3ff601453f84fcc48130c7 100644 (file)
@@ -99,6 +99,8 @@ static bool wb_io_lists_populated(struct bdi_writeback *wb)
                return false;
        } else {
                set_bit(WB_has_dirty_io, &wb->state);
+               atomic_long_add(wb->avg_write_bandwidth,
+                               &wb->bdi->tot_write_bandwidth);
                return true;
        }
 }
@@ -106,8 +108,11 @@ static bool wb_io_lists_populated(struct bdi_writeback *wb)
 static void wb_io_lists_depopulated(struct bdi_writeback *wb)
 {
        if (wb_has_dirty_io(wb) && list_empty(&wb->b_dirty) &&
-           list_empty(&wb->b_io) && list_empty(&wb->b_more_io))
+           list_empty(&wb->b_io) && list_empty(&wb->b_more_io)) {
                clear_bit(WB_has_dirty_io, &wb->state);
+               atomic_long_sub(wb->avg_write_bandwidth,
+                               &wb->bdi->tot_write_bandwidth);
+       }
 }
 
 /**
index 7a94b7850b7c08e07e3615f2acdf2220e9e9458c..d631a61f40237bfde6f810447ad13d760aea63c1 100644 (file)
@@ -142,6 +142,8 @@ struct backing_dev_info {
        unsigned int min_ratio;
        unsigned int max_ratio, max_prop_frac;
 
+       atomic_long_t tot_write_bandwidth; /* sum of active avg_write_bw */
+
        struct bdi_writeback wb;  /* the root writeback info for this bdi */
        struct bdi_writeback_congested wb_congested; /* its congested state */
 #ifdef CONFIG_CGROUP_WRITEBACK
index e31dea94d116967409e50849d00d9b59e7ce2eac..c95eb24dd6525f94dd0b77bfdb2115a4a85d0e53 100644 (file)
@@ -881,6 +881,9 @@ static void wb_update_write_bandwidth(struct bdi_writeback *wb,
                avg += (old - avg) >> 3;
 
 out:
+       if (wb_has_dirty_io(wb))
+               atomic_long_add(avg - wb->avg_write_bandwidth,
+                               &wb->bdi->tot_write_bandwidth);
        wb->write_bandwidth = bw;
        wb->avg_write_bandwidth = avg;
 }