linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Weizhao Ouyang <o451686892@gmail.com>,
	"Huang, Ying" <ying.huang@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Pavel Tatashin <pasha.tatashin@soleen.com>,
	Oscar Salvador <osalvador@suse.de>,
	Yang Shi <shy828301@gmail.com>, Zi Yan <ziy@nvidia.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/debug: sync up latest migrate_reason to migrate_reason_names
Date: Sat, 18 Sep 2021 22:38:10 -0700	[thread overview]
Message-ID: <cec9a286-f7b6-c80a-c518-480db65152fc@nvidia.com> (raw)
In-Reply-To: <b4123610-bddf-03b9-2190-7b0cda55b57c@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3427 bytes --]

On 9/18/21 00:03, Weizhao Ouyang wrote:
...
>   
> Anyway, I didn't find a simply way the build the "everywhere" relationship behind
> the packaged TRACE_DEFINE_ENUM , what do you think.
> 
It's actually pretty easy, unless I'm unknowingly violating some rule
here. But I did review tracing a bit before diving in, and I think this
is reasonable.

The trace macros EM(), EMe(), and MIGRATE_REASON are flexible enough to
get whatever you want, out of them. So, the trace header can be the one
location for the definition of the enum-to-string mapping.

The key is to move the enum to a common header file that both the trace
system (trace/events/migrate.h) and the migrate header
(include/linux/migrate.h) can include. Fortunately, that's already been
started for enum migrate_mode: there is migrate_mode.h.

So it all works approximately like this, below. (I'll attach a
white-space-correct diff that you can apply directly, too). I've
compiled tested and rebooted with it, but haven't checked much more
than that yet.

---
  include/linux/migrate.h      | 16 ++--------------
  include/linux/migrate_mode.h | 13 +++++++++++++
  mm/debug.c                   | 19 ++++++++++++-------
  3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index 326250996b4e..cb62fbc3d8d6 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -6,6 +6,7 @@
  #include <linux/mempolicy.h>
  #include <linux/migrate_mode.h>
  #include <linux/hugetlb.h>
+#include <linux/migrate_mode.h>

  typedef struct page *new_page_t(struct page *page, unsigned long private);
  typedef void free_page_t(struct page *page, unsigned long private);
@@ -19,20 +20,7 @@ struct migration_target_control;
   */
  #define MIGRATEPAGE_SUCCESS		0

-enum migrate_reason {
-	MR_COMPACTION,
-	MR_MEMORY_FAILURE,
-	MR_MEMORY_HOTPLUG,
-	MR_SYSCALL,		/* also applies to cpusets */
-	MR_MEMPOLICY_MBIND,
-	MR_NUMA_MISPLACED,
-	MR_CONTIG_RANGE,
-	MR_LONGTERM_PIN,
-	MR_DEMOTION,
-	MR_TYPES
-};
-
-/* In mm/debug.c; also keep sync with include/trace/events/migrate.h */
+/* In mm/debug.c */
  extern const char *migrate_reason_names[MR_TYPES];

  #ifdef CONFIG_MIGRATION
diff --git a/include/linux/migrate_mode.h b/include/linux/migrate_mode.h
index 883c99249033..f37cc03f9369 100644
--- a/include/linux/migrate_mode.h
+++ b/include/linux/migrate_mode.h
@@ -19,4 +19,17 @@ enum migrate_mode {
  	MIGRATE_SYNC_NO_COPY,
  };

+enum migrate_reason {
+	MR_COMPACTION,
+	MR_MEMORY_FAILURE,
+	MR_MEMORY_HOTPLUG,
+	MR_SYSCALL,		/* also applies to cpusets */
+	MR_MEMPOLICY_MBIND,
+	MR_NUMA_MISPLACED,
+	MR_CONTIG_RANGE,
+	MR_LONGTERM_PIN,
+	MR_DEMOTION,
+	MR_TYPES
+};
+
  #endif		/* MIGRATE_MODE_H_INCLUDED */
diff --git a/mm/debug.c b/mm/debug.c
index e73fe0a8ec3d..51152ffc1f29 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -17,14 +17,19 @@

  #include "internal.h"

+#include <trace/events/migrate.h>
+
+/*
+ * Define EM() and EMe() so that MIGRATE_REASON from trace/events/migrate.h can
+ * be used to populate migrate_reason_names[].
+ */
+#undef EM
+#undef EMe
+#define EM(a, b)	b,
+#define EMe(a, b)	b
+
  const char *migrate_reason_names[MR_TYPES] = {
-	"compaction",
-	"memory_failure",
-	"memory_hotplug",
-	"syscall_or_cpuset",
-	"mempolicy_mbind",
-	"numa_misplaced",
-	"cma",
+	MIGRATE_REASON
  };

  const struct trace_print_flags pageflag_names[] = {
-- 
2.33.0

thanks,
-- 
John Hubbard
NVIDIA

[-- Attachment #2: 0001-Use-one-definition-of-MIGRATE_REASON-strings-everywh.patch --]
[-- Type: text/x-patch, Size: 2704 bytes --]

From 7b10419a1de9be352539b38e2ca70cc5b14687d9 Mon Sep 17 00:00:00 2001
From: John Hubbard <jhubbard@nvidia.com>
Date: Sat, 18 Sep 2021 22:07:20 -0700
Subject: [PATCH] Use one definition of MIGRATE_REASON strings, everywhere
X-NVConfidentiality: public
Cc: John Hubbard <jhubbard@nvidia.com>

(Compiled-tested only, so no signed off by tag.)
---
 include/linux/migrate.h      | 16 ++--------------
 include/linux/migrate_mode.h | 13 +++++++++++++
 mm/debug.c                   | 19 ++++++++++++-------
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index 326250996b4e..cb62fbc3d8d6 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -6,6 +6,7 @@
 #include <linux/mempolicy.h>
 #include <linux/migrate_mode.h>
 #include <linux/hugetlb.h>
+#include <linux/migrate_mode.h>
 
 typedef struct page *new_page_t(struct page *page, unsigned long private);
 typedef void free_page_t(struct page *page, unsigned long private);
@@ -19,20 +20,7 @@ struct migration_target_control;
  */
 #define MIGRATEPAGE_SUCCESS		0
 
-enum migrate_reason {
-	MR_COMPACTION,
-	MR_MEMORY_FAILURE,
-	MR_MEMORY_HOTPLUG,
-	MR_SYSCALL,		/* also applies to cpusets */
-	MR_MEMPOLICY_MBIND,
-	MR_NUMA_MISPLACED,
-	MR_CONTIG_RANGE,
-	MR_LONGTERM_PIN,
-	MR_DEMOTION,
-	MR_TYPES
-};
-
-/* In mm/debug.c; also keep sync with include/trace/events/migrate.h */
+/* In mm/debug.c */
 extern const char *migrate_reason_names[MR_TYPES];
 
 #ifdef CONFIG_MIGRATION
diff --git a/include/linux/migrate_mode.h b/include/linux/migrate_mode.h
index 883c99249033..f37cc03f9369 100644
--- a/include/linux/migrate_mode.h
+++ b/include/linux/migrate_mode.h
@@ -19,4 +19,17 @@ enum migrate_mode {
 	MIGRATE_SYNC_NO_COPY,
 };
 
+enum migrate_reason {
+	MR_COMPACTION,
+	MR_MEMORY_FAILURE,
+	MR_MEMORY_HOTPLUG,
+	MR_SYSCALL,		/* also applies to cpusets */
+	MR_MEMPOLICY_MBIND,
+	MR_NUMA_MISPLACED,
+	MR_CONTIG_RANGE,
+	MR_LONGTERM_PIN,
+	MR_DEMOTION,
+	MR_TYPES
+};
+
 #endif		/* MIGRATE_MODE_H_INCLUDED */
diff --git a/mm/debug.c b/mm/debug.c
index e73fe0a8ec3d..51152ffc1f29 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -17,14 +17,19 @@
 
 #include "internal.h"
 
+#include <trace/events/migrate.h>
+
+/*
+ * Define EM() and EMe() so that MIGRATE_REASON from trace/events/migrate.h can
+ * be used to populate migrate_reason_names[].
+ */
+#undef EM
+#undef EMe
+#define EM(a, b)	b,
+#define EMe(a, b)	b
+
 const char *migrate_reason_names[MR_TYPES] = {
-	"compaction",
-	"memory_failure",
-	"memory_hotplug",
-	"syscall_or_cpuset",
-	"mempolicy_mbind",
-	"numa_misplaced",
-	"cma",
+	MIGRATE_REASON
 };
 
 const struct trace_print_flags pageflag_names[] = {
-- 
2.33.0


  reply	other threads:[~2021-09-19  5:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17  6:14 Weizhao Ouyang
2021-09-17  7:03 ` Huang, Ying
2021-09-17  7:27   ` John Hubbard
2021-09-17  9:48   ` Weizhao Ouyang
2021-09-18  0:30     ` John Hubbard
2021-09-18  7:03       ` Weizhao Ouyang
2021-09-19  5:38         ` John Hubbard [this message]
2021-09-20  9:14           ` Weizhao Ouyang
2021-09-19 23:35 ` Andrew Morton
2021-09-20  9:16   ` Weizhao Ouyang

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=cec9a286-f7b6-c80a-c518-480db65152fc@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=o451686892@gmail.com \
    --cc=osalvador@suse.de \
    --cc=pasha.tatashin@soleen.com \
    --cc=shy828301@gmail.com \
    --cc=ying.huang@intel.com \
    --cc=ziy@nvidia.com \
    /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