Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3606762pxm; Tue, 1 Mar 2022 01:34:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5KA0mlgQJyXhZLY9zS/7ris/qj2r1TEZHlvW0RUzSi11vwizOKKPZZRIvWrlvDGwZyNhG X-Received: by 2002:a05:6402:4396:b0:412:b131:fca6 with SMTP id o22-20020a056402439600b00412b131fca6mr23413848edc.133.1646127275467; Tue, 01 Mar 2022 01:34:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646127275; cv=none; d=google.com; s=arc-20160816; b=RjVBGTCllAbZGU6eTlZQyPg3KWMJaJ1ogD5p86EJYbzV4VSw9+V2BUuj0spNxa6k45 wQ8zyhZjdYhGNQqeMXspQPgkn5oMUkbms1aQSRi74RuPeI+zQroL2zsy/FIyF5jiBQbc 8EzOS9P77/gaYopwaQzwLB4OfKlq4QFjeZrK0hP6+dbOqAelLtwr0njr7nY9EeGPBSkA lZVktyYh40WzOOJGilxv7skBEkzCpvfZvzQfKEoAN/SHXNEdDeM3K1U3rla8yrNy33a0 ZKcTUtNNoPGxP5o67gNf6INUih0xW/DN7lF/WIHuyodLTMXzA8JV917tg0ccUPqE4Iep suNw== 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=TN4P7ZGhEibGkxJTXAWvrGJAPJrh6krmES4YtiU7mC0=; b=iz+x/u9iPPCis6ory9mrCSYkZQGCUrUHW5kSSPV39BWR+WmUY/FTQ+UM5GkCkkH6n7 ITVUbtp60X4eaKO6qoxVGRD+xavAhQvCO1s3wMpjsP1EhxuEF5eusosq0wym+0oHoUAD 7sYw+J+iydE5mMYlHXqF0h5zsrPfln2yacifu5CcOVgNtS9h0iOh3mu9Kgj/bg8iZbD6 NgpTu7Dfddp2vBBEfZgc6AceIro30y52Sj/nbrXlVsgHtDNCPft0kEkpDgDxluXByHFb ZRcPiIZqmAKzWS8lCIpb2UlYM7ooh0t1JOqNrCn61Ae48uQIG6tNECkwBzLElAcsOiiR 2hCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GMddQADa; 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 m23-20020a17090607d700b006b59752f330si7397637ejc.614.2022.03.01.01.34.12; Tue, 01 Mar 2022 01:34:35 -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=GMddQADa; 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 S233637AbiCAIyn (ORCPT + 99 others); Tue, 1 Mar 2022 03:54:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233638AbiCAIyl (ORCPT ); Tue, 1 Mar 2022 03:54:41 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E32E5527D8 for ; Tue, 1 Mar 2022 00:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646124840; x=1677660840; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Is7PELDrfcn7EzisRyWYLhNpJlmmAB/6lqn+KL4wNd4=; b=GMddQADaZVvOq3+nIrAJvivL+VFysOwq7xoSiX3ihF3I5weFmbANdv21 cZZurdWCz2Qn0wlfX1t0FfqYRVRLKYSdLKGBnl5dr8ZKbn1RKwPi2P+Pv +pVA6sQ3j6XRst4cnSUb8NJ5G7j9isJAF48002VKCmU2CSzXMgqxTTa22 ADdMfq1VQDTJ//N9aBk/6DoqbuTS81VdwVbt//9a4vpobvA44KzXhmXMb lCiytfcPFL181ZP1zzSMLWFMJfKAONgmNIIYVByoZQLiyuHkrmlE6Jkk3 wlLjuRT5kOqVk2kndCOl6SFheKXXfNAkGg3FUMRS/Q2K3imrab5xieQcG w==; X-IronPort-AV: E=McAfee;i="6200,9189,10272"; a="253018801" X-IronPort-AV: E=Sophos;i="5.90,145,1643702400"; d="scan'208";a="253018801" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 00:53:58 -0800 X-IronPort-AV: E=Sophos;i="5.90,145,1643702400"; d="scan'208";a="550627144" Received: from yhuang6-desk2.sh.intel.com ([10.239.13.11]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 00:53:52 -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 , Oscar Salvador , Michal Hocko , Rik van Riel , Yang Shi , Zi Yan , Wei Xu , Shakeel Butt , zhongjiang-ali Subject: [PATCH -V14 3/3] memory tiering: skip to scan fast memory Date: Tue, 1 Mar 2022 16:53:29 +0800 Message-Id: <20220301085329.3210428-4-ying.huang@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220301085329.3210428-1-ying.huang@intel.com> References: <20220301085329.3210428-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Reviewed-by: Oscar Salvador 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: 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