import math pow_threshold = 0.25 def nearest_pow2(size): val = math.pow(2,round(math.log(size)/math.log(2))) if val < size * (1-pow_threshold): val *=2 return val def update_pg_count(osd_num,size,pg_osd=100,pre_data=0.1): min_val = nearest_pow2(math.floor(osd_num/size)+1) if min_val < osd_num: min_val *= 2 calc_val = nearest_pow2(math.floor(pg_osd*osd_num*pre_data)/(100*size)) if min_val > calc_val: return min_val else: return calc_val print(int(update_pg_count(100,3,100,0.1)))