mm: mm_event: add compaction stat
authorMinchan Kim <minchan@google.com>
Wed, 27 Jun 2018 13:04:37 +0000 (22:04 +0900)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:24:01 +0000 (20:24 +0300)
This patch adds compaction mm_event stat so that we could keep track
latency of compaction as well as count of the event.

Under heavy memory fragmentation, high-order page allocation(e.g.
fork, ION memory allocation) triggers compaction, which is
another major part of latency. Let's track it down, too.

Mot-CRs-fixed: (CR)

Bug: 80168800
Change-Id: Ia3da9324f123ba2542863eafaf72024b5351785b
Signed-off-by: Minchan Kim <minchan@google.com>
Reviewed-on: https://gerrit.mot.com/1453722
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key

mm/compaction.c

index 0d8a825c4272778486450b1d8eef4caa0abc5422..244f751c3d7ff9972935b090823d023f9a8b08b5 100644 (file)
@@ -1509,6 +1509,7 @@ static enum compact_result compact_zone(struct zone *zone, struct compact_contro
        unsigned long start_pfn = zone->zone_start_pfn;
        unsigned long end_pfn = zone_end_pfn(zone);
        const bool sync = cc->mode != MIGRATE_ASYNC;
+       ktime_t event_ts;
 
        /*
         * These counters track activities during zone compaction.  Initialize
@@ -1566,6 +1567,7 @@ static enum compact_result compact_zone(struct zone *zone, struct compact_contro
 
        cc->last_migrated_pfn = 0;
 
+       mm_event_start(&event_ts);
        trace_mm_compaction_begin(start_pfn, cc->migrate_pfn,
                                cc->free_pfn, end_pfn, sync);
 
@@ -1650,6 +1652,7 @@ check_drain:
        }
 
 out:
+       mm_event_end(MM_COMPACTION, event_ts);
        /*
         * Release free pages and update where the free scanner should restart,
         * so we don't leave any returned pages behind in the next attempt.
@@ -1725,6 +1728,7 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
        struct zoneref *z;
        struct zone *zone;
        enum compact_result rc = COMPACT_SKIPPED;
+       ktime_t event_ts;
 
        /*
         * Check if the GFP flags allow compaction - GFP_NOIO is really
@@ -1733,6 +1737,7 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
        if (!may_perform_io)
                return COMPACT_SKIPPED;
 
+       mm_event_start(&event_ts);
        trace_mm_compaction_try_to_compact_pages(order, gfp_mask, prio);
 
        /* Compact each zone in the list */
@@ -1782,6 +1787,7 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
                        break;
        }
 
+       mm_event_end(MM_COMPACTION, event_ts);
        return rc;
 }