From: Yujie Liu <yujie.liu@intel.com>
To: Barry Song <21cnbao@gmail.com>
Cc: <lkp@intel.com>, <akpm@linux-foundation.org>,
<linux-mm@kvack.org>, <llvm@lists.linux.dev>,
<oe-kbuild-all@lists.linux.dev>, <v-songbaohua@oppo.com>
Subject: Re: [akpm-mm:mm-unstable 313/322] include/linux/huge_mm.h:274:16: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
Date: Sun, 7 Apr 2024 15:39:01 +0800 [thread overview]
Message-ID: <ZhJNlSSPNyQLG6iZ@yujie-X299> (raw)
In-Reply-To: <20240407042247.201412-1-21cnbao@gmail.com>
Hi Barry,
On Sun, Apr 07, 2024 at 04:22:47PM +1200, Barry Song wrote:
> >> tree: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable
> >> head: f43b3aae94511d62174c3b29239da0dd22d0eeb3
> >> commit: d4358ee0a075e232114dfec0cd162860cfa2771b [313/322] mm: add per-order mTHP anon_alloc and anon_alloc_fallback counters
> >> config: powerpc-allyesconfig (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/config)
> >> compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 546dc2245ffc4cccd0b05b58b7a5955e355a3b27)
> >> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/reproduce)
> >>
> >> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> >> the same patch/commit), kindly add following tags
> >> | Reported-by: kernel test robot <lkp@intel.com>
> >> | Closes: https://lore.kernel.org/oe-kbuild-all/202404061754.n8jmZ6s3-lkp@intel.com/
> >>
> >> All error/warnings (new ones prefixed by >>):
> >>
> >> In file included from arch/powerpc/kernel/asm-offsets.c:19:
> >> In file included from include/linux/mman.h:5:
> >> In file included from include/linux/mm.h:1115:
> >>>> include/linux/huge_mm.h:274:22: warning: variable length array used [-Wvla]
> >> 274 | unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
> > | ^~~~~~~~~~~~~
> >
> > This is amazing. powerpc's PMD_ORDER isn't const. I will
> > move to alloc_percpu instead of using a static array.
>
> As replied in another thread, can you please test the below patch?
> this is v2 combining the fix and the fix of the fix.
This v2 patch fixes the errors/warnings reported in both this thread
and thread [1].
[1] https://lore.kernel.org/all/202404061627.ungVloow-lkp@intel.com/
Tested-by: Yujie Liu <yujie.liu@intel.com>
> From 6f8604a51ff3333be467e2a681a1f1e8a5d41c48 Mon Sep 17 00:00:00 2001
> From: Barry Song <v-songbaohua@oppo.com>
> Date: Sun, 7 Apr 2024 12:23:35 +1200
> Subject: [PATCH v2] mm: fix powerpc build issue
>
> On powerpc, PMD_ORDER is not a constant variable. We should transition
> to using alloc_percpu instead of a static percpu array.
>
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> ---
> include/linux/huge_mm.h | 9 ++++-----
> mm/huge_memory.c | 12 ++++++++++--
> 2 files changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index c5d33017a4dd..0717063dc5e7 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -271,16 +271,15 @@ enum mthp_stat_item {
> };
>
> struct mthp_stat {
> - unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
> + unsigned long stats[0][__MTHP_STAT_COUNT];
> };
>
> -DECLARE_PER_CPU(struct mthp_stat, mthp_stats);
> +extern struct mthp_stat __percpu *mthp_stats;
>
> static inline void count_mthp_stat(int order, enum mthp_stat_item item)
> {
> - if (unlikely(order > PMD_ORDER))
> - return;
> - this_cpu_inc(mthp_stats.stats[order][item]);
> + if (likely(order <= PMD_ORDER))
> + raw_cpu_ptr(mthp_stats)->stats[order][item]++;
> }
>
> #define transparent_hugepage_use_zero_page() \
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 5b875f0fc923..7a72760dc1ce 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -526,7 +526,7 @@ static const struct kobj_type thpsize_ktype = {
> .sysfs_ops = &kobj_sysfs_ops,
> };
>
> -DEFINE_PER_CPU(struct mthp_stat, mthp_stats) = {{{0}}};
> +struct mthp_stat __percpu *mthp_stats;
>
> static unsigned long sum_mthp_stat(int order, enum mthp_stat_item item)
> {
> @@ -534,7 +534,7 @@ static unsigned long sum_mthp_stat(int order, enum mthp_stat_item item)
> int cpu;
>
> for_each_online_cpu(cpu) {
> - struct mthp_stat *this = &per_cpu(mthp_stats, cpu);
> + struct mthp_stat *this = per_cpu_ptr(mthp_stats, cpu);
>
> sum += this->stats[order][item];
> }
> @@ -636,6 +636,13 @@ static int __init hugepage_init_sysfs(struct kobject **hugepage_kobj)
> goto remove_hp_group;
> }
>
> + mthp_stats = __alloc_percpu((PMD_ORDER + 1) * sizeof(mthp_stats->stats[0]),
> + sizeof(unsigned long));
> + if (!mthp_stats) {
> + err = -ENOMEM;
> + goto remove_hp_group;
> + }
> +
> orders = THP_ORDERS_ALL_ANON;
> order = highest_order(orders);
> while (orders) {
> @@ -673,6 +680,7 @@ static void __init hugepage_exit_sysfs(struct kobject *hugepage_kobj)
> sysfs_remove_group(hugepage_kobj, &khugepaged_attr_group);
> sysfs_remove_group(hugepage_kobj, &hugepage_attr_group);
> kobject_put(hugepage_kobj);
> + free_percpu(mthp_stats);
> }
> #else
> static inline int hugepage_init_sysfs(struct kobject **hugepage_kobj)
> --
> 2.34.1
>
>
>
prev parent reply other threads:[~2024-04-07 7:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-06 9:30 kernel test robot
2024-04-06 22:40 ` Barry Song
2024-04-07 4:22 ` Barry Song
2024-04-07 7:39 ` Yujie Liu [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=ZhJNlSSPNyQLG6iZ@yujie-X299 \
--to=yujie.liu@intel.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=llvm@lists.linux.dev \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=v-songbaohua@oppo.com \
/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