Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2153341pxb; Sun, 30 Jan 2022 06:46:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXUcPWcAPrd5ianOS5tu387Dd9ypze4Z3bjLjNuT0ZHZd44bdQfVv2by5iTpq4Cp1E9gOb X-Received: by 2002:a05:6402:4256:: with SMTP id g22mr16790779edb.78.1643554007740; Sun, 30 Jan 2022 06:46:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643554007; cv=none; d=google.com; s=arc-20160816; b=arje3CVLxPvpA8uyGcjS6anWk4yZDwGHqvNUbbL8bZE/VyQPj7elTgwFO0HUrEfSIG hmNTE65OgsNEW9Ix/YKSfNPGdh/8GwFBftMBsCYNkpZedlXAypzn6iQzFtEdptXejs5J DNNQbJiZy1ixLe5EdGIaOMbVoVahTNDWvI4lb8dgfh0/DIsPkoVZ8/mO+gedRYN74Q49 WV3Q38pJr98G7Z9KeRgrtIx5YrhPWVJfLoWu2kouYQLrrJhOhAoZSKbLIG2ye/YERbrb 9G3DXgZqZN2lbclNc5wK9KeRev9w7twg1gOzCZaVKYTNgIw5nWC7Ty/oMd7+DqkJWv5A w8+g== 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=q0ZM8dhavDfLgJ8TPR+cK/itjGWxKGEaU7ne9c/+b7I=; b=NQfj0dW35PFi3X3taJtFzJipurWTuD7mAHEVquWKP5yfw6YuqpVGfE8uL7vC8j7mYt qw79vS12V9UR961lLr8ZfIC23hzbxqTJ+uzJLct/uUSVqYLUiezPMn5UgluKNZE5K1jY kbDmYqZGI0vg2mGkSd/rIBbVf98FKibr8iW4oj2rUb/Lk+f4fFylNFvTX8ZKdOpzQsGE nB0vSTh+ZYBBKdBLMWcOTnacRC2tR9D/4Qo7erCwCDtrC7gwg+AwVEkyBkXUPhrD3pdp xzlBZgOczj/Dua4PeJQOkG+XjRczHFP7JiduycHXArSZyxve2YTA/lXhyvvge6O1TrC0 RxWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="ikSc3G/o"; 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=pass (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 go16si6627251ejc.951.2022.01.30.06.46.22; Sun, 30 Jan 2022 06:46:47 -0800 (PST) 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; dkim=pass header.i=@intel.com header.s=Intel header.b="ikSc3G/o"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347299AbiA1I2Z (ORCPT + 99 others); Fri, 28 Jan 2022 03:28:25 -0500 Received: from mga01.intel.com ([192.55.52.88]:54811 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347282AbiA1I2V (ORCPT ); Fri, 28 Jan 2022 03:28:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643358501; x=1674894501; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dsVWmk+4uaBVS/PgrR6ol+oGdqxEBzkJwnQwzMlxr3c=; b=ikSc3G/oxcCwCpiaX7EqgZg0OU0W6rceExYNPZBbMf9TuOHWAn9Y99mf R4oUdbOS+mdUZfn3joIUILFC3BdBFlcwa/uwA9hkItUkY6N6j0ip0C6Q1 mklScWvdYnpdGqla6rL6fiErNWH+39ZQgUnQqhiiUYJwdTlYaGePUuGAd x850o3p35w2OUO4065CnDbE+vw379ZFoSvwE3mAwtyPudq4zj+1VA2tHE SnONCoa9GVzR2qS3wJE00rkdPkGwMMQ/ay4hjs+pMOggH40ahaj/I5BqX Io8ozlHOixNJ4hfMJ12htHwQ6meWCW7aaY0bYqJoOJicuFWzvB0xn40Dq A==; X-IronPort-AV: E=McAfee;i="6200,9189,10240"; a="271537219" X-IronPort-AV: E=Sophos;i="5.88,323,1635231600"; d="scan'208";a="271537219" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2022 00:28:21 -0800 X-IronPort-AV: E=Sophos;i="5.88,323,1635231600"; d="scan'208";a="697019677" Received: from yhuang6-desk2.sh.intel.com ([10.239.13.11]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2022 00:28:17 -0800 From: Huang Ying To: Peter Zijlstra , Mel Gorman Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Feng Tang , Huang Ying , Dave Hansen , Baolin Wang , Andrew Morton , Michal Hocko , Rik van Riel , Mel Gorman , Yang Shi , Zi Yan , Wei Xu , osalvador , Shakeel Butt , zhongjiang-ali Subject: [PATCH -V11 3/3] memory tiering: skip to scan fast memory Date: Fri, 28 Jan 2022 16:27:51 +0800 Message-Id: <20220128082751.593478-4-ying.huang@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220128082751.593478-1-ying.huang@intel.com> References: <20220128082751.593478-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 Tested-by: Baolin Wang Reviewed-by: Baolin Wang 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: 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