All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Yury Norov <yury.norov@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: Re: [GIT PULL] Bitmap patches for v5.19-rc1
Date: Fri, 27 May 2022 21:17:21 -0700	[thread overview]
Message-ID: <CAHk-=whTKRaz0j+cwkbLe6CEc1XWp45CLQESOqqGnRiaU1UsMQ@mail.gmail.com> (raw)
In-Reply-To: <YpDxiBywRMcdZNUO@yury-laptop>

On Fri, May 27, 2022 at 8:44 AM Yury Norov <yury.norov@gmail.com> wrote:
>
>       bitmap: add bitmap_weight_{cmp, eq, gt, ge, lt, le} functions

So honestly, I pulled this, looked at the code, and then unpulled it again.

This is not helping.

Making changes like this:

-       if (mm != current->active_mm || cpumask_weight(mm_cpumask(mm)) != 1) {
+       if (mm != current->active_mm || !cpumask_weight_eq(mm_cpumask(mm), 1)) {

only makes the code harder to understand.

And it gets worse:

-               if (cpumask_weight(mask) > cpumask_weight(sibling_mask(cpu)))
+               if (cpumask_weight_gt(mask, cpumask_weight(sibling_mask(cpu))))

is just disgusting. That original line is simple to read and makes
sense. That new replacement really makes you do "Whaa?"

Now, I understand that these kinds of helper functions could make for
slightly more efficient code in that you can break out of the bitmap
scanning early when you have found enough bits set. I get it.

BUT.

 (a) code legibility is really really important

 (b) the places I found this weren't that performance-critical.

 (c) in most cases, the bitmaps in question are one single word

so I'm unpulling this again.

Now, some other parts of the pull were clear improvements. For
example, the hyperv changes like this:

-               if (hc->var_cnt != bitmap_weight((unsigned long
*)&valid_bank_mask, 64))
+               if (hc->var_cnt != hweight64(valid_bank_mask))

were clear improvements where the old code was disgusting, and clearly
improved by the change.

But the "bitmap_weight_cmp()" functions (and the cpumask_weight_cmp()
ones) are just not a direction we want to go.

The special case of zero (ie "cpumask_weight() == 0" ->
"bitmap_empty()") is one thing: making that kind of change tends to
keep the code legible or even make it more understandable. So I didn't
mind that. But I do mind the pointlessly complex new arbitrary weight
comparisons, and the kind of mental cost they have.

There are people in the CS world that think "abstractions are always
good". Those people are very very wrong.

              Linus

  reply	other threads:[~2022-05-28  4:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-27 15:43 [GIT PULL] Bitmap patches for v5.19-rc1 Yury Norov
2022-05-28  4:17 ` Linus Torvalds [this message]
2022-06-01  1:15   ` Yury Norov
2022-06-03 19:46 Yury Norov
2022-06-04 21:20 ` pr-tracker-bot
2022-06-04 21:24 ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHk-=whTKRaz0j+cwkbLe6CEc1XWp45CLQESOqqGnRiaU1UsMQ@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.