All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Longlong Xia <xialonglong2025@163.com>,
	Mike Rapoport <rppt@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Longlong Xia <xialonglong@kylinos.cn>
Subject: Re: [PATCH 1/1] mm/mm_init: compute hash mask with unsigned arithmetic
Date: Mon, 10 Aug 2026 04:21:53 +0100	[thread overview]
Message-ID: <anlD0ZX0BZb_MVNw@casper.infradead.org> (raw)
In-Reply-To: <20260809181400.148e68eff30394f6b029f4d1@linux-foundation.org>

On Sun, Aug 09, 2026 at 06:14:00PM -0700, Andrew Morton wrote:
> > >> Use an unsigned literal so the mask is computed with unsigned
> > >> arithmetic. Supported compiler settings already produce the same
> > >> result, so this is a source-level cleanup with no functional change.
> > > If complier already takes care of this then why do we want this patch?
> >   
> > Fair point. Since supported compilers already produce the intended 
> > result and this patch has no functional impact, the benefit is only 
> > making the unsigned arithmetic explicit. So please disregard this patch.
> 
> It's a very small thing, but I believe the patch improves the code.
> 
> I mean, we erroneously compute a large negative number then subtract 1
> from it then copy that larger negative number into a signed scalar.

That is an erroneous description of this code.

1 << 31 is the largest-magnitude negative number, ie it's INT_MIN.
We then subtract one from it, so it wraps back around to INT_MAX.
So the number assigned to *_hash_mask is always positive.

> The copied bit pattern happens to be what we'd have got if the code had
> been correct, but the code isn't correct!

The code is correct as long as we compile with -fwrapv or whatever that
got renamed to.  And I don't see that changing.

      reply	other threads:[~2026-08-10  3:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09 12:31 [PATCH 1/1] mm/mm_init: compute hash mask with unsigned arithmetic Longlong Xia
2026-08-09 14:03 ` Mike Rapoport
2026-08-09 14:25   ` Longlong Xia
2026-08-10  1:14     ` Andrew Morton
2026-08-10  3:21       ` Matthew Wilcox [this message]

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=anlD0ZX0BZb_MVNw@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.org \
    --cc=xialonglong2025@163.com \
    --cc=xialonglong@kylinos.cn \
    /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.