Received: from eggs.gnu.org ([2001:4830:134:3::10]:37531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKUkP-0007Nh-Kf for qemu-devel@nongnu.org; Tue, 05 Jul 2016 14:07:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKUkL-0003Aw-Qd for qemu-devel@nongnu.org; Tue, 05 Jul 2016 14:07:01 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:52690) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKUkL-00039o-Iq for qemu-devel@nongnu.org; Tue, 05 Jul 2016 14:06:57 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u65I3NAT111853 for ; Tue, 5 Jul 2016 14:06:55 -0400 Received: from e06smtp09.uk.ibm.com (e06smtp09.uk.ibm.com [195.75.94.105]) by mx0a-001b2d01.pphosted.com with ESMTP id 23xa4dk4mc-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 05 Jul 2016 14:06:55 -0400 Received: from localhost by e06smtp09.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Jul 2016 19:06:53 +0100 From: Sascha Silbe In-Reply-To: References: <1467127721-9564-1-git-send-email-silbe@linux.vnet.ibm.com> <1467127721-9564-2-git-send-email-silbe@linux.vnet.ibm.com> <818452bb-a196-bac8-87a7-e283451a9494@redhat.com> <87a8hxa319.fsf@oc4731375738.ibm.com> Date: Tue, 05 Jul 2016 20:06:50 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-Id: <8760skklhh.fsf@oc4731375738.ibm.com> Subject: Re: [Qemu-devel] [PATCH 1/1] Improve block job rate limiting for small bandwidth values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , qemu-block@nongnu.org Cc: Kevin Wolf , Jeff Cody , qemu-devel@nongnu.org Dear Max, Max Reitz writes: > [ Good signature by key: 0x58B381CE2DC89CF99730EE643BB14202E838ACAD ] Feel free to drop by if you happen to be in the Stuttgart area some time. PGP key signing, a beverage of your choice and optionally some chatting about qemu and related topics. :) > On 04.07.2016 16:30, Sascha Silbe wrote: >> Max Reitz writes: [...] [include/qemu/ratelimit.h] >>>> static inline int64_t ratelimit_calculate_delay(RateLimit *limit, uin= t64_t n) >>>> { >>>> int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); >>>> + uint64_t delay_slices; >>>>=20=20 >>>> - if (limit->next_slice_time < now) { >>>> - limit->next_slice_time =3D now + limit->slice_ns; >>>> + assert(limit->slice_quota && limit->slice_ns); >>>> + >>>> + if (limit->slice_end_time < now) { >>>> + /* Previous, possibly extended, time slice finished; reset the >>>> + * accounting. */ >>>> + limit->slice_start_time =3D now; >>>> + limit->slice_end_time =3D now + limit->slice_ns; >>>> limit->dispatched =3D 0; >>>> } >>>> - if (limit->dispatched =3D=3D 0 || limit->dispatched + n <=3D limi= t->slice_quota) { >>>> - limit->dispatched +=3D n; >>>> + >>>> + limit->dispatched +=3D n; >>>> + if (limit->dispatched < limit->slice_quota) { >>> >>> Nitpick: This should probably stay <=3D. >>=20 >> This is a subtle edge case. Previously, when limit->dispatched =3D=3D >> limit->slice_quota, we returned 0 so that the _current_ request (which >> is still within quota) wouldn't be delayed. Now, we return a delay so >> that the _next_ request (which would be over quota) will be delayed. > > Hm, but that depends on the size of the next request. Of course, if we > get limit->dispatched =3D=3D limit->slice_quota we know for sure that we > need to delay the next request. But if we get limit->dispatched =3D=3D > limit->slice_quota - 1... Then we probably also have to delay it, but we > don't know for sure. No matter where exactly we draw the line, due to the way the block job rate limiting works (fixed size time slices, fixed size requests) there will always be cases where we're off the target rate quite a bit, in one or the other direction. For rate limits where we can send an integer number of chunks per time slice (i.e. some MiB/s sized value), the "<" condition is probably better. We'll send out a couple of chunks that exactly match the quota, then sleep for the rest of the time slice. If we'd use "<=3D", we'd send out one extra chunk before we start sleeping. But I don't care much either way, "<=3D" is fine with me, too. Sascha --=20 Softwareentwicklung Sascha Silbe, Niederhofenstra=C3=9Fe 5/1, 71229 Leonberg https://se-silbe.de/ USt-IdNr. DE281696641