From: John Hubbard <jhubbard@nvidia.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Peter Xu <peterx@redhat.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
David Hildenbrand <david@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Yang Shi <shy828301@gmail.com>, Vlastimil Babka <vbabka@suse.cz>,
Hugh Dickins <hughd@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Alistair Popple <apopple@nvidia.com>,
"Kirill A . Shutemov" <kirill@shutemov.name>
Subject: Re: [PATCH RFC v2 2/2] mm: Rework swap handling of zap_pte_range
Date: Tue, 16 Nov 2021 11:06:18 -0800 [thread overview]
Message-ID: <b055cf62-c957-db35-2bf9-630345d63cf6@nvidia.com> (raw)
In-Reply-To: <YZOt7qD6yeSXJgv4@casper.infradead.org>
On 11/16/21 05:11, Matthew Wilcox wrote:
> On Tue, Nov 16, 2021 at 12:51:13AM -0800, John Hubbard wrote:
>> On 11/15/21 05:57, Matthew Wilcox wrote:
>>> On Mon, Nov 15, 2021 at 09:49:51PM +0800, Peter Xu wrote:
>>>> Clean the code up by merging the device private/exclusive swap entry handling
>>>> with the rest, then we merge the pte clear operation too.
>>>>
>>>> struct* page is defined in multiple places in the function, move it upward.
>>>
>>> Is that actually a good thing? There was a time when declaring
>>
>> Yes. It is a very good thing. Having multiple cases of shadowed variables
>> (in this case I'm using programming language terminology, or what I
>> remember it as, anyway) provides lots of opportunities to create
>> hard-to-spot bugs.
>
> I think you're misremembering. These are shadowed variables:
OK, I remembered correctly, but read the diffs a little too quickly, and...
>
> int a;
>
> int b(void)
> {
> int a;
> if (c) {
> int a;
> }
> }
>
> This is not:
>
> int b(void)
> {
...missed that there is no longer a "int a" at the top level. But it does
still present a small land mine, in that just adding a top level "int a"
creates all these shadowed variables (not necessarily bugs, yet, I know).
It's less of an issue here, then I first thought. Generally, it's probably best
to either use "int a" throughout, or differently named variables at lower
levels...or make smaller functions. Because if a variable name is reused
a lot in the same function then there is likely a relationship of sorts
between the instances, and it's worth deciding what that is.
> if (c) {
> int a;
> } else {
> int a;
> }
> }
>
> I really wish we could turn on -Wshadow, but we get compilation warnings
> from header files right now. Or we did last time I checked.
>
...and as you say, it would be nice if the programmer could just let the
compiler figure out if there is a real problem. The elaborate rituals to
stay out of harm's way are not as good as a tool that checks. :)
thanks,
--
John Hubbard
NVIDIA
prev parent reply other threads:[~2021-11-16 19:06 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-15 13:49 [PATCH RFC v2 0/2] mm: Rework zap ptes on swap entries Peter Xu
2021-11-15 13:49 ` [PATCH RFC v2 1/2] mm: Don't skip swap entry even if zap_details specified Peter Xu
2021-12-02 11:06 ` Alistair Popple
2021-12-03 3:21 ` Peter Xu
2021-12-03 5:33 ` Alistair Popple
2021-12-03 6:59 ` Peter Xu
2022-01-09 1:19 ` Hugh Dickins
2022-01-12 13:18 ` Peter Xu
2022-01-12 13:26 ` Peter Xu
2022-01-13 3:47 ` Hugh Dickins
2022-01-20 10:32 ` Peter Xu
2022-01-21 3:11 ` Peter Xu
2022-01-21 5:11 ` Peter Xu
2022-01-24 6:51 ` Hugh Dickins
2022-01-24 9:13 ` Peter Xu
2022-01-24 6:29 ` Hugh Dickins
2022-01-24 8:54 ` Peter Xu
2022-01-24 11:01 ` Peter Xu
2022-01-10 8:37 ` David Hildenbrand
2022-01-11 7:40 ` Alistair Popple
2022-01-11 9:00 ` David Hildenbrand
2021-11-15 13:49 ` [PATCH RFC v2 2/2] mm: Rework swap handling of zap_pte_range Peter Xu
2021-11-15 13:57 ` Matthew Wilcox
2021-11-16 5:06 ` Peter Xu
2021-11-16 8:51 ` John Hubbard
2021-11-16 13:11 ` Matthew Wilcox
2021-11-16 19:06 ` John Hubbard [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=b055cf62-c957-db35-2bf9-630345d63cf6@nvidia.com \
--to=jhubbard@nvidia.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=shy828301@gmail.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).