From: Vivek Goyal <vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Hong Zhiguo <honkiko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Hong Zhiguo <zhiguohong-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org>
Subject: Re: [PATCH v3] blk-throttle: simplify logic by token bucket algorithm
Date: Fri, 18 Oct 2013 11:55:33 -0400 [thread overview]
Message-ID: <20131018155532.GD2277@redhat.com> (raw)
In-Reply-To: <1382012272-26170-1-git-send-email-zhiguohong-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org>
On Thu, Oct 17, 2013 at 08:17:52PM +0800, Hong Zhiguo wrote:
[..]
> @@ -852,41 +710,30 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio,
> unsigned long *wait)
> {
> bool rw = bio_data_dir(bio);
> - u64 bytes_allowed, extra_bytes, tmp;
> - unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
> -
> - jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[rw];
> -
> - /* Slice has just started. Consider one slice interval */
> - if (!jiffy_elapsed)
> - jiffy_elapsed_rnd = throtl_slice;
> + u64 extra_bytes, token;
> + unsigned long jiffy_wait;
>
> - jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, throtl_slice);
> + token = (u64)tg->bps[rw] * (jiffies - tg->last_dispatch[rw]);
> + do_div(token, HZ);
> + token += tg->bytes_token[rw];
>
> - tmp = tg->bps[rw] * jiffy_elapsed_rnd;
> - do_div(tmp, HZ);
> - bytes_allowed = tmp;
> + /* trim the token if the group is idle */
> + if (!tg->service_queue.nr_queued[rw] && token > THROTL_BURST_BYTES)
> + token = THROTL_BURST_BYTES;
I think same logic need to be applied to iops too?
Also, how does it work in case of hierarchy? IIUC, when bio is being
propogated upwards, we first add it to the parent, and then later
update dispatch time which will in turn call tg_with_in_bps_limit().
So by the time you come here after bio propogation, bio is already
on service queue and it will be entitiled to *unlimited* idle tokens.
On the flip side, we can't do blind truncation of idle tokens in
parent group. Reason being that once bio got queued in child group,
effectively it should be subjected to parent's limits too right now
and not necessarily when it climbs up the tree.
To solve this problem I had put following patch.
commit 32ee5bc4787dfbdb280b4d81a338dcdd55918c1e
Author: Vivek Goyal <vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Date: Tue May 14 13:52:38 2013 -0700
blk-throttle: Account for child group's start time in parent while bio
climb
Above solution was not perfect but seemed like reasonable approximation.
We might have to do something similar. I think we can keep track of time
when an bio starts waiting in a group (gets to head of list) and then
when that bio is dispatched, pass that time to parent group. Now
parent can give more tokens to bio based on wait time start as passed
by children.
For example say Twaitstart is the time a bio started waiting on the head
of queue of a group. Say Tidle is time when parent became idle. Now when
child passes this bio to parent, it will also pass Twaitstart to parent.
When it comes time for token calculation, parent can do following.
If (time_after(Twaitstart, Tidle)
start_time = Twaitstart;
else
start_time = Tidle;
token_eligibility = (jiffies - start_time) * rate;
This is far from perfect, but it should work reasonably.
Thanks
Vivek
next prev parent reply other threads:[~2013-10-18 15:55 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-12 10:46 [PATCH] blk-throttle: simplify logic by token bucket algorithm Hong Zhiguo
[not found] ` <1381574794-7639-1-git-send-email-zhiguohong-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org>
2013-10-13 12:59 ` Hong zhi guo
2013-10-14 9:09 ` [PATCH v2] " Hong Zhiguo
[not found] ` <1381741757-20888-1-git-send-email-zhiguohong-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org>
2013-10-14 13:36 ` Tejun Heo
2013-10-14 13:47 ` Hong zhi guo
[not found] ` <20131014133620.GF4722-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-10-14 13:53 ` Hong zhi guo
[not found] ` <CAA7+ByWPM2Pizm+dP1AxPM7Ut-w=AtRfD2GkCK-0OVh+C2Twkg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-10-14 13:59 ` Tejun Heo
[not found] ` <20131014135929.GH4722-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-10-15 12:35 ` Hong zhi guo
2013-10-15 16:19 ` Jens Axboe
2013-10-15 13:03 ` Vivek Goyal
2013-10-15 17:32 ` Vivek Goyal
2013-10-16 6:09 ` Hong zhi guo
2013-10-16 14:14 ` Vivek Goyal
2013-10-16 15:47 ` Hong zhi guo
2013-10-16 15:53 ` Tejun Heo
[not found] ` <20131016155344.GA10012-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-10-16 16:22 ` Vivek Goyal
2013-10-16 16:22 ` Hong zhi guo
2013-10-17 12:17 ` [PATCH v3] " Hong Zhiguo
[not found] ` <1382012272-26170-1-git-send-email-zhiguohong-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org>
2013-10-18 15:55 ` Vivek Goyal [this message]
[not found] ` <20131018155532.GD2277-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-10-20 12:08 ` Hong zhi guo
2013-10-20 12:11 ` [PATCH v4 0/2] " Hong Zhiguo
2013-10-20 12:11 ` [PATCH v4 1/2] " Hong Zhiguo
2014-04-10 10:07 ` Hong zhi guo
[not found] ` <CAA7+ByVJWjfs5HiMsnuum75egghrNQHt2KNNPTWeVa0-FWccaQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-10 13:32 ` Vivek Goyal
2013-10-20 12:11 ` [PATCH v4 2/2] blk-throttle: trim tokens generated for an idle tree Hong Zhiguo
[not found] ` <1382271072-15664-3-git-send-email-zhiguohong-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org>
2013-10-22 21:02 ` Vivek Goyal
[not found] ` <20131022210232.GB2884-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-10-23 3:30 ` Hong zhi guo
2013-10-28 5:08 ` Hong zhi guo
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=20131018155532.GD2277@redhat.com \
--to=vgoyal-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=honkiko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=zhiguohong-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org \
/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).