Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp259819pxb; Mon, 13 Sep 2021 18:39:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4O5cTAO1W+EDePSUI7Zz5VSbWdwUqoalMNqiqS7ZNRGwFDrjSh8m/DraJ4b1EEMfFBs49 X-Received: by 2002:a50:cb8b:: with SMTP id k11mr16305759edi.256.1631583563774; Mon, 13 Sep 2021 18:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631583563; cv=none; d=google.com; s=arc-20160816; b=QlipRwZlUrXxM8l4egMxKBzv1d6Zg2KEecBB/+BGVFsnpbp77X37hMGJ8yqi3X7X1Z JmBP6KrNwrRrbjOpcxfB7fMFN791o+LQrxUGplaAQJZZ7WjNv0+lXqQ0jzBfqVrbO+gN F6RLqaNoQhCe4oSxrXMuf5/Yh7vJb0EH5Pcl45MCai5VkddZtbZ0t+47xf6rqhKu0RDa QhrSftD/Xb6zPsdZQsezHfrNYI0LSJ4DMdRKOYnRuHnhYw/ESz0XZsmMLAzWWcz+T0WU MBOT6WvJ7J1aTxHxNjY4d3MUr40CusXEtydpFW+1Wuk8na3Ajvw6xWn+FwviYhH6VhMZ sJyQ== 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=gRj8TnVxK3cIieXPpy3WTIQW7tRHZA/Iq9nU5OFYU85dN486PfpuccizRJXiic5Evj g/WGtu4GXMj31e8eg1msntbUOkeyl3ENMMbu91sbNgGUpc3aBNxCyP2HUzUkHNq456yw Ju9pze1tLlAVjHAjTh5JyC+6wEXD3mycga/FJ0+COGsx8UGjCpZhcumBV4e7yEVjEhgd kUFxILezPFkHaLDHeJmcNETHjpQeWvBZnVFVHfzrnal+IsMRWD3Mm7eEyvDwCTeaZlpj IXOSATKpZ9VKRMi2F4LS20+XPIrzhm2LyMFmnO5NNecJWKjqYU3b2AFktrwy7KV8oqou +P9g== 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 b5si8756875edx.499.2021.09.13.18.39.00; Mon, 13 Sep 2021 18:39:23 -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 S234829AbhINBiv (ORCPT + 99 others); Mon, 13 Sep 2021 21:38:51 -0400 Received: from mga05.intel.com ([192.55.52.43]:19808 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234945AbhINBio (ORCPT ); Mon, 13 Sep 2021 21:38:44 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10106"; a="307395560" X-IronPort-AV: E=Sophos;i="5.85,291,1624345200"; d="scan'208";a="307395560" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 18:37:28 -0700 X-IronPort-AV: E=Sophos;i="5.85,291,1624345200"; d="scan'208";a="543575396" Received: from yhuang6-desk2.sh.intel.com ([10.239.159.119]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 18:37:24 -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 -V8 3/6] memory tiering: skip to scan fast memory Date: Tue, 14 Sep 2021 09:36:58 +0800 Message-Id: <20210914013701.344956-4-ying.huang@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210914013701.344956-1-ying.huang@intel.com> References: <20210914013701.344956-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