[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a4dc3313-b9b7-4075-b082-7232b3b7717b@suse.cz>
Date: Wed, 29 Jan 2025 11:22:00 +0100
From: Vlastimil Babka <vbabka@...e.cz>
To: Bart Van Assche <bvanassche@....org>,
Ivan Shapovalov <intelfx@...elfx.name>,
Andrew Morton <akpm@...ux-foundation.org>
Cc: Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>, Bill Wendling
<morbo@...gle.com>, Justin Stitt <justinstitt@...gle.com>,
Pasha Tatashin <pasha.tatashin@...een.com>,
David Rientjes <rientjes@...gle.com>, David Hildenbrand <david@...hat.com>,
Joel Granados <joel.granados@...nel.org>,
Sourav Panda <souravpanda@...gle.com>, Kaiyang Zhao <kaiyang2@...cmu.edu>,
Johannes Weiner <hannes@...xchg.org>,
Konstantin Khlebnikov <koct9i@...il.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [PATCH] mm/vmstat: Fix a W=1 clang compiler warning
On 1/28/25 22:36, Bart Van Assche wrote:
> On 1/21/25 5:57 PM, Ivan Shapovalov wrote:
>>> Spose so. One always suspects that adding a typecast is a sign that we
>>> screwed things up somehow. The relationship between enums lru_list and
>>> node_stat_item is foggy, and I'm unsure whether this is the place to
>>> make the transition it. Perhaps lru_list_name() should take an
>>> `unsigned int' arg instead.
>>
>> All of these *_name() functions do seem to expect arguments in range of
>> the corresponding enums, so perhaps keep those args typed as a form of
>> self-documenting code, and do this instead?
>
> If nobody objects I will submit this patch for review after the merge
> window has closed:
>
> Subject: [PATCH] mm/vmstat: Fix W=1 clang compiler warnings
>
> Commit 30c2de0a267c ("mm/vmstat: fix a W=1 clang compiler warning")
> suppresses some but not all compiler warnings that are reported by clang
> when building with W=1 about NR_LRU_BASE and NR_ZONE_LRU_BASE. Hence
> revert commit 30c2de0a267c and instead make NR_LRU_BASE and
> NR_ZONE_LRU_BASE integer constants instead of enumeration constants.
>
> Cc: Ivan Shapovalov <intelfx@...elfx.name>
> Signed-off-by: Bart Van Assche <bvanassche@....org>
> ---
> include/linux/mmzone.h | 22 +++++++++++++++++++---
> include/linux/vmstat.h | 9 +++++++--
> 2 files changed, 26 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 9540b41894da..92ed919ea99d 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -135,10 +135,19 @@ enum numa_stat_item {
> #define NR_VM_NUMA_EVENT_ITEMS 0
> #endif
>
> +/*
> + * NR_ZONE_LRU_BASE and NR_VM_ZONE_STAT_ITEMS are often added to
> enumeration
> + * constants of another type than enum_zone_stat_item. Define these
> constants
> + * as an integer instead of enum node_stat_item to prevent that the
> compiler
> + * warns about enumeration type mismatches when these constants are used.
> + */
> +#define NR_ZONE_LRU_BASE (1 * __NR_ZONE_LRU_BASE)
> +#define NR_VM_ZONE_STAT_ITEMS (1 * __NR_VM_ZONE_STAT_ITEMS)
Seems an acceptable approach, dunno if this multiply by one is any better
than casting to int?
> +
> enum zone_stat_item {
> /* First 128 byte cacheline (assuming 64 bit words) */
> NR_FREE_PAGES,
> - NR_ZONE_LRU_BASE, /* Used only for compaction and reclaim retry */
> + __NR_ZONE_LRU_BASE, /* Used only for compaction and reclaim retry */
> NR_ZONE_INACTIVE_ANON = NR_ZONE_LRU_BASE,
Should we rather use __NR_ZONE_LRU_BASE here?
> NR_ZONE_ACTIVE_ANON,
> NR_ZONE_INACTIVE_FILE,
> @@ -155,10 +164,17 @@ enum zone_stat_item {
> #ifdef CONFIG_UNACCEPTED_MEMORY
> NR_UNACCEPTED,
> #endif
> - NR_VM_ZONE_STAT_ITEMS };
> + __NR_VM_ZONE_STAT_ITEMS };
> +
> +/*
> + * enum lru_list constants are often added to NR_LRU_BASE. Define
> NR_LRU_BASE
> + * as an integer instead of enum node_stat_item to prevent that the
> compiler
> + * warns about enumeration type mismatches.
> + */
> +#define NR_LRU_BASE (1 * __NR_LRU_BASE)
>
> enum node_stat_item {
> - NR_LRU_BASE,
> + __NR_LRU_BASE,
> NR_INACTIVE_ANON = NR_LRU_BASE, /* must match order of LRU_[IN]ACTIVE */
ditto
> NR_ACTIVE_ANON, /* " " " " " */
> NR_INACTIVE_FILE, /* " " " " " */
> diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
> index 9f3a04345b86..eb115b9a50f4 100644
> --- a/include/linux/vmstat.h
> +++ b/include/linux/vmstat.h
> @@ -135,8 +135,13 @@ static inline void vm_events_fold_cpu(int cpu)
> #define count_vm_vma_lock_event(x) do {} while (0)
> #endif
>
> +/*
> + * item##_NORMAL has type enum vm_event_item while ZONE_NORMAL and zid have
> + * type enum zone_type. Suppress compiler warnings about mixing different
> + * enumeration types by converting item##_NORMAL into an int with '1 *'.
> + */
> #define __count_zid_vm_events(item, zid, delta) \
> - __count_vm_events(item##_NORMAL - ZONE_NORMAL + zid, delta)
> + __count_vm_events(1 * item##_NORMAL - ZONE_NORMAL + zid, delta)
>
> /*
> * Zone and node-based page accounting with per cpu differentials.
> @@ -515,7 +520,7 @@ static inline const char *node_stat_name(enum
> node_stat_item item)
>
> static inline const char *lru_list_name(enum lru_list lru)
> {
> - return node_stat_name(NR_LRU_BASE + (enum node_stat_item)lru) + 3; //
> skip "nr_"
> + return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
> }
>
> #if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG)
>
Powered by blists - more mailing lists