lkml.org 
[lkml]   [2016]   [Nov]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH V4 15/15] blk-throttle: add latency target support
Date
One hard problem adding .high limit is to detect idle cgroup. If one
cgroup doesn't dispatch enough IO against its high limit, we must have a
mechanism to determine if other cgroups dispatch more IO. We added the
think time detection mechanism before, but it doesn't work for all
workloads. Here we add a latency based approach.

We calculate the average request size and average latency of a cgroup.
Then we can calculate the target latency for the cgroup with the average
request size and the equation. In queue LIMIT_HIGH state, if a cgroup
doesn't dispatch enough IO against high limit but its average latency is
lower than its target latency, we treat the cgroup idle. In this case
other cgroups can dispatch more IO, eg, across their high limit.
Similarly in queue LIMIT_MAX state, if a cgroup doesn't dispatch enough
IO but its average latency is higher than its target latency, we treat
the cgroup busy. In this case, we should throttle other cgroups to make
the first cgroup's latency lower.

If cgroup's average request size is big (currently sets to 128k), we
always treat the cgroup busy (the think time check is still effective
though).

Currently this latency target check is only for SSD as we can't
calcualte the latency target for hard disk. And this is only for cgroup
leaf node so far.

Signed-off-by: Shaohua Li <shli@fb.com>
---
block/blk-throttle.c | 58 ++++++++++++++++++++++++++++++++++++++++++++---
include/linux/blk_types.h | 1 +
2 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index ac4d9ea..d07f332 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -156,6 +156,12 @@ struct throtl_grp {
u64 last_finish_time;
u64 checked_last_finish_time;
u64 avg_ttime;
+
+ unsigned int bio_batch;
+ u64 total_latency;
+ u64 avg_latency;
+ u64 total_size;
+ u64 avg_size;
};

/* We measure latency for request size from 4k to 4k * ( 1 << 4) */
@@ -1734,12 +1740,30 @@ static unsigned long tg_last_high_overflow_time(struct throtl_grp *tg)
return ret;
}

+static u64 throtl_target_latency(struct throtl_data *td,
+ struct throtl_grp *tg)
+{
+ if (td->line_slope == 0 || tg->latency_target == 0)
+ return 0;
+
+ /* latency_target + f(avg_size) - f(4k) */
+ return td->line_slope * ((tg->avg_size >> 10) - 4) +
+ tg->latency_target;
+}
+
static bool throtl_tg_is_idle(struct throtl_grp *tg)
{
- /* cgroup is idle if average think time is more than threshold */
- return ktime_get_ns() - tg->last_finish_time >
+ /*
+ * cgroup is idle if:
+ * 1. average think time is higher than threshold
+ * 2. average request size is small and average latency is higher
+ * than target
+ */
+ return (ktime_get_ns() - tg->last_finish_time >
4 * tg->td->idle_ttime_threshold ||
- tg->avg_ttime > tg->td->idle_ttime_threshold;
+ tg->avg_ttime > tg->td->idle_ttime_threshold) ||
+ (tg->avg_latency && tg->avg_size && tg->avg_size <= 128 * 1024 &&
+ tg->avg_latency < throtl_target_latency(tg->td, tg));
}

static bool throtl_upgrade_check_one(struct throtl_grp *tg)
@@ -2123,6 +2147,7 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
bio_associate_current(bio);
bio->bi_cg_private = q;
bio->bi_cg_size = bio_sectors(bio);
+ bio->bi_cg_enter_time = ktime_get_ns();

blk_throtl_update_ttime(tg);

@@ -2264,6 +2289,33 @@ void blk_throtl_bio_endio(struct bio *bio)
}
}

+ if (bio->bi_cg_enter_time && finish_time > bio->bi_cg_enter_time &&
+ tg->latency_target) {
+ lat = finish_time - bio->bi_cg_enter_time;
+ tg->total_latency += lat;
+ tg->total_size += bio->bi_cg_size << 9;
+ tg->bio_batch++;
+ }
+
+ if (tg->bio_batch >= 8) {
+ int batch = tg->bio_batch;
+ u64 size = tg->total_size;
+
+ lat = tg->total_latency;
+
+ tg->bio_batch = 0;
+ tg->total_latency = 0;
+ tg->total_size = 0;
+
+ if (batch) {
+ do_div(lat, batch);
+ tg->avg_latency = (tg->avg_latency * 7 +
+ lat) >> 3;
+ do_div(size, batch);
+ tg->avg_size = (tg->avg_size * 7 + size) >> 3;
+ }
+ }
+
end:
rcu_read_unlock();
}
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 45bb437..fe87a20 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -61,6 +61,7 @@ struct bio {
struct cgroup_subsys_state *bi_css;
void *bi_cg_private;
u64 bi_cg_issue_time;
+ u64 bi_cg_enter_time;
sector_t bi_cg_size;
#endif
union {
--
2.9.3
\
 
 \ /
  Last update: 2016-11-14 23:24    [W:0.360 / U:0.228 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site