Re: [PATCH RFC v2 2/2] mm: Rework swap handling of zap_pte_range
From: John Hubbard <jhubbard@nvidia.com>
Date: 2021-11-16 19:06:42
Also in:
lkml
On 11/16/21 05:11, Matthew Wilcox wrote:
On Tue, Nov 16, 2021 at 12:51:13AM -0800, John Hubbard wrote:quoted
On 11/15/21 05:57, Matthew Wilcox wrote:quoted
On Mon, Nov 15, 2021 at 09:49:51PM +0800, Peter Xu wrote:quoted
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 declaringYes. 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