Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/migrate: de-duplicate migrate_reason strings

In order to remove the need to manually keep three different files in
synch, provide a common definition of the mapping between enum
migrate_reason, and the associated strings for each enum item.

1. Use the tracing system's mapping of enums to strings, by redefining
and reusing the MIGRATE_REASON and supporting macros, and using that
to populate the string array in mm/debug.c.

2. Move enum migrate_reason to migrate_mode.h. This is not strictly
necessary for this patch, but migrate mode and migrate reason go
together, so this will slightly clarify things.

Link: https://lkml.kernel.org/r/20210922041755.141817-2-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Weizhao Ouyang <o451686892@gmail.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

John Hubbard and committed by
Linus Torvalds
8eb42bea b5389086

+25 -27
+1 -18
include/linux/migrate.h
··· 19 19 */ 20 20 #define MIGRATEPAGE_SUCCESS 0 21 21 22 - /* 23 - * Keep sync with: 24 - * - macro MIGRATE_REASON in include/trace/events/migrate.h 25 - * - migrate_reason_names[MR_TYPES] in mm/debug.c 26 - */ 27 - enum migrate_reason { 28 - MR_COMPACTION, 29 - MR_MEMORY_FAILURE, 30 - MR_MEMORY_HOTPLUG, 31 - MR_SYSCALL, /* also applies to cpusets */ 32 - MR_MEMPOLICY_MBIND, 33 - MR_NUMA_MISPLACED, 34 - MR_CONTIG_RANGE, 35 - MR_LONGTERM_PIN, 36 - MR_DEMOTION, 37 - MR_TYPES 38 - }; 39 - 22 + /* Defined in mm/debug.c: */ 40 23 extern const char *migrate_reason_names[MR_TYPES]; 41 24 42 25 #ifdef CONFIG_MIGRATION
+13
include/linux/migrate_mode.h
··· 19 19 MIGRATE_SYNC_NO_COPY, 20 20 }; 21 21 22 + enum migrate_reason { 23 + MR_COMPACTION, 24 + MR_MEMORY_FAILURE, 25 + MR_MEMORY_HOTPLUG, 26 + MR_SYSCALL, /* also applies to cpusets */ 27 + MR_MEMPOLICY_MBIND, 28 + MR_NUMA_MISPLACED, 29 + MR_CONTIG_RANGE, 30 + MR_LONGTERM_PIN, 31 + MR_DEMOTION, 32 + MR_TYPES 33 + }; 34 + 22 35 #endif /* MIGRATE_MODE_H_INCLUDED */
+11 -9
mm/debug.c
··· 16 16 #include <linux/ctype.h> 17 17 18 18 #include "internal.h" 19 + #include <trace/events/migrate.h> 20 + 21 + /* 22 + * Define EM() and EMe() so that MIGRATE_REASON from trace/events/migrate.h can 23 + * be used to populate migrate_reason_names[]. 24 + */ 25 + #undef EM 26 + #undef EMe 27 + #define EM(a, b) b, 28 + #define EMe(a, b) b 19 29 20 30 const char *migrate_reason_names[MR_TYPES] = { 21 - "compaction", 22 - "memory_failure", 23 - "memory_hotplug", 24 - "syscall_or_cpuset", 25 - "mempolicy_mbind", 26 - "numa_misplaced", 27 - "contig_range", 28 - "longterm_pin", 29 - "demotion", 31 + MIGRATE_REASON 30 32 }; 31 33 32 34 const struct trace_print_flags pageflag_names[] = {