On Fri, Feb 07, 2020 at 07:34:57AM +0100, Uwe Kleine-König wrote: > Hello, > > On 2/7/20 12:47 AM, Linus Torvalds wrote: > > Instead, it could just calculate the nbuckets first, and then do the > > "log2()" on that: > > > > /* Use at least 2 buckets, select_bucket() is undefined > > behavior with 1 bucket */ > > nbuckets = max_t(u32, 2, roundup_pow_of_two(num_possible_cpus())); > > smap->bucket_log = ilog2(buckets); > > > Isn't it kind of ineffective to first round to a power of two and then > take the ilog2 of it? > > At a first glance I'd say that > > ilog2(roundup_pow_of_two(x)) == ilog(x - 1) + 1 > > for x > 1. (Maybe even for x == 1? Didn't care to check, I think it > doesn't matter for the case at hand.) > > This RHS might be easier to optimize for the compiler?! I believe x == 1 needs an extra case since ilog2(0) won't work. Since this function (map creation) is not on the fast path, I currently opt for Linus's suggestion which its code is more self-explanatory. Thanks, Martin