Received: by 10.192.165.156 with SMTP id m28csp430686imm; Wed, 11 Apr 2018 01:14:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/D0ZpX3s93gGPn61WrRC6/AI8YeAzYEzr0B9WYKQfPIdNHkvv+E5octg5C97M7QZEx26xV X-Received: by 2002:a17:902:5581:: with SMTP id g1-v6mr3974800pli.351.1523434486985; Wed, 11 Apr 2018 01:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523434486; cv=none; d=google.com; s=arc-20160816; b=GC2ccjIP1XBu4lBErNqLBbKjCnvhyZO+J2hVRNDxUKufoKWAf2Bnf8HmhH0eMhC2eq OsC4JcJ5rKbyqnkmj4XPbAfwDl+tncpk8G1SX9T1x2NkmU5tHX1B3/7NLlX0Td4DE7WI sWPp6stEnCU6m6MyJKyy4vv8W4X/AgR8JkLnLJT/SveN47kf3efAqNjOi41X+uSNpcot 5C0ECv6ItMUJaU2Xzi9kWM4ni8+k4xl29b5HdEaCjRG/kEot2w+QE04aA0l9Irw8Dqkd KFOPb3E9SQ2B6B+fPfHwYi41AtIm8DzCAkHUGdSUd4d/aS3TV4N5I5r3KJulKM43LCq1 ifow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=v2LKeuiW9G86YteXt9buCzpGY1/7W0bsBVShGt+34RU=; b=SoBH7DNOCNSj60+rV7/PFb8pH6OKprzClaDxGm9x7qYTbPObleMlZ83eluLOiV23dO jGw2wroojNZyK10URHZfxBk7IqLVxFuwv1rNYSqvXr20Kt5QkVa6FhpaY4qyLXOLdRDT 9ilcOtNiOgLlHt2NHsS6h6OHD6kNx1nMk4sJNxWr82rhZL0V3TwhX6IfGyelIb+NxDMq H5b4NAvVycp7rR1kbyH/djigH2TGq2rql0AoqB9vAT8dVlytU4CFGD+wJfzYjqOEhFsv ExqLJeOLAS8H+f6a3t/zQNT1tV5efUPh0i//rCpCekbXPUJR2+OUxtOY6TT7zknVTBAp 4T9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YY7Fps6W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e32-v6si655648plb.135.2018.04.11.01.14.09; Wed, 11 Apr 2018 01:14:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YY7Fps6W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752724AbeDKIKC (ORCPT + 99 others); Wed, 11 Apr 2018 04:10:02 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:46520 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752521AbeDKIJl (ORCPT ); Wed, 11 Apr 2018 04:09:41 -0400 Received: by mail-pl0-f65.google.com with SMTP id 59-v6so806947plc.13 for ; Wed, 11 Apr 2018 01:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=v2LKeuiW9G86YteXt9buCzpGY1/7W0bsBVShGt+34RU=; b=YY7Fps6WbM8akzqFm8FeOjN7OBg1fYn80/NQvPj4CiY4p4l+blbOnyi8IAZZI0Ah5A nnPTB/7UQwvlFizrSdOeFvdQaLTPJHwp8d8HqRmHvGQkqs3crrFR2kpqL2xe1QEu8kOy NeZprxIa5Baao9gOIOh8GNwW9JXFfkHwxbWXPkpC8qPw9T9PQzlhWE8f7UPpz67GmYmB EEeOyB00nfXWMfp2n/e808tqElSKVyVy/TFXYPIQpEvuh+rp2IpYoG8TPI2W/X68qXyy 8PLLZ4JkBKCp6tAbarP8yu/0LERb8VwneEVVtamAOZu8mPDVS+gRIvwZqYJ0HOwrMZ2O ZM3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=v2LKeuiW9G86YteXt9buCzpGY1/7W0bsBVShGt+34RU=; b=LOW5FODfXiBy/SIqC8N0UBGPl4fCCVr+P6kMuZ0JjKbwWisOo0xIps9aRcMDRRv2Jk A/T8E+VBmui6K4hABkcDAAwAC03ajhiGx5nOWQuMnGmyjAdL8attIij6jLNg7TejWLNQ 5xEw+MlRTw1za95ithDqMuuSUTQcmlODbNHQIH4ProF04gDgCv8vFQCPcXPpUs3tBIpB R4HwGaYr3vCbUi4gA5c7gmlRUr8eE2LGniDkvoeE+uSH+EGwHKLKU/JGl9K3YbDtEgc6 kAyf4xYByu+C5C1unJx6LipnhyI1uoEGvo0u/SQKLYkBEyS0W26MwsbQ2G1vCPtDWwBv 1+8A== X-Gm-Message-State: ALQs6tAJ1fcMi6DFS0Y/MIapFMz52vcTkzfgKj9Eh2/aoRz0mg1UC2/u Mu+6w6jTreY+HtreISA7oA== X-Received: by 2002:a17:902:24c7:: with SMTP id l7-v6mr3943419plg.320.1523434180990; Wed, 11 Apr 2018 01:09:40 -0700 (PDT) Received: from www9186uo.sakura.ne.jp (www9186uo.sakura.ne.jp. [153.121.56.200]) by smtp.gmail.com with ESMTPSA id b13sm1568311pfi.169.2018.04.11.01.09.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Apr 2018 01:09:40 -0700 (PDT) From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Michal Hocko , Zi Yan , "Kirill A. Shutemov" , Andrew Morton , Vlastimil Babka , linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] mm: migrate: add vm event counters thp_migrate_(success|fail) Date: Wed, 11 Apr 2018 17:09:26 +0900 Message-Id: <1523434167-19995-2-git-send-email-n-horiguchi@ah.jp.nec.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1523434167-19995-1-git-send-email-n-horiguchi@ah.jp.nec.com> References: <1523434167-19995-1-git-send-email-n-horiguchi@ah.jp.nec.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currenly we have some vm event counters for page migration, but all migration events are counted in a single value regardless of page size. That is not good for end users who are interested in knowing whether hugepage migration works. So this patch is suggesting to add separate counters for thp migration. Note that when thp migration fails due to ENOMEM or the lack of thp migration support, the event is not counted in thp_migrate_fail and we transparently retry the subpages' migrations. Another note is that the return value of migrate_pages(), which is claimed as "the number of pages that were not migrated (positive) or an error code (negative)," doesn't consider the page size now. We could do this for example by counting a single failure of thp migration event as 512, but this patch doesn't do it for simplicity. It seems to me that there is no migrate_pages()'s caller which cares about the number itself of the positive return value, so this should not be critical for now. Signed-off-by: Naoya Horiguchi --- include/linux/vm_event_item.h | 4 ++ mm/migrate.c | 93 +++++++++++++++++++++++++++++++++++-------- mm/vmstat.c | 4 ++ 3 files changed, 85 insertions(+), 16 deletions(-) diff --git v4.16-mmotm-2018-04-10-17-02/include/linux/vm_event_item.h v4.16-mmotm-2018-04-10-17-02_patched/include/linux/vm_event_item.h index 5c7f010..fa2d2e0 100644 --- v4.16-mmotm-2018-04-10-17-02/include/linux/vm_event_item.h +++ v4.16-mmotm-2018-04-10-17-02_patched/include/linux/vm_event_item.h @@ -88,6 +88,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, THP_ZERO_PAGE_ALLOC_FAILED, THP_SWPOUT, THP_SWPOUT_FALLBACK, +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + THP_MIGRATE_SUCCESS, + THP_MIGRATE_FAIL, +#endif #endif #ifdef CONFIG_MEMORY_BALLOON BALLOON_INFLATE, diff --git v4.16-mmotm-2018-04-10-17-02/mm/migrate.c v4.16-mmotm-2018-04-10-17-02_patched/mm/migrate.c index bb6367d..46ff23a 100644 --- v4.16-mmotm-2018-04-10-17-02/mm/migrate.c +++ v4.16-mmotm-2018-04-10-17-02_patched/mm/migrate.c @@ -1348,6 +1348,69 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, return rc; } +enum migrate_result_type { + MIGRATE_SUCCEED, + MIGRATE_FAIL, + MIGRATE_RETRY, + MIGRATE_RESULT_TYPES +}; + +enum migrate_page_type { + MIGRATE_PAGE_NORMAL, +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + MIGRATE_PAGE_THP, +#endif + MIGRATE_PAGE_TYPES +}; + +static struct migrate_event { + int succeeded; + int failed; +} migrate_events[] = { + { PGMIGRATE_SUCCESS, PGMIGRATE_FAIL }, +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + { THP_MIGRATE_SUCCESS, THP_MIGRATE_FAIL }, +#endif +}; + +static inline enum migrate_page_type get_type(struct page *page) +{ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + if (PageTransHuge(page)) + return MIGRATE_PAGE_THP; +#endif + return MIGRATE_PAGE_NORMAL; +} + +static inline int get_count(int array[][MIGRATE_PAGE_TYPES], int type) +{ + int i, ret; + + for (i = 0, ret = 0; i < MIGRATE_PAGE_TYPES; i++) + ret += array[type][i]; + return ret; +} + +static inline void reset_nr_retry(int array[][MIGRATE_PAGE_TYPES]) +{ + int i; + + for (i = 0; i < MIGRATE_PAGE_TYPES; i++) + array[MIGRATE_RETRY][i] = 0; +} + +static inline void update_vm_migrate_events(int array[][MIGRATE_PAGE_TYPES]) +{ + int i; + + for (i = 0; i < MIGRATE_PAGE_TYPES; i++) { + count_vm_events(migrate_events[i].succeeded, + array[MIGRATE_SUCCEED][i]); + count_vm_events(migrate_events[i].failed, + array[MIGRATE_FAIL][i]); + } +} + /* * migrate_pages - migrate the pages specified in a list, to the free pages * supplied as the target for the page migration @@ -1373,9 +1436,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, free_page_t put_new_page, unsigned long private, enum migrate_mode mode, int reason) { - int retry = 1; - int nr_failed = 0; - int nr_succeeded = 0; + int counts[MIGRATE_RESULT_TYPES][MIGRATE_PAGE_TYPES] = {0}; int pass = 0; struct page *page; struct page *page2; @@ -1385,13 +1446,16 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, if (!swapwrite) current->flags |= PF_SWAPWRITE; - for(pass = 0; pass < 10 && retry; pass++) { - retry = 0; + for (pass = 0; !pass || (pass < 10 && get_count(counts, MIGRATE_RETRY)); + pass++) { + reset_nr_retry(counts); list_for_each_entry_safe(page, page2, from, lru) { + enum migrate_page_type mpt; retry: cond_resched(); + mpt = get_type(page); if (PageHuge(page)) rc = unmap_and_move_huge_page(get_new_page, put_new_page, private, page, @@ -1423,13 +1487,13 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, goto retry; } } - nr_failed++; + counts[MIGRATE_FAIL][mpt]++; goto out; case -EAGAIN: - retry++; + counts[MIGRATE_RETRY][mpt]++; break; case MIGRATEPAGE_SUCCESS: - nr_succeeded++; + counts[MIGRATE_SUCCEED][mpt]++; break; default: /* @@ -1438,19 +1502,16 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, * removed from migration page list and not * retried in the next outer loop. */ - nr_failed++; + counts[MIGRATE_FAIL][mpt]++; break; } } } - nr_failed += retry; - rc = nr_failed; + rc = get_count(counts, MIGRATE_FAIL) + get_count(counts, MIGRATE_RETRY); out: - if (nr_succeeded) - 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); + update_vm_migrate_events(counts); + trace_mm_migrate_pages(get_count(counts, MIGRATE_SUCCEED), rc, + mode, reason); if (!swapwrite) current->flags &= ~PF_SWAPWRITE; diff --git v4.16-mmotm-2018-04-10-17-02/mm/vmstat.c v4.16-mmotm-2018-04-10-17-02_patched/mm/vmstat.c index 536332e..57e9cc3 100644 --- v4.16-mmotm-2018-04-10-17-02/mm/vmstat.c +++ v4.16-mmotm-2018-04-10-17-02_patched/mm/vmstat.c @@ -1263,6 +1263,10 @@ const char * const vmstat_text[] = { "thp_zero_page_alloc_failed", "thp_swpout", "thp_swpout_fallback", +#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION + "thp_migrate_success", + "thp_migrate_fail", +#endif #endif #ifdef CONFIG_MEMORY_BALLOON "balloon_inflate", -- 2.7.0