From: Tejun Heo <tj@kernel.org>
To: axboe@kernel.dk
Cc: linux-kernel@vger.kernel.org, jack@suse.cz, hch@infradead.org,
hannes@cmpxchg.org, linux-fsdevel@vger.kernel.org,
vgoyal@redhat.com, lizefan@huawei.com, cgroups@vger.kernel.org,
linux-mm@kvack.org, mhocko@suse.cz, clm@fb.com,
fengguang.wu@intel.com, david@fromorbit.com, gthelen@google.com,
Tejun Heo <tj@kernel.org>
Subject: [PATCH 32/49] writeback: make bdi_has_dirty_io() take multiple bdi_writeback's into account
Date: Mon, 6 Apr 2015 15:58:21 -0400 [thread overview]
Message-ID: <1428350318-8215-33-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1428350318-8215-1-git-send-email-tj@kernel.org>
bdi_has_dirty_io() used to only reflect whether the root wb
(bdi_writeback) has dirty inodes. For cgroup writeback support, it
needs to take all active wb's into account. If any wb on the bdi has
dirty inodes, bdi_has_dirty_io() should return true.
To achieve that, as inode_wb_list_{move|del}_locked() now keep track
of the dirty state transition of each wb, the number of dirty wbs can
be counted in the bdi; however, bdi is already aggregating
wb->avg_write_bandwidth which can easily be guaranteed to be > 0 when
there are any dirty inodes by ensuring wb->avg_write_bandwidth can't
dip below 1. bdi_has_dirty_io() can simply test whether
bdi->tot_write_bandwidth is zero or not.
While this bumps the value of wb->avg_write_bandwidth to one when it
used to be zero, this shouldn't cause any meaningful behavior
difference.
bdi_has_dirty_io() is made an inline function which tests whether
->tot_write_bandwidth is non-zero. Also, WARN_ON_ONCE()'s on its
value are added to inode_wb_list_{move|del}_locked().
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Jan Kara <jack@suse.cz>
---
fs/fs-writeback.c | 5 +++--
include/linux/backing-dev-defs.h | 8 ++++++--
include/linux/backing-dev.h | 10 +++++++++-
mm/backing-dev.c | 5 -----
mm/page-writeback.c | 10 +++++++---
5 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 590c3ba..5df1bc7 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -87,6 +87,7 @@ static bool wb_io_lists_populated(struct bdi_writeback *wb)
return false;
} else {
set_bit(WB_has_dirty_io, &wb->state);
+ WARN_ON_ONCE(!wb->avg_write_bandwidth);
atomic_long_add(wb->avg_write_bandwidth,
&wb->bdi->tot_write_bandwidth);
return true;
@@ -98,8 +99,8 @@ 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)) {
clear_bit(WB_has_dirty_io, &wb->state);
- atomic_long_sub(wb->avg_write_bandwidth,
- &wb->bdi->tot_write_bandwidth);
+ WARN_ON_ONCE(atomic_long_sub_return(wb->avg_write_bandwidth,
+ &wb->bdi->tot_write_bandwidth) < 0);
}
}
diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h
index d631a61..8c857d7 100644
--- a/include/linux/backing-dev-defs.h
+++ b/include/linux/backing-dev-defs.h
@@ -98,7 +98,7 @@ struct bdi_writeback {
unsigned long dirtied_stamp;
unsigned long written_stamp; /* pages written at bw_time_stamp */
unsigned long write_bandwidth; /* the estimated write bandwidth */
- unsigned long avg_write_bandwidth; /* further smoothed write bw */
+ unsigned long avg_write_bandwidth; /* further smoothed write bw, > 0 */
/*
* The base dirty throttle rate, re-calculated on every 200ms.
@@ -142,7 +142,11 @@ 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 */
+ /*
+ * Sum of avg_write_bw of wbs with dirty inodes. > 0 if there are
+ * any dirty wbs, which is depended upon by bdi_has_dirty().
+ */
+ atomic_long_t tot_write_bandwidth;
struct bdi_writeback wb; /* the root writeback info for this bdi */
struct bdi_writeback_congested wb_congested; /* its congested state */
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index 3c8403c..0839e44 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -29,7 +29,6 @@ void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
enum wb_reason reason);
void bdi_start_background_writeback(struct backing_dev_info *bdi);
void wb_workfn(struct work_struct *work);
-bool bdi_has_dirty_io(struct backing_dev_info *bdi);
void wb_wakeup_delayed(struct bdi_writeback *wb);
extern spinlock_t bdi_lock;
@@ -42,6 +41,15 @@ static inline bool wb_has_dirty_io(struct bdi_writeback *wb)
return test_bit(WB_has_dirty_io, &wb->state);
}
+static inline bool bdi_has_dirty_io(struct backing_dev_info *bdi)
+{
+ /*
+ * @bdi->tot_write_bandwidth is guaranteed to be > 0 if there are
+ * any dirty wbs. See wb_update_write_bandwidth().
+ */
+ return atomic_long_read(&bdi->tot_write_bandwidth);
+}
+
static inline void __add_wb_stat(struct bdi_writeback *wb,
enum wb_stat_item item, s64 amount)
{
diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index 161ddf1..d2f16fc9 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -256,11 +256,6 @@ static int __init default_bdi_init(void)
}
subsys_initcall(default_bdi_init);
-bool bdi_has_dirty_io(struct backing_dev_info *bdi)
-{
- return wb_has_dirty_io(&bdi->wb);
-}
-
/*
* This function is used when the first inode for this wb is marked dirty. It
* wakes-up the corresponding bdi thread which should then take care of the
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 26c72e4..ba2b83d 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -881,9 +881,13 @@ 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);
+ /* keep avg > 0 to guarantee that tot > 0 if there are dirty wbs */
+ avg = max(avg, 1LU);
+ if (wb_has_dirty_io(wb)) {
+ long delta = avg - wb->avg_write_bandwidth;
+ WARN_ON_ONCE(atomic_long_add_return(delta,
+ &wb->bdi->tot_write_bandwidth) <= 0);
+ }
wb->write_bandwidth = bw;
wb->avg_write_bandwidth = avg;
}
--
2.1.0
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-04-06 19:58 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-06 19:57 [PATCHSET 1/3 v3 block/for-4.1/core] writeback: cgroup writeback support Tejun Heo
2015-04-06 19:57 ` [PATCH 01/49] memcg: add per cgroup dirty page accounting Tejun Heo
2015-04-06 19:57 ` [PATCH 02/49] blkcg: move block/blk-cgroup.h to include/linux/blk-cgroup.h Tejun Heo
2015-04-06 19:57 ` [PATCH 03/49] update !CONFIG_BLK_CGROUP dummies in include/linux/blk-cgroup.h Tejun Heo
2015-04-06 19:57 ` [PATCH 04/49] blkcg: always create the blkcg_gq for the root blkcg Tejun Heo
2015-04-06 19:57 ` [PATCH 05/49] memcg: add mem_cgroup_root_css Tejun Heo
2015-04-06 19:57 ` [PATCH 06/49] blkcg: add blkcg_root_css Tejun Heo
2015-04-06 19:57 ` [PATCH 07/49] cgroup, block: implement task_get_css() and use it in bio_associate_current() Tejun Heo
2015-04-06 19:57 ` [PATCH 08/49] blkcg: implement task_get_blkcg_css() Tejun Heo
2015-04-06 19:57 ` [PATCH 09/49] blkcg: implement bio_associate_blkcg() Tejun Heo
2015-04-06 19:57 ` [PATCH 10/49] memcg: implement mem_cgroup_css_from_page() Tejun Heo
2015-04-06 19:58 ` [PATCH 11/49] writeback: move backing_dev_info->state into bdi_writeback Tejun Heo
2015-04-20 15:32 ` Jan Kara
2015-04-06 19:58 ` [PATCH 12/49] writeback: move backing_dev_info->bdi_stat[] " Tejun Heo
2015-04-20 15:02 ` Jan Kara
[not found] ` <20150420150231.GA17020-+0h/O2h83AeN3ZZ/Hiejyg@public.gmane.org>
2015-04-20 17:56 ` Tejun Heo
[not found] ` <20150420175626.GB4206-piEFEHQLUPpN0TnZuCh8vA@public.gmane.org>
2015-04-21 8:51 ` Jan Kara
2015-04-21 15:02 ` Tejun Heo
[not found] ` <20150421150229.GA9455-piEFEHQLUPpN0TnZuCh8vA@public.gmane.org>
2015-04-21 15:05 ` Jan Kara
2015-04-06 19:58 ` [PATCH 13/49] writeback: move bandwidth related fields from backing_dev_info " Tejun Heo
2015-04-20 15:09 ` Jan Kara
2015-04-20 18:01 ` Tejun Heo
2015-04-06 19:58 ` [PATCH 14/49] writeback: s/bdi/wb/ in mm/page-writeback.c Tejun Heo
2015-04-20 15:18 ` Jan Kara
2015-04-06 19:58 ` [PATCH 15/49] writeback: move backing_dev_info->wb_lock and ->worklist into bdi_writeback Tejun Heo
[not found] ` <1428350318-8215-16-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-04-20 15:32 ` Jan Kara
2015-04-20 18:17 ` Tejun Heo
[not found] ` <20150420181707.GD4206-piEFEHQLUPpN0TnZuCh8vA@public.gmane.org>
2015-04-21 8:59 ` Jan Kara
2015-04-06 19:58 ` [PATCH 16/49] writeback: reorganize mm/backing-dev.c Tejun Heo
[not found] ` <1428350318-8215-17-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-04-20 15:34 ` Jan Kara
2015-04-06 19:58 ` [PATCH 17/49] writeback: separate out include/linux/backing-dev-defs.h Tejun Heo
2015-04-20 15:37 ` Jan Kara
2015-04-06 19:58 ` [PATCH 18/49] bdi: make inode_to_bdi() inline Tejun Heo
[not found] ` <1428350318-8215-19-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-04-20 15:40 ` Jan Kara
2015-04-20 18:21 ` Tejun Heo
2015-04-06 19:58 ` [PATCH 19/49] writeback: add @gfp to wb_init() Tejun Heo
2015-04-20 15:41 ` Jan Kara
2015-04-06 19:58 ` [PATCH 20/49] bdi: separate out congested state into a separate struct Tejun Heo
2015-04-21 14:36 ` Jan Kara
2015-04-06 19:58 ` [PATCH 21/49] writeback: add {CONFIG|BDI_CAP|FS}_CGROUP_WRITEBACK Tejun Heo
2015-04-06 19:58 ` [PATCH 22/49] writeback: make backing_dev_info host cgroup-specific bdi_writebacks Tejun Heo
2015-04-06 19:58 ` [PATCH 23/49] writeback, blkcg: associate each blkcg_gq with the corresponding bdi_writeback_congested Tejun Heo
2015-04-06 19:58 ` [PATCH 24/49] writeback: attribute stats to the matching per-cgroup bdi_writeback Tejun Heo
[not found] ` <1428350318-8215-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-04-06 19:58 ` [PATCH 25/49] writeback: let balance_dirty_pages() work on the matching cgroup bdi_writeback Tejun Heo
2015-04-06 19:58 ` [PATCH 26/49] writeback: make congestion functions per bdi_writeback Tejun Heo
2015-04-06 19:58 ` [PATCH 27/49] writeback, blkcg: restructure blk_{set|clear}_queue_congested() Tejun Heo
2015-04-06 19:58 ` [PATCH 28/49] writeback, blkcg: propagate non-root blkcg congestion state Tejun Heo
2015-04-06 19:58 ` [PATCH 29/49] writeback: implement and use inode_congested() Tejun Heo
2015-04-06 19:58 ` [PATCH 30/49] writeback: implement WB_has_dirty_io wb_state flag Tejun Heo
2015-04-06 19:58 ` [PATCH 31/49] writeback: implement backing_dev_info->tot_write_bandwidth Tejun Heo
2015-04-06 19:58 ` Tejun Heo [this message]
2015-04-06 19:58 ` [PATCH 33/49] writeback: don't issue wb_writeback_work if clean Tejun Heo
2015-04-06 19:58 ` [PATCH 34/49] writeback: make bdi->min/max_ratio handling cgroup writeback aware Tejun Heo
2015-04-06 19:58 ` [PATCH 35/49] writeback: implement bdi_for_each_wb() Tejun Heo
2015-04-06 19:58 ` [PATCH 36/49] writeback: remove bdi_start_writeback() Tejun Heo
2015-04-06 19:58 ` [PATCH 37/49] writeback: make laptop_mode_timer_fn() handle multiple bdi_writeback's Tejun Heo
2015-04-06 19:58 ` [PATCH 38/49] writeback: make writeback_in_progress() take bdi_writeback instead of backing_dev_info Tejun Heo
2015-04-06 19:58 ` [PATCH 39/49] writeback: make bdi_start_background_writeback() " Tejun Heo
2015-04-06 19:58 ` [PATCH 40/49] writeback: make wakeup_flusher_threads() handle multiple bdi_writeback's Tejun Heo
2015-04-06 19:58 ` [PATCH 41/49] writeback: add wb_writeback_work->auto_free Tejun Heo
2015-04-06 19:58 ` [PATCH 42/49] writeback: implement bdi_wait_for_completion() Tejun Heo
2015-04-06 19:58 ` [PATCH 43/49] writeback: implement wb_wait_for_single_work() Tejun Heo
2015-04-06 19:58 ` [PATCH 44/49] writeback: restructure try_writeback_inodes_sb[_nr]() Tejun Heo
2015-04-06 19:58 ` [PATCH 45/49] writeback: make writeback initiation functions handle multiple bdi_writeback's Tejun Heo
2015-04-06 19:58 ` [PATCH 46/49] writeback: dirty inodes against their matching cgroup bdi_writeback's Tejun Heo
2015-04-06 19:58 ` [PATCH 47/49] buffer, writeback: make __block_write_full_page() honor cgroup writeback Tejun Heo
2015-04-06 19:58 ` [PATCH 48/49] mpage: make __mpage_writepage() " Tejun Heo
2015-04-06 19:58 ` [PATCH 49/49] ext2: enable cgroup writeback support Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1428350318-8215-33-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=clm@fb.com \
--cc=david@fromorbit.com \
--cc=fengguang.wu@intel.com \
--cc=gthelen@google.com \
--cc=hannes@cmpxchg.org \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan@huawei.com \
--cc=mhocko@suse.cz \
--cc=vgoyal@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).