Re: [PATCH v1 1/1] bitmap: Refactor bitmap_read() and bitmap_write() to avoid too big shift

From: Andy Shevchenko

Date: Tue Nov 24 2026 - 05:01:10 EST


On Fri, Nov 20, 2026 at 09:42:32AM -0500, Yury Norov wrote:
> On Fri, Nov 20, 2026 at 10:42:24AM +0200, Andy Shevchenko wrote:
> > On Thu, Nov 19, 2026 at 04:22:06PM -0500, Yury Norov wrote:
> > > On Thu, Nov 19, 2026 at 11:03:53PM +0200, Andy Shevchenko wrote:
> > > > On Thu, Nov 19, 2026 at 03:37:33PM -0500, Yury Norov wrote:
> > > > > On Thu, Nov 19, 2026 at 08:15:30PM +0100, Andy Shevchenko wrote:

...

> > > > > I guess... Let's keep the patch minimal?
> > > > >
> > > > > > - mask = BITMAP_LAST_WORD_MASK(nbits);
> > > > > > - value &= mask;
> > > > > > - offset = start % BITS_PER_LONG;
> > > > > > - space = BITS_PER_LONG - offset;
> > > > > > - fit = space >= nbits;
> > > > >
> > > > > I don't like this 'fit' thing, and would like to drop it. But
> > > > > let's find a better motivation to do that?
> > > >
> > > > Why? The fit keeps the check I want to refactor, since it makes it twice
> > > > the code with that ternary looks ugly and unreadable. This is exactly the
> > > > chance to kill two birds with one stone.
> > >
> > > That's what I meant regarding the motivational part and minimizing the
> > > patch.
> >
> > OK. So refactoring bitmap_write() to make it look like bitmap_read() can be
> > done after your nice below patch.
>
> Sure, I'll take the patch with the tags suggested.

In the Linux Next it uses Link instead of Closes. Perhaps you still have
a chance to amend that?

> But you're very welcome to continue optimizing it - my gut feeling says we
> can squeeze a few more percents out of it with just a careful refactoring.

Sure, when I have time to look into this again.

--
With Best Regards,
Andy Shevchenko