From: Andy Lutomirski <luto@kernel.org>
To: Fanjun Kong <fanjun.kong@linux.dev>,
Dave Hansen <dave.hansen@linux.intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>
Cc: Muchun Song <songmuchun@bytedance.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/mm: declare static variable inside a function instead of global
Date: Tue, 28 Jun 2022 16:46:44 -0700 [thread overview]
Message-ID: <2f966e28-cebd-067d-580e-ad6a1fc32c35@kernel.org> (raw)
In-Reply-To: <20220618101134.3073210-1-fanjun.kong@linux.dev>
On 6/18/22 03:11, Fanjun Kong wrote:
> Global variables are global capacity variables, unless they are
> shadowed, they are available to the entire program.
This is true in general, but:
> -static unsigned long memory_block_size_probed;
^^^^^^
So this isn't actually the case.
> unsigned long memory_block_size_bytes(void)
> {
> + static unsigned long memory_block_size_probed;
> +
> if (!memory_block_size_probed)
> memory_block_size_probed = probe_memory_block_size();
>
I'm sort of okay with the patch, but it's worth noting that, in C++,
initialized function-scope static variables have quite surprising
semantics, so this type of change isn't a pure win in my book. (Yes,
the kernel is C, not C++. But C++ programmers may be nervous anyway.)
prev parent reply other threads:[~2022-06-28 23:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-18 10:11 Fanjun Kong
2022-06-28 23:46 ` Andy Lutomirski [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=2f966e28-cebd-067d-580e-ad6a1fc32c35@kernel.org \
--to=luto@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=fanjun.kong@linux.dev \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=songmuchun@bytedance.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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
all inboxes | Powered by JetHome®