Skip to content

Commit

Permalink
mm/compaction: more trace to understand when/why compaction start/finish
Browse files Browse the repository at this point in the history
It is not well analyzed that when/why compaction start/finish or not.
With these new tracepoints, we can know much more about start/finish
reason of compaction.  I can find following bug with these tracepoint.

http://www.spinics.net/lists/linux-mm/msg81582.html

Signed-off-by: Joonsoo Kim <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: David Rientjes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoonsooKim authored and torvalds committed Feb 12, 2015
1 parent e34d85f commit 837d026
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/linux/compaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#define COMPACT_PARTIAL 3
/* The full zone was compacted */
#define COMPACT_COMPLETE 4
/* For more detailed tracepoint output */
#define COMPACT_NO_SUITABLE_PAGE 5
#define COMPACT_NOT_SUITABLE_ZONE 6
/* When adding new state, please change compaction_status_string, too */

/* Used to signal whether compaction detected need_sched() or lock contention */
Expand Down
74 changes: 74 additions & 0 deletions include/trace/events/compaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,80 @@ TRACE_EVENT(mm_compaction_end,
compaction_status_string[__entry->status])
);

TRACE_EVENT(mm_compaction_try_to_compact_pages,

TP_PROTO(
int order,
gfp_t gfp_mask,
enum migrate_mode mode),

TP_ARGS(order, gfp_mask, mode),

TP_STRUCT__entry(
__field(int, order)
__field(gfp_t, gfp_mask)
__field(enum migrate_mode, mode)
),

TP_fast_assign(
__entry->order = order;
__entry->gfp_mask = gfp_mask;
__entry->mode = mode;
),

TP_printk("order=%d gfp_mask=0x%x mode=%d",
__entry->order,
__entry->gfp_mask,
(int)__entry->mode)
);

DECLARE_EVENT_CLASS(mm_compaction_suitable_template,

TP_PROTO(struct zone *zone,
int order,
int ret),

TP_ARGS(zone, order, ret),

TP_STRUCT__entry(
__field(int, nid)
__field(char *, name)
__field(int, order)
__field(int, ret)
),

TP_fast_assign(
__entry->nid = zone_to_nid(zone);
__entry->name = (char *)zone->name;
__entry->order = order;
__entry->ret = ret;
),

TP_printk("node=%d zone=%-8s order=%d ret=%s",
__entry->nid,
__entry->name,
__entry->order,
compaction_status_string[__entry->ret])
);

DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_finished,

TP_PROTO(struct zone *zone,
int order,
int ret),

TP_ARGS(zone, order, ret)
);

DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_suitable,

TP_PROTO(struct zone *zone,
int order,
int ret),

TP_ARGS(zone, order, ret)
);

#endif /* _TRACE_COMPACTION_H */

/* This part must be outside protection */
Expand Down
38 changes: 34 additions & 4 deletions mm/compaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static const char *const compaction_status_string[] = {
"continue",
"partial",
"complete",
"no_suitable_page",
"not_suitable_zone",
};
#endif

Expand Down Expand Up @@ -1049,7 +1051,7 @@ static isolate_migrate_t isolate_migratepages(struct zone *zone,
return cc->nr_migratepages ? ISOLATE_SUCCESS : ISOLATE_NONE;
}

static int compact_finished(struct zone *zone, struct compact_control *cc,
static int __compact_finished(struct zone *zone, struct compact_control *cc,
const int migratetype)
{
unsigned int order;
Expand Down Expand Up @@ -1104,7 +1106,20 @@ static int compact_finished(struct zone *zone, struct compact_control *cc,
return COMPACT_PARTIAL;
}

return COMPACT_CONTINUE;
return COMPACT_NO_SUITABLE_PAGE;
}

static int compact_finished(struct zone *zone, struct compact_control *cc,
const int migratetype)
{
int ret;

ret = __compact_finished(zone, cc, migratetype);
trace_mm_compaction_finished(zone, cc->order, ret);
if (ret == COMPACT_NO_SUITABLE_PAGE)
ret = COMPACT_CONTINUE;

return ret;
}

/*
Expand All @@ -1114,7 +1129,7 @@ static int compact_finished(struct zone *zone, struct compact_control *cc,
* COMPACT_PARTIAL - If the allocation would succeed without compaction
* COMPACT_CONTINUE - If compaction should run now
*/
unsigned long compaction_suitable(struct zone *zone, int order,
static unsigned long __compaction_suitable(struct zone *zone, int order,
int alloc_flags, int classzone_idx)
{
int fragindex;
Expand Down Expand Up @@ -1158,11 +1173,24 @@ unsigned long compaction_suitable(struct zone *zone, int order,
*/
fragindex = fragmentation_index(zone, order);
if (fragindex >= 0 && fragindex <= sysctl_extfrag_threshold)
return COMPACT_SKIPPED;
return COMPACT_NOT_SUITABLE_ZONE;

return COMPACT_CONTINUE;
}

unsigned long compaction_suitable(struct zone *zone, int order,
int alloc_flags, int classzone_idx)
{
unsigned long ret;

ret = __compaction_suitable(zone, order, alloc_flags, classzone_idx);
trace_mm_compaction_suitable(zone, order, ret);
if (ret == COMPACT_NOT_SUITABLE_ZONE)
ret = COMPACT_SKIPPED;

return ret;
}

static int compact_zone(struct zone *zone, struct compact_control *cc)
{
int ret;
Expand Down Expand Up @@ -1376,6 +1404,8 @@ unsigned long try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
if (!order || !may_enter_fs || !may_perform_io)
return COMPACT_SKIPPED;

trace_mm_compaction_try_to_compact_pages(order, gfp_mask, mode);

/* Compact each zone in the list */
for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->high_zoneidx,
ac->nodemask) {
Expand Down

0 comments on commit 837d026

Please sign in to comment.