From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF849CA9EC9 for ; Fri, 1 Nov 2019 07:58:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A4F292080F for ; Fri, 1 Nov 2019 07:58:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4F292080F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4AE7A6B0269; Fri, 1 Nov 2019 03:58:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40CF76B026A; Fri, 1 Nov 2019 03:58:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 289496B026B; Fri, 1 Nov 2019 03:58:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EAD046B0269 for ; Fri, 1 Nov 2019 03:58:37 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 899762A87 for ; Fri, 1 Nov 2019 07:58:37 +0000 (UTC) X-FDA: 76106956674.26.toes94_10dc95fc38c40 X-HE-Tag: toes94_10dc95fc38c40 X-Filterd-Recvd-Size: 7324 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Fri, 1 Nov 2019 07:58:35 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Nov 2019 00:58:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,254,1569308400"; d="scan'208";a="225962493" Received: from yhuang-dev.sh.intel.com ([10.239.159.29]) by fmsmga004.fm.intel.com with ESMTP; 01 Nov 2019 00:58:33 -0700 From: "Huang, Ying" To: Peter Zijlstra Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Andrew Morton , Michal Hocko , Rik van Riel , Mel Gorman , Ingo Molnar , Dave Hansen , Dan Williams , Fengguang Wu Subject: [RFC 05/10] autonuma, memory tiering: Use kswapd to demote cold pages to PMEM Date: Fri, 1 Nov 2019 15:57:22 +0800 Message-Id: <20191101075727.26683-6-ying.huang@intel.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191101075727.26683-1-ying.huang@intel.com> References: <20191101075727.26683-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Huang Ying In a memory tiering system, if the memory size of the workloads is smaller than that of the faster memory (e.g. DRAM) nodes, all pages of the workloads should be put in the faster memory nodes. But this makes it unnecessary to use slower memory (e.g. PMEM) at all. So in common cases, the memory size of the workload should be larger than that of the faster memory nodes. And to optimize the performance, the hot pages should be promoted to the faster memory nodes while the cold pages should be demoted to the slower memory nodes. To achieve that, we have two choices, a. Promote the hot pages from the slower memory node to the faster memory node. This will create some memory pressure in the faster memory node, thus trigger the memory reclaiming, where the cold pages will be demoted to the slower memory node. b. Demote the cold pages from faster memory node to the slower memory node. This will create some free memory space in the faster memory node, and the hot pages in the slower memory node could be promoted to the faster memory node. The choice "a" will create the memory pressure in the faster memory node. If the memory pressure of the workload is high too, the memory pressure may become so high that the memory allocation latency of the workload is influenced, e.g. the direct reclaiming may be triggered. The choice "b" works much better at this aspect. If the memory pressure of the workload is high, it will consume the free memory and the hot pages promotion will stop earlier if its allocation watermark is higher than that of the normal memory allocation. In this patch, choice "b" is implemented. If memory tiering NUMA balancing mode is enabled, the node isn't the slowest node, and the free memory size of the node is below the high watermark, the kswapd of the node will be waken up to free some memory until the free memory size is above the high watermark + autonuma promotion rate limit. If the free memory size is below the high watermark, autonuma promotion will stop working. This avoids to create too much memory pressure to the system. Signed-off-by: "Huang, Ying" Cc: Andrew Morton Cc: Michal Hocko Cc: Rik van Riel Cc: Mel Gorman Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Dave Hansen Cc: Dan Williams Cc: Fengguang Wu Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org --- mm/migrate.c | 26 +++++++++++++++++--------- mm/vmscan.c | 7 +++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 8f06bd37d927..dd9e31416c10 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -47,6 +47,7 @@ #include #include #include +#include =20 #include =20 @@ -1939,8 +1940,7 @@ COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, comp= at_ulong_t, nr_pages, * Returns true if this is a safe migration target node for misplaced NU= MA * pages. Currently it only checks the watermarks which crude */ -static bool migrate_balanced_pgdat(struct pglist_data *pgdat, - unsigned long nr_migrate_pages) +static bool migrate_balanced_pgdat(struct pglist_data *pgdat, int order) { int z; =20 @@ -1951,12 +1951,9 @@ static bool migrate_balanced_pgdat(struct pglist_d= ata *pgdat, continue; =20 /* Avoid waking kswapd by allocating pages_to_migrate pages. */ - if (!zone_watermark_ok(zone, 0, - high_wmark_pages(zone) + - nr_migrate_pages, - ZONE_MOVABLE, 0)) - continue; - return true; + if (zone_watermark_ok(zone, order, high_wmark_pages(zone), + ZONE_MOVABLE, 0)) + return true; } return false; } @@ -1983,8 +1980,19 @@ static int numamigrate_isolate_page(pg_data_t *pgd= at, struct page *page) VM_BUG_ON_PAGE(compound_order(page) && !PageTransHuge(page), page); =20 /* Avoid migrating to a node that is nearly full */ - if (!migrate_balanced_pgdat(pgdat, 1UL << compound_order(page))) + if (!migrate_balanced_pgdat(pgdat, compound_order(page))) { + if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) { + int z; + + for (z =3D pgdat->nr_zones - 1; z >=3D 0; z--) { + if (populated_zone(pgdat->node_zones + z)) + break; + } + wakeup_kswapd(pgdat->node_zones + z, + 0, compound_order(page), ZONE_MOVABLE); + } return 0; + } =20 if (isolate_lru_page(page)) return 0; diff --git a/mm/vmscan.c b/mm/vmscan.c index 6867b49ce360..ecc7f66ee2c3 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -57,6 +57,7 @@ =20 #include #include +#include =20 #include "internal.h" =20 @@ -3336,8 +3337,11 @@ static bool pgdat_balanced(pg_data_t *pgdat, int o= rder, int classzone_idx) { int i; unsigned long mark =3D -1; + unsigned long promote_ratelimit; struct zone *zone; =20 + promote_ratelimit =3D sysctl_numa_balancing_rate_limit << + (20 - PAGE_SHIFT); /* * Check watermarks bottom-up as lower zones are more likely to * meet watermarks. @@ -3349,6 +3353,9 @@ static bool pgdat_balanced(pg_data_t *pgdat, int or= der, int classzone_idx) continue; =20 mark =3D high_wmark_pages(zone); + if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING && + next_migration_node(pgdat->node_id) !=3D -1) + mark +=3D promote_ratelimit; if (zone_watermark_ok_safe(zone, order, mark, classzone_idx)) return true; } --=20 2.23.0