* [PATCH] memcontrol: use flexible-array member
@ 2021-05-18 5:20 wenhuizhang
2021-05-18 6:35 ` [External] " Muchun Song
2021-05-18 8:08 ` Michal Hocko
0 siblings, 2 replies; 4+ messages in thread
From: wenhuizhang @ 2021-05-18 5:20 UTC (permalink / raw)
Cc: wenhui, Andrew Morton, Shakeel Butt, Johannes Weiner,
Roman Gushchin, Michal Hocko, Muchun Song, Yang Shi, Alex Shi,
Alexander Duyck, Wei Yang, linux-kernel
Change depracated zero-length-and-one-element-arrays into flexible
array member.
Zero-length and one-element arrays detected by Lukas's CodeChecker.
Zero/one element arrays causes undefined behaviours if sizeof() used.
https://www.kernel.org/doc/html/latest/processd/deprecated.html
Signed-off-by: wenhuizhang<wenhui@gwmail.gwu.edu>
---
include/linux/memcontrol.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 0ce97eff79e2..f879efb1bc6e 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -190,7 +190,7 @@ enum memcg_kmem_state {
#if defined(CONFIG_SMP)
struct memcg_padding {
- char x[0];
+ char x[];
} ____cacheline_internodealigned_in_smp;
#define MEMCG_PADDING(name) struct memcg_padding name;
#else
@@ -349,7 +349,7 @@ struct mem_cgroup {
struct deferred_split deferred_split_queue;
#endif
- struct mem_cgroup_per_node *nodeinfo[0];
+ struct mem_cgroup_per_node *nodeinfo[];
/* WARNING: nodeinfo must be the last member here */
};
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [External] [PATCH] memcontrol: use flexible-array member
2021-05-18 5:20 [PATCH] memcontrol: use flexible-array member wenhuizhang
@ 2021-05-18 6:35 ` Muchun Song
2021-05-18 8:08 ` Michal Hocko
1 sibling, 0 replies; 4+ messages in thread
From: Muchun Song @ 2021-05-18 6:35 UTC (permalink / raw)
To: wenhuizhang
Cc: Andrew Morton, Shakeel Butt, Johannes Weiner, Roman Gushchin,
Michal Hocko, Yang Shi, Alex Shi, Alexander Duyck, Wei Yang,
LKML
On Tue, May 18, 2021 at 1:20 PM wenhuizhang <wenhui@gwmail.gwu.edu> wrote:
>
>
> Change depracated zero-length-and-one-element-arrays into flexible
> array member.
> Zero-length and one-element arrays detected by Lukas's CodeChecker.
> Zero/one element arrays causes undefined behaviours if sizeof() used.
>
> https://www.kernel.org/doc/html/latest/processd/deprecated.html
>
>
> Signed-off-by: wenhuizhang<wenhui@gwmail.gwu.edu>
> ---
> include/linux/memcontrol.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 0ce97eff79e2..f879efb1bc6e 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -190,7 +190,7 @@ enum memcg_kmem_state {
>
> #if defined(CONFIG_SMP)
> struct memcg_padding {
> - char x[0];
> + char x[];
Have you tested this?
The compiler will complain about this. The output will be something like below.
error: flexible array member in otherwise empty struct
Thanks.
> } ____cacheline_internodealigned_in_smp;
> #define MEMCG_PADDING(name) struct memcg_padding name;
> #else
> @@ -349,7 +349,7 @@ struct mem_cgroup {
> struct deferred_split deferred_split_queue;
> #endif
>
> - struct mem_cgroup_per_node *nodeinfo[0];
> + struct mem_cgroup_per_node *nodeinfo[];
> /* WARNING: nodeinfo must be the last member here */
> };
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] memcontrol: use flexible-array member
2021-05-18 5:20 [PATCH] memcontrol: use flexible-array member wenhuizhang
2021-05-18 6:35 ` [External] " Muchun Song
@ 2021-05-18 8:08 ` Michal Hocko
2021-05-18 8:43 ` [External] " Muchun Song
1 sibling, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2021-05-18 8:08 UTC (permalink / raw)
To: wenhuizhang
Cc: Andrew Morton, Shakeel Butt, Johannes Weiner, Roman Gushchin,
Muchun Song, Yang Shi, Alex Shi, Alexander Duyck, Wei Yang,
linux-kernel
On Tue 18-05-21 01:20:36, wenhuizhang wrote:
>
> Change depracated zero-length-and-one-element-arrays into flexible
> array member.
> Zero-length and one-element arrays detected by Lukas's CodeChecker.
> Zero/one element arrays causes undefined behaviours if sizeof() used.
>
> https://www.kernel.org/doc/html/latest/processd/deprecated.html
I do understand why zero-length structures are discouraged for trail
space but does the same concern apply to internal padding inside
structures to enforce alignment to different cache lines? AFAIK this is
a trick we use at other places and I do not remember having heard about
any problems.
nodeinfo is a different case where flexible arrays seems reasonable to
me.
> Signed-off-by: wenhuizhang<wenhui@gwmail.gwu.edu>
> ---
> include/linux/memcontrol.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 0ce97eff79e2..f879efb1bc6e 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -190,7 +190,7 @@ enum memcg_kmem_state {
>
> #if defined(CONFIG_SMP)
> struct memcg_padding {
> - char x[0];
> + char x[];
> } ____cacheline_internodealigned_in_smp;
> #define MEMCG_PADDING(name) struct memcg_padding name;
> #else
> @@ -349,7 +349,7 @@ struct mem_cgroup {
> struct deferred_split deferred_split_queue;
> #endif
>
> - struct mem_cgroup_per_node *nodeinfo[0];
> + struct mem_cgroup_per_node *nodeinfo[];
> /* WARNING: nodeinfo must be the last member here */
> };
>
> --
> 2.17.1
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [External] Re: [PATCH] memcontrol: use flexible-array member
2021-05-18 8:08 ` Michal Hocko
@ 2021-05-18 8:43 ` Muchun Song
0 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2021-05-18 8:43 UTC (permalink / raw)
To: wenhuizhang
Cc: Michal Hocko, Andrew Morton, Shakeel Butt, Johannes Weiner,
Roman Gushchin, Yang Shi, Alex Shi, Wei Yang, LKML
On Tue, May 18, 2021 at 4:08 PM Michal Hocko <mhocko@suse.com> wrote:
>
> On Tue 18-05-21 01:20:36, wenhuizhang wrote:
> >
> > Change depracated zero-length-and-one-element-arrays into flexible
> > array member.
> > Zero-length and one-element arrays detected by Lukas's CodeChecker.
> > Zero/one element arrays causes undefined behaviours if sizeof() used.
> >
> > https://www.kernel.org/doc/html/latest/processd/deprecated.html
>
> I do understand why zero-length structures are discouraged for trail
> space but does the same concern apply to internal padding inside
> structures to enforce alignment to different cache lines? AFAIK this is
> a trick we use at other places and I do not remember having heard about
> any problems.
>
> nodeinfo is a different case where flexible arrays seems reasonable to
> me.
I do agree with Michal's suggestion. If you only change nodeinfo
to a flexible array in the next version. Please also remove the
comment below it.
>
> > Signed-off-by: wenhuizhang<wenhui@gwmail.gwu.edu>
> > ---
> > include/linux/memcontrol.h | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index 0ce97eff79e2..f879efb1bc6e 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -190,7 +190,7 @@ enum memcg_kmem_state {
> >
> > #if defined(CONFIG_SMP)
> > struct memcg_padding {
> > - char x[0];
> > + char x[];
> > } ____cacheline_internodealigned_in_smp;
> > #define MEMCG_PADDING(name) struct memcg_padding name;
> > #else
> > @@ -349,7 +349,7 @@ struct mem_cgroup {
> > struct deferred_split deferred_split_queue;
> > #endif
> >
> > - struct mem_cgroup_per_node *nodeinfo[0];
> > + struct mem_cgroup_per_node *nodeinfo[];
> > /* WARNING: nodeinfo must be the last member here */
I mean this comment. Because the compiler will help us to
check this if we convert it to a flexible array.
Thanks.
> > };
> >
> > --
> > 2.17.1
>
> --
> Michal Hocko
> SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-18 8:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 5:20 [PATCH] memcontrol: use flexible-array member wenhuizhang
2021-05-18 6:35 ` [External] " Muchun Song
2021-05-18 8:08 ` Michal Hocko
2021-05-18 8:43 ` [External] " Muchun Song
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.