Skip to content

Commit

Permalink
cgroup: blkio: adjust block io bps limit by weight
Browse files Browse the repository at this point in the history
Kernel now supports cgroup bps and iops hard limit by io-throttling.
But that's not a scalable way, because block devices' bandwith is
always changing over time.

This patch dynamically adjusts bps limit of each blkio cgroup according
to its pre-set weight. Additionally, if a process has not issued any io
request during a time window, its weight will be shared by other processes
until its next io request.

Signed-off-by: Lei Chen <lennychen@tencent.com>
  • Loading branch information
Lei Chen committed Mar 11, 2020
1 parent c18a297 commit e8be225
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 11 deletions.
25 changes: 23 additions & 2 deletions block/blk-core.c
Expand Up @@ -1514,6 +1514,19 @@ static void part_round_stats_single(struct request_queue *q, int cpu,
part->stamp = now;
}

static void part_round_stats_single_ns(struct request_queue *q, int cpu,
struct hd_struct *part, u64 now,
unsigned int inflight)
{
if (now == part->stamp_ns)
return;

if (inflight)
__part_stat_add(cpu, part, io_ticks_ns, (now - part->stamp_ns));
part->stamp_ns = now;
}


/**
* part_round_stats() - Round off the performance stats on a struct disk_stats.
* @q: target block queue
Expand All @@ -1537,6 +1550,7 @@ void part_round_stats(struct request_queue *q, int cpu, struct hd_struct *part)
unsigned long now = jiffies;
unsigned int inflight[2];
int stats = 0;
u64 now_ns = ktime_to_ns(ktime_get());

if (part->stamp != now)
stats |= 1;
Expand All @@ -1552,10 +1566,17 @@ void part_round_stats(struct request_queue *q, int cpu, struct hd_struct *part)

part_in_flight(q, part, inflight);

if (stats & 2)
if (stats & 2) {
/*for sda1 sda2 sda3*/
part_round_stats_single(q, cpu, part2, now, inflight[1]);
if (stats & 1)
part_round_stats_single_ns(q, cpu, part2, now_ns, inflight[1]);
}

if (stats & 1) {
/*for sda*/
part_round_stats_single(q, cpu, part, now, inflight[0]);
part_round_stats_single_ns(q, cpu, part, now_ns, inflight[0]);
}
}
EXPORT_SYMBOL_GPL(part_round_stats);

Expand Down
12 changes: 12 additions & 0 deletions block/blk-sysfs.c
Expand Up @@ -364,6 +364,17 @@ queue_rq_affinity_store(struct request_queue *q, const char *page, size_t count)
return ret;
}

static ssize_t queue_avg_perf_show(struct request_queue *q, char *page)
{
return sprintf(page, "%llu\n",
(unsigned long long)q->disk_bw * 512);
}

static struct queue_sysfs_entry queue_avg_perf_entry = {
.attr = {.name = "average_perf", .mode = S_IRUGO },
.show = queue_avg_perf_show,
};

static ssize_t queue_poll_delay_show(struct request_queue *q, char *page)
{
int val;
Expand Down Expand Up @@ -688,6 +699,7 @@ static struct queue_sysfs_entry throtl_sample_time_entry = {
#endif

static struct attribute *default_attrs[] = {
&queue_avg_perf_entry.attr,
&queue_requests_entry.attr,
&queue_ra_entry.attr,
&queue_max_hw_sectors_entry.attr,
Expand Down

0 comments on commit e8be225

Please sign in to comment.