Messages in this thread | | | Date | Sat, 7 Oct 2023 17:16:08 +0200 | From | Oleg Nesterov <> | Subject | Re: [PATCH] blk-throttle: Calculate allowed value only when the throttle is enabled |
| |
On 10/07, Yu Kuai wrote: > > >>>probably need to remove the mul_u64_u64_div_u64 and check for > >>>overflow/potential overflow ourselves? > > > >probably yes... > > How about this? > > diff --git a/block/blk-throttle.c b/block/blk-throttle.c > index 1101fb6f6cc8..5482c316a103 100644 > --- a/block/blk-throttle.c > +++ b/block/blk-throttle.c > @@ -723,6 +723,10 @@ static unsigned int calculate_io_allowed(u32 > iops_limit, > > static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long > jiffy_elapsed) > { > + if (jiffy_elapsed > HZ && > + bps_limit > mul_u64_u64_div_u64(U64_MAX, (u64)HZ, > (u64)jiffy_elapsed); > + return U64_MAX; > +
I can't suggest anything better...
but I do not know if it is possible that HZ > jiffy_elapsed. If yes, then mul_u64_u64_div_u64() above is not safe too.
Oleg.
| |