throttle: Make LeakyBucket.avg and LeakyBucket.max integer types
PATCH 1/1 throttle: Make LeakyBucket.avg and LeakyBucket.max integer types
Both the throttling limits set with the throttling.iops-* and throttling.bps-* options and their QMP equivalents defined in the BlockIOThrottle struct are integer values.
Those limits are also reported in the BlockDeviceInfo struct and they are integers there as well.
Therefore there's no reason to store them internally as double and do the conversion everytime we're setting or querying them, so this patch uses int64_t for those types.
LeakyBucket.level and LeakyBucket.burst_level do however remain double because their value changes depending on the fraction of time elapsed since the previous I/O operation.
There's one particular instance of the previous code where bkt->max could have a non-integer value: that's in throttle_fix_bucket() when bkt->max is initialized to bkt->avg / 10. This is now an integer division and the result is rounded. We don't need to worry about this because:
a) with the magnitudes we're dealing with (bytes per second, I/O operations per second) the limits are likely to be always multiples of 10.
b) even if they weren't this doesn't affect the actual limits, only the algorithm that makes the throttling smoother.
--- include/qemu/throttle.h | 4 ++-- util/throttle.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-)
include/qemu/throttle.h +2 -2
@@ -77,8 +77,8 @@ typedef enum {*/ typedef struct LeakyBucket { - double avg; /* average goal in units per second */ - double max; /* leaky bucket max burst in units */ + int64_t avg; /* average goal in units per second */ + int64_t max; /* leaky bucket max burst in units */ double level; /* bucket level in units */ double burst_level; /* bucket level in units (for computing bursts) */ unsigned burst_length; /* max length of the burst period, in seconds */
util/throttle.c +2 -5
@@ -111,7 +111,7 @@ int64_t throttle_compute_wait(LeakyBucket *bkt)if (bkt->burst_length >1 ) {/* We use 1/10 of the max value to smooth the throttling. * See throttle_fix_bucket() for more details. */ - extra = bkt->burst_level - bkt->max /10 ; + extra = bkt->burst_level - (double ) bkt->max /10 ;if (extra >0 ) {return throttle_do_compute_wait (bkt->max, extra); }
@@ -361,8 +361,6 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **errp)/* fix bucket parameters */ static void throttle_fix_bucket (LeakyBucket *bkt) { -double min; -/* zero bucket level */ bkt->level = bkt->burst_level =0 ;
@@ -374,9 +372,8 @@ static void throttle_fix_bucket(LeakyBucket *bkt)* Having a max burst value of 100ms of the average will help smooth the * throttling */ - min = bkt->avg /10 ;if (bkt->avg && !bkt->max) { - bkt->max = min; + bkt->max = (bkt->avg +5 ) /10 ; } }
Signature · 1 line
2.11.0
Quoted 25 lines · Alberto Garcia
Both the throttling limits set with the throttling.iops-* and throttling.bps-* options and their QMP equivalents defined in the BlockIOThrottle struct are integer values.
Those limits are also reported in the BlockDeviceInfo struct and they are integers there as well.
Therefore there's no reason to store them internally as double and do the conversion everytime we're setting or querying them, so this patch uses
int64_tfor those types.LeakyBucket.level and LeakyBucket.burst_level do however remain double because their value changes depending on the fraction of time elapsed since the previous I/O operation.
There's one particular instance of the previous code where
bkt->maxcould have a non-integer value: that's inthrottle_fix_bucket()whenbkt->maxis initialized tobkt->avg/ 10. This is now an integer division and the result is rounded. We don't need to worry about this because:a) with the magnitudes we're dealing with (bytes per second, I/O operations per second) the limits are likely to be always multiples of 10.
Quoted 8 lines
b) even if they weren't this doesn't affect the actual limits, only the algorithm that makes the throttling smoother.
Signed-off-by Alberto Garcia <[email protected]>--- include/qemu/throttle.h | 4 ++-- util/throttle.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 25 lines · Alberto Garcia
Both the throttling limits set with the throttling.iops-* and throttling.bps-* options and their QMP equivalents defined in the BlockIOThrottle struct are integer values.
Those limits are also reported in the BlockDeviceInfo struct and they are integers there as well.
Therefore there's no reason to store them internally as double and do the conversion everytime we're setting or querying them, so this patch uses
int64_tfor those types.LeakyBucket.level and LeakyBucket.burst_level do however remain double because their value changes depending on the fraction of time elapsed since the previous I/O operation.
There's one particular instance of the previous code where
bkt->maxcould have a non-integer value: that's inthrottle_fix_bucket()whenbkt->maxis initialized tobkt->avg/ 10. This is now an integer division and the result is rounded. We don't need to worry about this because:a) with the magnitudes we're dealing with (bytes per second, I/O operations per second) the limits are likely to be always multiples of 10.
Quoted 8 lines
b) even if they weren't this doesn't affect the actual limits, only the algorithm that makes the throttling smoother.
Signed-off-by Alberto Garcia <[email protected]>--- include/qemu/throttle.h | 4 ++-- util/throttle.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-)
Why is this marked for-2.10? Does it fix a bug?
Quoted 5 lines · Stefan Hajnoczi
Quoted 4 lines · Alberto Garcia
Both the throttling limits set with the throttling.iops-* and throttling.bps-* options and their QMP equivalents defined in the BlockIOThrottle struct are integer values.
Quoted 8 lines
Quoted 7 lines
Those limits are also reported in the BlockDeviceInfo struct and they are integers there as well.
Therefore there's no reason to store them internally as double and do the conversion everytime we're setting or querying them, so this patch uses
int64_tfor those types.Why is this marked for-2.10? Does it fix a bug?
I was under the impression that Markus wanted to change the QAPI types of the throttling fields in BlockDeviceInfo for 2.10 as well, so this patch is relevant.
If that's not the case we can ignore it for now and leave it for the next cycle. Sorry for the noise!
Berto
Quoted 3 lines · Alberto Garcia
I was under the impression that Markus wanted to change the QAPI types of the throttling fields in BlockDeviceInfo for 2.10 as well, so this patch is relevant.
I just saw that his series is still an RFC, so we can leave this patch for 2.11. Sorry again!
Berto
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Alberto Garcia
Both the throttling limits set with the throttling.iops-* and throttling.bps-* options and their QMP equivalents defined in the BlockIOThrottle struct are integer values.
Those limits are also reported in the BlockDeviceInfo struct and they are integers there as well.
Quoted 6 lines
Quoted 4 lines
Therefore there's no reason to store them internally as double and do the conversion everytime we're setting or querying them, so this patch uses
int64_tfor those types.Why is this marked for-2.10? Does it fix a bug?
Theoretically, converting between int64_t and double loses precision on any values larger than 2^53. In all practicality, though, if you expect throttling to be precise through 2^53 (approximately 16 orders of magnitude), you're crazy. I also don't see any change to potential division-by-zero actions (where differences in NaN vs. SIGFPE each have their own advantages, but changing between them can be construed as a bug fix). So I'm also having a hard time seeing this as 2.10 material.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 6 lines · Eric Blake
Quoted 1 line
Why is this marked for-2.10? Does it fix a bug?
Theoretically, converting between
int64_tand double loses precision on any values larger than 2^53. In all practicality, though, if you expect throttling to be precise through 2^53 (approximately 16 orders of magnitude), you're crazy.
You cannot, THROTTLE_VALUE_MAX is set to 10^15, which is smaller than 2^50.
Quoted 1 line
So I'm also having a hard time seeing this as 2.10 material.
Right, as I said that was a wrong assumption from my side :) No need for this in 2.10.
Berto
Stefan Hajnoczi
AppliedQuoted 25 lines · Alberto Garcia
Both the throttling limits set with the throttling.iops-* and throttling.bps-* options and their QMP equivalents defined in the BlockIOThrottle struct are integer values.
Those limits are also reported in the BlockDeviceInfo struct and they are integers there as well.
Therefore there's no reason to store them internally as double and do the conversion everytime we're setting or querying them, so this patch uses
int64_tfor those types.LeakyBucket.level and LeakyBucket.burst_level do however remain double because their value changes depending on the fraction of time elapsed since the previous I/O operation.
There's one particular instance of the previous code where
bkt->maxcould have a non-integer value: that's inthrottle_fix_bucket()whenbkt->maxis initialized tobkt->avg/ 10. This is now an integer division and the result is rounded. We don't need to worry about this because:a) with the magnitudes we're dealing with (bytes per second, I/O operations per second) the limits are likely to be always multiples of 10.
Quoted 8 lines
b) even if they weren't this doesn't affect the actual limits, only the algorithm that makes the throttling smoother.
Signed-off-by Alberto Garcia <[email protected]>--- include/qemu/throttle.h | 4 ++-- util/throttle.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-)
Thanks, applied to my block-next tree:
https://github.com/stefanha/qemu/commits/block-next
Stefan