linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: Ingo Molnar <mingo@kernel.org>, Vlastimil Babka <vbabka@suse.cz>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Anshuman Khandual <anshuman.khandual@arm.com>
Subject: Re: [PATCH V2] fork: Improve error message for corrupted page tables
Date: Tue, 6 Aug 2019 09:30:45 -0700	[thread overview]
Message-ID: <73b77479-cdd2-6d53-14ae-25ec4c4c3d25@intel.com> (raw)
In-Reply-To: <3ef8a340deb1c87b725d44edb163073e2b6eca5a.1565059496.git.sai.praneeth.prakhya@intel.com>

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.


  parent reply	other threads:[~2019-08-06 16:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06  3:05 Sai Praneeth Prakhya
2019-08-06  7:53 ` Vlastimil Babka
2019-08-06  8:32   ` Anshuman Khandual
2019-08-06 16:11     ` Prakhya, Sai Praneeth
2019-08-06 16:10   ` Prakhya, Sai Praneeth
2019-08-06  8:36 ` Michal Hocko
2019-08-06 21:21   ` Sai Praneeth Prakhya
2019-08-06 16:30 ` Dave Hansen [this message]
2019-08-06 18:30   ` Sai Praneeth Prakhya

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=73b77479-cdd2-6d53-14ae-25ec4c4c3d25@intel.com \
    --to=dave.hansen@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sai.praneeth.prakhya@intel.com \
    --cc=vbabka@suse.cz \
    /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