Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3625335pxb; Mon, 21 Feb 2022 02:09:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyl+gSeJbBvamxKfpafCroZk1pLcqkSrhW4hkHOswm06V3UcvhMPZUb7w0wXgw14dBpoj+g X-Received: by 2002:a17:906:f851:b0:6cf:5cbb:df65 with SMTP id ks17-20020a170906f85100b006cf5cbbdf65mr15392788ejb.508.1645438150215; Mon, 21 Feb 2022 02:09:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645438150; cv=none; d=google.com; s=arc-20160816; b=f7KkWOT+dYjcV2T26S/atGBjO5BsvWRVHtjhkm2ThrlvXA3sLdGcx2jD9vX+raa9H+ RP1hhsyie4893j1+2vsrpDvfoxJjOUjNjr3pbtl5gAERw74XiMOgbrAz0KNxG05s+z5a OCJ9MNBkXhbuN7+wc2rY9qbv5PxxVFTo82T5sBSSqtSYvYLqpZygYTKdDDmUQNlBbVof SV8dOVqTdnTMNj1dx1bQ6JnvRE9NqdlcvMlFhvTkXxMMsV3NJ8WFpAQ8xqTKLxWSFTcu rXvuo+rwGg4XU9s90XUUb9iSYHrcS8ikKdH5OQgjOLFl3onVOdN0lUQBFI22MF5LD+JM WckA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=isCbajgNvni6PZ2eBDthFmMUZmlm9tMYzlUYs9QsX4w=; b=Ix+IPSGBjzXWiOSNI83zaJFXArJmPaBCYTWH72Q/Qj3qMtKmfqzyBAFHImUwwlUkWC 5OSxcwvRO8PkmUFt0vRiPiRednxOuz980MBh2KPRXqLr64xC2JdsIORNy1xs4CHFtOdh usuOczrwro1QtGIiFwvB9gswxYwcjqFo2RlquRdeiqvEqyEEfTNqVQwHrBbQfuUghav6 Zxb59YQidHsFRWqcaA/uXQZcs+uQzedqnbQ7u6bORPXqtmZ0byfqHL0G18Gi0+UA6jiP eDRz5rR0WqJ2CKAB4ffeafcTdW7cFyscLMEgK5oNGV+WfEX2arH5ivwHWvn37+16pilH X1Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Z2fDi7dx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ck26si1665906ejb.423.2022.02.21.02.08.47; Mon, 21 Feb 2022 02:09:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Z2fDi7dx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344769AbiBUIqd (ORCPT + 99 others); Mon, 21 Feb 2022 03:46:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344711AbiBUIq3 (ORCPT ); Mon, 21 Feb 2022 03:46:29 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDF2913DEB for ; Mon, 21 Feb 2022 00:45:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645433159; x=1676969159; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=psltTbQSqTHI37Tn5wwsvdJ9MbHsDu951d9NJsQVf2A=; b=Z2fDi7dxatJxTep6hobC5GzgOo5KJgbztuhfb7XXLIoDoB1ae2g8W0wt os2ZrIPVX+qKKBUYYphb0/QMS4iJGSunrI0S38ouBTrqBtjV4H2KaWICE VQYBIwxxBcI4ncGUfrcFhCoMRw+PvTcCRGSfO1ahvF85uzR44Lz16Mr9u 2fDf1rcoERulZLiYaxzZ4j6WKA4/271Zx92m8toZOBTCCIsi9iaHnjBzA 8DokxvzGpwmfC5ATW40q0av2PDomgsaIfso06NNfyCZnEKstDcxjYjA3/ r4nxwDOu9Utf+n+8zXVNL88NPNu8smFX7Yu2HX8CKtRfXgooUaXjR/8P/ Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10264"; a="249045817" X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="249045817" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2022 00:45:59 -0800 X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="531774883" Received: from yhuang6-desk2.sh.intel.com ([10.239.13.11]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2022 00:45:55 -0800 From: Huang Ying To: Peter Zijlstra , Mel Gorman , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Feng Tang , Huang Ying , Dave Hansen , Baolin Wang , Johannes Weiner , Michal Hocko , Rik van Riel , Yang Shi , Zi Yan , Wei Xu , Oscar Salvador , Shakeel Butt , zhongjiang-ali Subject: [PATCH -V13 3/3] memory tiering: skip to scan fast memory Date: Mon, 21 Feb 2022 16:45:29 +0800 Message-Id: <20220221084529.1052339-4-ying.huang@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220221084529.1052339-1-ying.huang@intel.com> References: <20220221084529.1052339-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the NUMA balancing isn't used to optimize the page placement among sockets but only among memory types, the hot pages in the fast memory node couldn't be migrated (promoted) to anywhere. So it's unnecessary to scan the pages in the fast memory node via changing their PTE/PMD mapping to be PROT_NONE. So that the page faults could be avoided too. In the test, if only the memory tiering NUMA balancing mode is enabled, the number of the NUMA balancing hint faults for the DRAM node is reduced to almost 0 with the patch. While the benchmark score doesn't change visibly. Signed-off-by: "Huang, Ying" Suggested-by: Dave Hansen Tested-by: Baolin Wang Reviewed-by: Baolin Wang Acked-by: Johannes Weiner Cc: Andrew Morton Cc: Michal Hocko Cc: Rik van Riel Cc: Mel Gorman Cc: Peter Zijlstra Cc: Yang Shi Cc: Zi Yan Cc: Wei Xu Cc: Oscar Salvador Cc: Shakeel Butt Cc: zhongjiang-ali Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org --- mm/huge_memory.c | 30 +++++++++++++++++++++--------- mm/mprotect.c | 13 ++++++++++++- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 406a3c28c026..9ce126cb0cfd 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -1766,17 +1767,28 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, } #endif - /* - * Avoid trapping faults against the zero page. The read-only - * data is likely to be read-cached on the local CPU and - * local/remote hits to the zero page are not interesting. - */ - if (prot_numa && is_huge_zero_pmd(*pmd)) - goto unlock; + if (prot_numa) { + struct page *page; + /* + * Avoid trapping faults against the zero page. The read-only + * data is likely to be read-cached on the local CPU and + * local/remote hits to the zero page are not interesting. + */ + if (is_huge_zero_pmd(*pmd)) + goto unlock; - if (prot_numa && pmd_protnone(*pmd)) - goto unlock; + if (pmd_protnone(*pmd)) + goto unlock; + page = pmd_page(*pmd); + /* + * Skip scanning top tier node if normal numa + * balancing is disabled + */ + if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL) && + node_is_toptier(page_to_nid(page))) + goto unlock; + } /* * In case prot_numa, we are under mmap_read_lock(mm). It's critical * to not clear pmd intermittently to avoid race with MADV_DONTNEED diff --git a/mm/mprotect.c b/mm/mprotect.c index 0138dfcdb1d8..2fe03e695c81 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -83,6 +84,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, */ if (prot_numa) { struct page *page; + int nid; /* Avoid TLB flush if possible */ if (pte_protnone(oldpte)) @@ -109,7 +111,16 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, * Don't mess with PTEs if page is already on the node * a single-threaded process is running on. */ - if (target_node == page_to_nid(page)) + nid = page_to_nid(page); + if (target_node == nid) + continue; + + /* + * Skip scanning top tier node if normal numa + * balancing is disabled + */ + if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL) && + node_is_toptier(nid)) continue; } -- 2.30.2