[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9a09db3d4827bc6bf49c4579d495d71015f2c5a6.camel@intel.com>
Date: Tue, 06 Aug 2019 11:30:02 -0700
From: Sai Praneeth Prakhya <sai.praneeth.prakhya@...el.com>
To: Dave Hansen <dave.hansen@...el.com>, linux-kernel@...r.kernel.org,
linux-mm@...ck.org
Cc: Ingo Molnar <mingo@...nel.org>, Vlastimil Babka <vbabka@...e.cz>,
Peter Zijlstra <peterz@...radead.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Anshuman Khandual <anshuman.khandual@....com>
Subject: Re: [PATCH V2] fork: Improve error message for corrupted page tables
On Tue, 2019-08-06 at 09:30 -0700, Dave Hansen wrote:
> On 8/5/19 8:05 PM, Sai Praneeth Prakhya wrote:
> > +static const char * const resident_page_types[NR_MM_COUNTERS] = {
> > + [MM_FILEPAGES] = "MM_FILEPAGES",
> > + [MM_ANONPAGES] = "MM_ANONPAGES",
> > + [MM_SWAPENTS] = "MM_SWAPENTS",
> > + [MM_SHMEMPAGES] = "MM_SHMEMPAGES",
> > +};
>
> One trick to ensure that this gets updated if the names are ever
> updated. You can do:
>
> #define NAMED_ARRAY_INDEX(x) [x] = __stringify(x),
>
> and
>
> static const char * const resident_page_types[NR_MM_COUNTERS] = {
> NAMED_ARRAY_INDEX(MM_FILE_PAGES),
> NAMED_ARRAY_INDEX(MM_SHMEMPAGES),
> ...
> };
Thanks for the suggestion Dave. I will add this in V3.
Even with this, (if ever) anyone who changes the name of page types or adds an
new entry would still need to update struct resident_page_types[]. So, I will
add the comment as suggested by Vlastimil.
>
> That makes sure that any name changes make it into the strings. Then
> stick a:
>
> BUILD_BUG_ON(NR_MM_COUNTERS != ARRAY_SIZE(resident_page_types));
>
> somewhere. That makes sure that any new array indexes get a string
> added in the array. Otherwise you get nice, early, compile-time errors.
Sure! this sounds good and a small nit-bit :)
For the BUILD_BUG_ON() to work, the definition of struct should be changed as
below
static const char * const resident_page_types[] = {
...
}
i.e. we should not specify the size of array.
Regards,
Sai
Powered by blists - more mailing lists