Skip to content

Commit 1a5bae2

Browse files
Anshuman Khandualtorvalds
authored andcommitted
mm/vmstat: add events for THP migration without split
Add following new vmstat events which will help in validating THP migration without split. Statistics reported through these new VM events will help in performance debugging. 1. THP_MIGRATION_SUCCESS 2. THP_MIGRATION_FAILURE 3. THP_MIGRATION_SPLIT In addition, these new events also update normal page migration statistics appropriately via PGMIGRATE_SUCCESS and PGMIGRATE_FAILURE. While here, this updates current trace event 'mm_migrate_pages' to accommodate now available THP statistics. [akpm@linux-foundation.org: s/hpage_nr_pages/thp_nr_pages/] [ziy@nvidia.com: v2] Link: http://lkml.kernel.org/r/C5E3C65C-8253-4638-9D3C-71A61858BB8B@nvidia.com [anshuman.khandual@arm.com: s/thp_nr_pages/hpage_nr_pages/] Link: http://lkml.kernel.org/r/1594287583-16568-1-git-send-email-anshuman.khandual@arm.com Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> Signed-off-by: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com> Cc: Hugh Dickins <hughd@google.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Zi Yan <ziy@nvidia.com> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Link: http://lkml.kernel.org/r/1594080415-27924-1-git-send-email-anshuman.khandual@arm.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4958e4d commit 1a5bae2

5 files changed

Lines changed: 91 additions & 11 deletions

File tree

‎Documentation/vm/page_migration.rst‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,32 @@ which are function pointers of struct address_space_operations.
253253
PG_isolated is alias with PG_reclaim flag so driver shouldn't use the flag
254254
for own purpose.
255255

256+
Monitoring Migration
257+
=====================
258+
259+
The following events (counters) can be used to monitor page migration.
260+
261+
1. PGMIGRATE_SUCCESS: Normal page migration success. Each count means that a
262+
page was migrated. If the page was a non-THP page, then this counter is
263+
increased by one. If the page was a THP, then this counter is increased by
264+
the number of THP subpages. For example, migration of a single 2MB THP that
265+
has 4KB-size base pages (subpages) will cause this counter to increase by
266+
512.
267+
268+
2. PGMIGRATE_FAIL: Normal page migration failure. Same counting rules as for
269+
_SUCCESS, above: this will be increased by the number of subpages, if it was
270+
a THP.
271+
272+
3. THP_MIGRATION_SUCCESS: A THP was migrated without being split.
273+
274+
4. THP_MIGRATION_FAIL: A THP could not be migrated nor it could be split.
275+
276+
5. THP_MIGRATION_SPLIT: A THP was migrated, but not as such: first, the THP had
277+
to be split. After splitting, a migration retry was used for it's sub-pages.
278+
279+
THP_MIGRATION_* events also update the appropriate PGMIGRATE_SUCCESS or
280+
PGMIGRATE_FAIL events. For example, a THP migration failure will cause both
281+
THP_MIGRATION_FAIL and PGMIGRATE_FAIL to increase.
282+
256283
Christoph Lameter, May 8, 2006.
257284
Minchan Kim, Mar 28, 2016.

‎include/linux/vm_event_item.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
5656
#endif
5757
#ifdef CONFIG_MIGRATION
5858
PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,
59+
THP_MIGRATION_SUCCESS,
60+
THP_MIGRATION_FAIL,
61+
THP_MIGRATION_SPLIT,
5962
#endif
6063
#ifdef CONFIG_COMPACTION
6164
COMPACTMIGRATE_SCANNED, COMPACTFREE_SCANNED,

‎include/trace/events/migrate.h‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,38 @@ MIGRATE_REASON
4646
TRACE_EVENT(mm_migrate_pages,
4747

4848
TP_PROTO(unsigned long succeeded, unsigned long failed,
49-
enum migrate_mode mode, int reason),
49+
unsigned long thp_succeeded, unsigned long thp_failed,
50+
unsigned long thp_split, enum migrate_mode mode, int reason),
5051

51-
TP_ARGS(succeeded, failed, mode, reason),
52+
TP_ARGS(succeeded, failed, thp_succeeded, thp_failed,
53+
thp_split, mode, reason),
5254

5355
TP_STRUCT__entry(
5456
__field( unsigned long, succeeded)
5557
__field( unsigned long, failed)
58+
__field( unsigned long, thp_succeeded)
59+
__field( unsigned long, thp_failed)
60+
__field( unsigned long, thp_split)
5661
__field( enum migrate_mode, mode)
5762
__field( int, reason)
5863
),
5964

6065
TP_fast_assign(
6166
__entry->succeeded = succeeded;
6267
__entry->failed = failed;
68+
__entry->thp_succeeded = thp_succeeded;
69+
__entry->thp_failed = thp_failed;
70+
__entry->thp_split = thp_split;
6371
__entry->mode = mode;
6472
__entry->reason = reason;
6573
),
6674

67-
TP_printk("nr_succeeded=%lu nr_failed=%lu mode=%s reason=%s",
75+
TP_printk("nr_succeeded=%lu nr_failed=%lu nr_thp_succeeded=%lu nr_thp_failed=%lu nr_thp_split=%lu mode=%s reason=%s",
6876
__entry->succeeded,
6977
__entry->failed,
78+
__entry->thp_succeeded,
79+
__entry->thp_failed,
80+
__entry->thp_split,
7081
__print_symbolic(__entry->mode, MIGRATE_MODE),
7182
__print_symbolic(__entry->reason, MIGRATE_REASON))
7283
);

‎mm/migrate.c‎

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,22 +1418,35 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
14181418
enum migrate_mode mode, int reason)
14191419
{
14201420
int retry = 1;
1421+
int thp_retry = 1;
14211422
int nr_failed = 0;
14221423
int nr_succeeded = 0;
1424+
int nr_thp_succeeded = 0;
1425+
int nr_thp_failed = 0;
1426+
int nr_thp_split = 0;
14231427
int pass = 0;
1428+
bool is_thp = false;
14241429
struct page *page;
14251430
struct page *page2;
14261431
int swapwrite = current->flags & PF_SWAPWRITE;
1427-
int rc;
1432+
int rc, nr_subpages;
14281433

14291434
if (!swapwrite)
14301435
current->flags |= PF_SWAPWRITE;
14311436

1432-
for(pass = 0; pass < 10 && retry; pass++) {
1437+
for (pass = 0; pass < 10 && (retry || thp_retry); pass++) {
14331438
retry = 0;
1439+
thp_retry = 0;
14341440

14351441
list_for_each_entry_safe(page, page2, from, lru) {
14361442
retry:
1443+
/*
1444+
* THP statistics is based on the source huge page.
1445+
* Capture required information that might get lost
1446+
* during migration.
1447+
*/
1448+
is_thp = PageTransHuge(page);
1449+
nr_subpages = hpage_nr_pages(page);
14371450
cond_resched();
14381451

14391452
if (PageHuge(page))
@@ -1464,15 +1477,30 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
14641477
unlock_page(page);
14651478
if (!rc) {
14661479
list_safe_reset_next(page, page2, lru);
1480+
nr_thp_split++;
14671481
goto retry;
14681482
}
14691483
}
1484+
if (is_thp) {
1485+
nr_thp_failed++;
1486+
nr_failed += nr_subpages;
1487+
goto out;
1488+
}
14701489
nr_failed++;
14711490
goto out;
14721491
case -EAGAIN:
1492+
if (is_thp) {
1493+
thp_retry++;
1494+
break;
1495+
}
14731496
retry++;
14741497
break;
14751498
case MIGRATEPAGE_SUCCESS:
1499+
if (is_thp) {
1500+
nr_thp_succeeded++;
1501+
nr_succeeded += nr_subpages;
1502+
break;
1503+
}
14761504
nr_succeeded++;
14771505
break;
14781506
default:
@@ -1482,19 +1510,27 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
14821510
* removed from migration page list and not
14831511
* retried in the next outer loop.
14841512
*/
1513+
if (is_thp) {
1514+
nr_thp_failed++;
1515+
nr_failed += nr_subpages;
1516+
break;
1517+
}
14851518
nr_failed++;
14861519
break;
14871520
}
14881521
}
14891522
}
1490-
nr_failed += retry;
1523+
nr_failed += retry + thp_retry;
1524+
nr_thp_failed += thp_retry;
14911525
rc = nr_failed;
14921526
out:
1493-
if (nr_succeeded)
1494-
count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded);
1495-
if (nr_failed)
1496-
count_vm_events(PGMIGRATE_FAIL, nr_failed);
1497-
trace_mm_migrate_pages(nr_succeeded, nr_failed, mode, reason);
1527+
count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded);
1528+
count_vm_events(PGMIGRATE_FAIL, nr_failed);
1529+
count_vm_events(THP_MIGRATION_SUCCESS, nr_thp_succeeded);
1530+
count_vm_events(THP_MIGRATION_FAIL, nr_thp_failed);
1531+
count_vm_events(THP_MIGRATION_SPLIT, nr_thp_split);
1532+
trace_mm_migrate_pages(nr_succeeded, nr_failed, nr_thp_succeeded,
1533+
nr_thp_failed, nr_thp_split, mode, reason);
14981534

14991535
if (!swapwrite)
15001536
current->flags &= ~PF_SWAPWRITE;

‎mm/vmstat.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,9 @@ const char * const vmstat_text[] = {
12771277
#ifdef CONFIG_MIGRATION
12781278
"pgmigrate_success",
12791279
"pgmigrate_fail",
1280+
"thp_migration_success",
1281+
"thp_migration_fail",
1282+
"thp_migration_split",
12801283
#endif
12811284
#ifdef CONFIG_COMPACTION
12821285
"compact_migrate_scanned",

0 commit comments

Comments
 (0)