Re: [GIT PULL] percpu fix for v5.9-rc6

From: Matthew Wilcox
Date: Fri Sep 18 2020 - 23:02:50 EST

On Fri, Sep 18, 2020 at 10:53:36PM -0400, Arvind Sankar wrote:
> I think you can't do this in standard C. It's a GCC extension.
> A structure containing a flexible array member, or a union
> containing such a structure (possibly recursively), may not be a
> member of a structure or an element of an array. (However, these
> uses are permitted by GCC as extensions.)

I actually have a patch in the works which wants to do this.

struct pagevec {
- unsigned char nr;
- bool percpu_pvec_drained;
- struct page *pages[PAGEVEC_SIZE];
+ union {
+ struct {
+ unsigned char sz;
+ unsigned char nr;
+ bool percpu_pvec_drained;
+ struct page *pages[];
+ };
+ void *__p[PAGEVEC_SIZE + 1];
+ };

I don't think ANSI C permits this, but it's useful to be able to declare
a pagevec on the stack and be guaranteed to get enough memory to hold
a useful sized array of pointers (as well as be able to dynamically
allocate a larger pagevec for the cases which want such a thing).

We could certainly split pagevec into a variable length array version
and have a struct stack_pagevec which had the extra padding, but that
involves changing a lot more code.