Skip to content

Commit 7f354a5

Browse files
rientjestorvalds
authored andcommitted
mm, compaction: add vmstats for kcompactd work
A "compact_daemon_wake" vmstat exists that represents the number of times kcompactd has woken up. This doesn't represent how much work it actually did, though. It's useful to understand how much compaction work is being done by kcompactd versus other methods such as direct compaction and explicitly triggered per-node (or system) compaction. This adds two new vmstats: "compact_daemon_migrate_scanned" and "compact_daemon_free_scanned" to represent the number of pages kcompactd has scanned as part of its migration scanner and freeing scanner, respectively. These values are still accounted for in the general "compact_migrate_scanned" and "compact_free_scanned" for compatibility. It could be argued that explicitly triggered compaction could also be tracked separately, and that could be added if others find it useful. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: David Rientjes <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Joonsoo Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e57b9d8 commit 7f354a5

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

include/linux/vm_event_item.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
5656
COMPACTISOLATED,
5757
COMPACTSTALL, COMPACTFAIL, COMPACTSUCCESS,
5858
KCOMPACTD_WAKE,
59+
KCOMPACTD_MIGRATE_SCANNED, KCOMPACTD_FREE_SCANNED,
5960
#endif
6061
#ifdef CONFIG_HUGETLB_PAGE
6162
HTLB_BUDDY_PGALLOC, HTLB_BUDDY_PGALLOC_FAIL,

mm/compaction.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
548548
if (blockpfn == end_pfn)
549549
update_pageblock_skip(cc, valid_page, total_isolated, false);
550550

551-
count_compact_events(COMPACTFREE_SCANNED, nr_scanned);
551+
cc->total_free_scanned += nr_scanned;
552552
if (total_isolated)
553553
count_compact_events(COMPACTISOLATED, total_isolated);
554554
return total_isolated;
@@ -931,7 +931,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
931931
trace_mm_compaction_isolate_migratepages(start_pfn, low_pfn,
932932
nr_scanned, nr_isolated);
933933

934-
count_compact_events(COMPACTMIGRATE_SCANNED, nr_scanned);
934+
cc->total_migrate_scanned += nr_scanned;
935935
if (nr_isolated)
936936
count_compact_events(COMPACTISOLATED, nr_isolated);
937937

@@ -1631,6 +1631,9 @@ static enum compact_result compact_zone(struct zone *zone, struct compact_contro
16311631
zone->compact_cached_free_pfn = free_pfn;
16321632
}
16331633

1634+
count_compact_events(COMPACTMIGRATE_SCANNED, cc->total_migrate_scanned);
1635+
count_compact_events(COMPACTFREE_SCANNED, cc->total_free_scanned);
1636+
16341637
trace_mm_compaction_end(start_pfn, cc->migrate_pfn,
16351638
cc->free_pfn, end_pfn, sync, ret);
16361639

@@ -1645,6 +1648,8 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
16451648
struct compact_control cc = {
16461649
.nr_freepages = 0,
16471650
.nr_migratepages = 0,
1651+
.total_migrate_scanned = 0,
1652+
.total_free_scanned = 0,
16481653
.order = order,
16491654
.gfp_mask = gfp_mask,
16501655
.zone = zone,
@@ -1757,6 +1762,8 @@ static void compact_node(int nid)
17571762
struct zone *zone;
17581763
struct compact_control cc = {
17591764
.order = -1,
1765+
.total_migrate_scanned = 0,
1766+
.total_free_scanned = 0,
17601767
.mode = MIGRATE_SYNC,
17611768
.ignore_skip_hint = true,
17621769
.whole_zone = true,
@@ -1883,6 +1890,8 @@ static void kcompactd_do_work(pg_data_t *pgdat)
18831890
struct zone *zone;
18841891
struct compact_control cc = {
18851892
.order = pgdat->kcompactd_max_order,
1893+
.total_migrate_scanned = 0,
1894+
.total_free_scanned = 0,
18861895
.classzone_idx = pgdat->kcompactd_classzone_idx,
18871896
.mode = MIGRATE_SYNC_LIGHT,
18881897
.ignore_skip_hint = true,
@@ -1891,7 +1900,7 @@ static void kcompactd_do_work(pg_data_t *pgdat)
18911900
};
18921901
trace_mm_compaction_kcompactd_wake(pgdat->node_id, cc.order,
18931902
cc.classzone_idx);
1894-
count_vm_event(KCOMPACTD_WAKE);
1903+
count_compact_event(KCOMPACTD_WAKE);
18951904

18961905
for (zoneid = 0; zoneid <= cc.classzone_idx; zoneid++) {
18971906
int status;
@@ -1909,6 +1918,8 @@ static void kcompactd_do_work(pg_data_t *pgdat)
19091918

19101919
cc.nr_freepages = 0;
19111920
cc.nr_migratepages = 0;
1921+
cc.total_migrate_scanned = 0;
1922+
cc.total_free_scanned = 0;
19121923
cc.zone = zone;
19131924
INIT_LIST_HEAD(&cc.freepages);
19141925
INIT_LIST_HEAD(&cc.migratepages);
@@ -1927,6 +1938,11 @@ static void kcompactd_do_work(pg_data_t *pgdat)
19271938
defer_compaction(zone, cc.order);
19281939
}
19291940

1941+
count_compact_events(KCOMPACTD_MIGRATE_SCANNED,
1942+
cc.total_migrate_scanned);
1943+
count_compact_events(KCOMPACTD_FREE_SCANNED,
1944+
cc.total_free_scanned);
1945+
19301946
VM_BUG_ON(!list_empty(&cc.freepages));
19311947
VM_BUG_ON(!list_empty(&cc.migratepages));
19321948
}

mm/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ struct compact_control {
175175
struct list_head migratepages; /* List of pages being migrated */
176176
unsigned long nr_freepages; /* Number of isolated free pages */
177177
unsigned long nr_migratepages; /* Number of pages to migrate */
178+
unsigned long total_migrate_scanned;
179+
unsigned long total_free_scanned;
178180
unsigned long free_pfn; /* isolate_freepages search base */
179181
unsigned long migrate_pfn; /* isolate_migratepages search base */
180182
unsigned long last_migrated_pfn;/* Not yet flushed page being freed */

mm/vmstat.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,8 @@ const char * const vmstat_text[] = {
10381038
"compact_fail",
10391039
"compact_success",
10401040
"compact_daemon_wake",
1041+
"compact_daemon_migrate_scanned",
1042+
"compact_daemon_free_scanned",
10411043
#endif
10421044

10431045
#ifdef CONFIG_HUGETLB_PAGE

0 commit comments

Comments
 (0)