lkml.org 
[lkml]   [2019]   [Aug]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH V2] fork: Improve error message for corrupted page tables
From
Date
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),
...
};

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.

\
 
 \ /
  Last update: 2019-08-06 18:57    [W:0.088 / U:0.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site