mm: migrate: Add a tracepoint for migrate_pages
authorMel Gorman <mgorman@suse.de>
Fri, 19 Oct 2012 13:07:31 +0000 (14:07 +0100)
committerMel Gorman <mgorman@suse.de>
Tue, 11 Dec 2012 14:28:35 +0000 (14:28 +0000)
The pgmigrate_success and pgmigrate_fail vmstat counters tells the user
about migration activity but not the type or the reason. This patch adds
a tracepoint to identify the type of page migration and why the page is
being migrated.

Signed-off-by: Mel Gorman <mgorman@suse.de>
Reviewed-by: Rik van Riel <riel@redhat.com>
include/linux/migrate.h
include/trace/events/migrate.h [new file with mode: 0644]
mm/compaction.c
mm/memory-failure.c
mm/memory_hotplug.c
mm/mempolicy.c
mm/migrate.c
mm/page_alloc.c

index ce7e6671968b791194df3c35d180443dbd615869..9d1c159e242704c077fe91de3b5d5a1fdace9413 100644 (file)
@@ -7,6 +7,15 @@
 
 typedef struct page *new_page_t(struct page *, unsigned long private, int **);
 
+enum migrate_reason {
+       MR_COMPACTION,
+       MR_MEMORY_FAILURE,
+       MR_MEMORY_HOTPLUG,
+       MR_SYSCALL,             /* also applies to cpusets */
+       MR_MEMPOLICY_MBIND,
+       MR_CMA
+};
+
 #ifdef CONFIG_MIGRATION
 
 extern void putback_lru_pages(struct list_head *l);
@@ -14,7 +23,7 @@ extern int migrate_page(struct address_space *,
                        struct page *, struct page *, enum migrate_mode);
 extern int migrate_pages(struct list_head *l, new_page_t x,
                        unsigned long private, bool offlining,
-                       enum migrate_mode mode);
+                       enum migrate_mode mode, int reason);
 extern int migrate_huge_page(struct page *, new_page_t x,
                        unsigned long private, bool offlining,
                        enum migrate_mode mode);
@@ -35,7 +44,7 @@ extern int migrate_huge_page_move_mapping(struct address_space *mapping,
 static inline void putback_lru_pages(struct list_head *l) {}
 static inline int migrate_pages(struct list_head *l, new_page_t x,
                unsigned long private, bool offlining,
-               enum migrate_mode mode) { return -ENOSYS; }
+               enum migrate_mode mode, int reason) { return -ENOSYS; }
 static inline int migrate_huge_page(struct page *page, new_page_t x,
                unsigned long private, bool offlining,
                enum migrate_mode mode) { return -ENOSYS; }
diff --git a/include/trace/events/migrate.h b/include/trace/events/migrate.h
new file mode 100644 (file)
index 0000000..ec2a6cc
--- /dev/null
@@ -0,0 +1,51 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM migrate
+
+#if !defined(_TRACE_MIGRATE_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_MIGRATE_H
+
+#define MIGRATE_MODE                                           \
+       {MIGRATE_ASYNC,         "MIGRATE_ASYNC"},               \
+       {MIGRATE_SYNC_LIGHT,    "MIGRATE_SYNC_LIGHT"},          \
+       {MIGRATE_SYNC,          "MIGRATE_SYNC"}         
+
+#define MIGRATE_REASON                                         \
+       {MR_COMPACTION,         "compaction"},                  \
+       {MR_MEMORY_FAILURE,     "memory_failure"},              \
+       {MR_MEMORY_HOTPLUG,     "memory_hotplug"},              \
+       {MR_SYSCALL,            "syscall_or_cpuset"},           \
+       {MR_MEMPOLICY_MBIND,    "mempolicy_mbind"},             \
+       {MR_CMA,                "cma"}
+
+TRACE_EVENT(mm_migrate_pages,
+
+       TP_PROTO(unsigned long succeeded, unsigned long failed,
+                enum migrate_mode mode, int reason),
+
+       TP_ARGS(succeeded, failed, mode, reason),
+
+       TP_STRUCT__entry(
+               __field(        unsigned long,          succeeded)
+               __field(        unsigned long,          failed)
+               __field(        enum migrate_mode,      mode)
+               __field(        int,                    reason)
+       ),
+
+       TP_fast_assign(
+               __entry->succeeded      = succeeded;
+               __entry->failed         = failed;
+               __entry->mode           = mode;
+               __entry->reason         = reason;
+       ),
+
+       TP_printk("nr_succeeded=%lu nr_failed=%lu mode=%s reason=%s",
+               __entry->succeeded,
+               __entry->failed,
+               __print_symbolic(__entry->mode, MIGRATE_MODE),
+               __print_symbolic(__entry->reason, MIGRATE_REASON))
+);
+
+#endif /* _TRACE_MIGRATE_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
index 00ad883952160838127b442c167ca35081fe5380..2c077a78487c61b8d083130b566bf05055227d1e 100644 (file)
@@ -990,7 +990,8 @@ static int compact_zone(struct zone *zone, struct compact_control *cc)
                nr_migrate = cc->nr_migratepages;
                err = migrate_pages(&cc->migratepages, compaction_alloc,
                                (unsigned long)cc, false,
-                               cc->sync ? MIGRATE_SYNC_LIGHT : MIGRATE_ASYNC);
+                               cc->sync ? MIGRATE_SYNC_LIGHT : MIGRATE_ASYNC,
+                               MR_COMPACTION);
                update_nr_listpages(cc);
                nr_remaining = cc->nr_migratepages;
 
index 6c5899b9034aa7d769e5fd80e139cad61af104c0..ddb68a169e4517f085cca927453e4c67424f1e43 100644 (file)
@@ -1558,7 +1558,8 @@ int soft_offline_page(struct page *page, int flags)
                                            page_is_file_cache(page));
                list_add(&page->lru, &pagelist);
                ret = migrate_pages(&pagelist, new_page, MPOL_MF_MOVE_ALL,
-                                                       false, MIGRATE_SYNC);
+                                                       false, MIGRATE_SYNC,
+                                                       MR_MEMORY_FAILURE);
                if (ret) {
                        putback_lru_pages(&pagelist);
                        pr_info("soft offline: %#lx: migration failed %d, type %lx\n",
index e4eeacae2b91199142776390bdaef73241416b47..e598bd15c0415fe37db52fcab94a5ad6cc401cc6 100644 (file)
@@ -812,7 +812,8 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
                 * migrate_pages returns # of failed pages.
                 */
                ret = migrate_pages(&source, alloc_migrate_target, 0,
-                                                       true, MIGRATE_SYNC);
+                                                       true, MIGRATE_SYNC,
+                                                       MR_MEMORY_HOTPLUG);
                if (ret)
                        putback_lru_pages(&source);
        }
index d04a8a54c294f852f55e624e3c41d1b03b7a56e9..66e90ecc2350f916dfdad660d95d1a4ee5c8b9df 100644 (file)
@@ -961,7 +961,8 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
 
        if (!list_empty(&pagelist)) {
                err = migrate_pages(&pagelist, new_node_page, dest,
-                                                       false, MIGRATE_SYNC);
+                                                       false, MIGRATE_SYNC,
+                                                       MR_SYSCALL);
                if (err)
                        putback_lru_pages(&pagelist);
        }
@@ -1202,7 +1203,8 @@ static long do_mbind(unsigned long start, unsigned long len,
                if (!list_empty(&pagelist)) {
                        nr_failed = migrate_pages(&pagelist, new_vma_page,
                                                (unsigned long)vma,
-                                               false, MIGRATE_SYNC);
+                                               false, MIGRATE_SYNC,
+                                               MR_MEMPOLICY_MBIND);
                        if (nr_failed)
                                putback_lru_pages(&pagelist);
                }
index 04687f69cc173b0581b1bc0381792253ca119fcc..27be9c923dc1b250070da02fbf0e9075487c197c 100644 (file)
@@ -38,6 +38,9 @@
 
 #include <asm/tlbflush.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/migrate.h>
+
 #include "internal.h"
 
 /*
@@ -958,7 +961,7 @@ out:
  */
 int migrate_pages(struct list_head *from,
                new_page_t get_new_page, unsigned long private, bool offlining,
-               enum migrate_mode mode)
+               enum migrate_mode mode, int reason)
 {
        int retry = 1;
        int nr_failed = 0;
@@ -1004,6 +1007,8 @@ out:
                count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded);
        if (nr_failed)
                count_vm_events(PGMIGRATE_FAIL, nr_failed);
+       trace_mm_migrate_pages(nr_succeeded, nr_failed, mode, reason);
+
        if (!swapwrite)
                current->flags &= ~PF_SWAPWRITE;
 
@@ -1145,7 +1150,8 @@ set_status:
        err = 0;
        if (!list_empty(&pagelist)) {
                err = migrate_pages(&pagelist, new_page_node,
-                               (unsigned long)pm, 0, MIGRATE_SYNC);
+                               (unsigned long)pm, 0, MIGRATE_SYNC,
+                               MR_SYSCALL);
                if (err)
                        putback_lru_pages(&pagelist);
        }
index 7bb35ac0964aaa425b3888e0963e3d7fa2ac1e53..5953dc2d196f1a5b3b7f584361f41ca6cbf08c93 100644 (file)
@@ -5707,7 +5707,8 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
 
                ret = migrate_pages(&cc->migratepages,
                                    alloc_migrate_target,
-                                   0, false, MIGRATE_SYNC);
+                                   0, false, MIGRATE_SYNC,
+                                   MR_CMA);
        }
 
        putback_lru_pages(&cc->migratepages);