Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2147886pxb; Fri, 8 Oct 2021 01:42:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPZ/xMDpUuhFUaK4pyU+3pCgeHNtpXNImtJLrmSAFS9XouT4se5j1bBbC4mBejr8/pbQmf X-Received: by 2002:aa7:9f8f:0:b0:44c:cf63:ec7c with SMTP id z15-20020aa79f8f000000b0044ccf63ec7cmr5455552pfr.77.1633682572638; Fri, 08 Oct 2021 01:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633682572; cv=none; d=google.com; s=arc-20160816; b=PnBVpDgCIp09jN3A9KsD3A8nQUQeVMJMvR+XvjPYiUnBmw9CoUzVTPlmvtcaBHSDvv JX4O9RHfx0oVyjKElFE2iGCak6K3PPK06bo40ClkZw84AQ0Y6SjTnsvZQPGbWicNuPKp jl49dRUmP1MpYF2z4i5nDIg54yCzhD14dO1YLX+Pq1KNqUjNvTUKgFxo41vDEegxdF2z NUO0QFDnVkkD7zvOgGuA3PuHkkdoV34kG3IFx5fZu2wR3Yyh9f4kgBATqzpscqQfPwmX qiXNfwN13skbetTg0BrCzDmrgqC8lFha0esMVKJGKp+O28+v+2JSQhgehscrpjcHm78h oYRw== 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; bh=EJTYR3dmaeM6aaeq8aexNTNTDuAAQD9h7zLc3ICSgr4=; b=GoXCctkfxuifLZCjwymh7YKn1kETGUAA9iOgFZUwOlMtsyI0VJtwLtCj7ZBDii10ix R38aPZUHVrdRPhVd2X8gkMZk7DWcec13cOw33AoPsgk+5Bd/fxm5gWOncFWfWyg+Wc1m XCZa2whkcu2F0ibBLrordWyUy8S9gMV8JOdKuqaG1pVYwLPP7ILCKaS2z2sGWDmUU0d/ xeNk/QEkgkcHGmI7P3g8XbuaPhRO3DlXXM262Tz9HMUEX0AcjbgVFtrzykA15VgBBw21 QVtvrbHfhEDgZ2/5oinfjdFLL7MtLZVam9G3YOI6LF8CQxFR+tpkCAlXzKj+prNu246X ly3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si2148263plb.162.2021.10.08.01.42.39; Fri, 08 Oct 2021 01:42:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235233AbhJHImr (ORCPT + 99 others); Fri, 8 Oct 2021 04:42:47 -0400 Received: from mga18.intel.com ([134.134.136.126]:39515 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235222AbhJHIme (ORCPT ); Fri, 8 Oct 2021 04:42:34 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="213413444" X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="213413444" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 01:40:06 -0700 X-IronPort-AV: E=Sophos;i="5.85,357,1624345200"; d="scan'208";a="439860376" Received: from yhuang6-desk2.sh.intel.com ([10.239.159.119]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 01:40:02 -0700 From: Huang Ying To: linux-kernel@vger.kernel.org Cc: Huang Ying , Dave Hansen , Andrew Morton , Michal Hocko , Rik van Riel , Mel Gorman , Peter Zijlstra , Yang Shi , Zi Yan , Wei Xu , osalvador , Shakeel Butt , linux-mm@kvack.org Subject: [PATCH -V9 3/6] memory tiering: skip to scan fast memory Date: Fri, 8 Oct 2021 16:39:35 +0800 Message-Id: <20211008083938.1702663-4-ying.huang@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211008083938.1702663-1-ying.huang@intel.com> References: <20211008083938.1702663-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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: osalvador Cc: Shakeel Butt 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 5e9ef0fc261e..8edcd64b5b1f 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 883e2cc85cad..0dd3f82ec6eb 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