From patchwork Wed Apr 3 08:39:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13615377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90F4CCD1288 for ; Wed, 3 Apr 2024 08:39:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B833C6B00A1; Wed, 3 Apr 2024 04:39:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8D2A6B00A5; Wed, 3 Apr 2024 04:39:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A0076B00A6; Wed, 3 Apr 2024 04:39:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 574856B00A3 for ; Wed, 3 Apr 2024 04:39:27 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 03E4DA1224 for ; Wed, 3 Apr 2024 08:39:26 +0000 (UTC) X-FDA: 81967571574.30.CD72794 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf17.hostedemail.com (Postfix) with ESMTP id CF36B40009 for ; Wed, 3 Apr 2024 08:39:24 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=hUQVwZ6V; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712133565; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oLhTr2J/3wy/5GEpHjjzFAy9UR1eWN6w8XG4KoPFC1k=; b=Czh5h0cmCUnbdZ3k6Fs5DNHLftSGly0OmX7wR4rXKMd10MCufgY7mMpiXtYnQx/tZtNUMG fQvvY8wsc6M8ebsajiSoilaCLpWamvkJ0zPvesjWzicoR35BkEiBz+jwj8iNxWoZFjdf/x JTw+SAdi4U9WhsCqsrgjljD028QLVlQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=hUQVwZ6V; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712133565; a=rsa-sha256; cv=none; b=gjrGd5LcBxPmmanRNeJ5w3ASQ18Gjri88CrG6w+jmdjuysNEeDMYRqjDx9fns/YnqFIlC0 lY63NSSgxmqKENf/MfQ+4J1cKiyj2+VAdSLJOeWdj2wwWvKxqtSi/yYWArzLSi/c48D+bj 3LW9Ot1fIUxkIHWRbjGiT3BWY/52xoE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1712133561; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=oLhTr2J/3wy/5GEpHjjzFAy9UR1eWN6w8XG4KoPFC1k=; b=hUQVwZ6VvtJ26cr6CaZEKy4SZwLqiDE9GVTCLyfnFCsWctyuGXyv4pLMp2USlZSZW1kS7XHrZpx30Z9qUc92Ycl8oLec3eBJVILzYsSyTrOLiqA7wKnjReOXS626nsLB2mEqI4+PF3xa9G3OnVzW/ntmCRjNLYmb/EUAAFn2pSw= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0W3r8YaY_1712133559; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W3r8YaY_1712133559) by smtp.aliyun-inc.com; Wed, 03 Apr 2024 16:39:20 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: david@redhat.com, mgorman@techsingularity.net, wangkefeng.wang@huawei.com, jhubbard@nvidia.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] mm: factor out the numa mapping rebuilding into a new helper Date: Wed, 3 Apr 2024 16:39:09 +0800 Message-Id: <24736d92416099336a1d0738f0afb062a8127be4.1712132950.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: CF36B40009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 4zip8b96iy4a76igxfjqw1byf1rrex9c X-HE-Tag: 1712133564-948189 X-HE-Meta: U2FsdGVkX18ZOIcjYZWq+aAsZitURQVxhS2G6T5IRgxgbhbj+929gKGoMLjfwz601TDnzdrCUZxNCpoITdm4IqYZA+N/46T7IaFWsrKANYiwTHQuVAmXAUepkVWZmDIe7CX8ZOQ1w078OMGKzKgqDcE5vZnwDFb1H+f0bYTLjkgbpoleg1UVoTbnm34zAmHFAnV4zGCjdMHyBsr9uczpEX0WCIH6yBFNhV5poSN022qEdV4192ozloORY9qKTm8UvZcnGWVEWekS1GY/pqj0Slw87koy90+B169nj0BV8Pmj1LpVlQFpLA01Vs7vtAtHNGnDqId8Zxzl75EcD6W1R5ax5UrIFYVoOKKqQaBDo+OtC3cD0XnlyGcqVtlWoA1ouK8nQeAa+gMHxqBbUx/RDcSSRMZyFQis8GdvkmliPvFfCc+saaDiFsOfhFdIhnuIdcHPSsDTc4WbZhTTW0G/KIhvdIRPR5ZV0SpTCl4f8IjuBUeS/eLR6eht6woFeoiJ5s6XdpCuo7/sBFTxCP4Ll/G4FZZYFxujZcEIBBZQuG/RonNc6JaFwieV/gUo+jeAK/us30g25WsaTkyosi65fPIu/uNGCDA942+lm8lTt9tLzq+B6nDtZKR+ytAAVgnJ7mPlNzKULWQwvFw4h0tP5ZHOb9AHDszDEj8GBHMFD660XiuOKa1lyRdnyJJtAgRf1ZAco2W/Nrszjwxa5NWJ0PzFWjwdAy6hkK/6c8i+8EA1iXzZcFzvYTz+B3Z3ehyatHvspLuYgaEN5JYe2stm8Ph0I6n87iPX9TUyzv6WveSGvpCJPHudX7ySDPBQtTLQwaG2Was1CsDvlhHNkakESCqRoDPRFmc9cbWlxlUCGUphgXEb9IW5SNjPSeUKJjUm/paK6zLrOEC4c8OKSBibeKIHn3u/luwsX0gCD1C9thRPXuogMeVDEjSLWIxyMPYolHuLy9KFczyWEhLSal7 c+6fmJqg OmNCRgrGz25PPoli3NlTJGQ/at+G632G4xBw72octbqFVRefL/CG2OlYbVdmEDVujPLr7QHwsta0K18uH/GOVpmgNVOqGjMb2QkYIuRJ6+3mLU/UNFujiBKtDw63LGff8nvVpsi+5mR70Q60kuPuPAPKQ+OtZjuUMEzIN96AtgYYS0FHeWlkvOYkBxLJf80Bmsj6P6+gKDwiRHFfuMXL5+Riv/TlfFhOWbgod+R7+AwHsG2hoHEDPZwsRHmMU1LAI/3MoCTSJE6hTayA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: To support large folio's numa balancing, factor out the numa mapping rebuilding into a new helper as a preparation. Signed-off-by: Baolin Wang Reviewed-by: "Huang, Ying" --- mm/memory.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 62ee4a15092a..c30fb4b95e15 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5054,6 +5054,20 @@ int numa_migrate_prep(struct folio *folio, struct vm_fault *vmf, return mpol_misplaced(folio, vmf, addr); } +static void numa_rebuild_single_mapping(struct vm_fault *vmf, struct vm_area_struct *vma, + bool writable) +{ + pte_t pte, old_pte; + + old_pte = ptep_modify_prot_start(vma, vmf->address, vmf->pte); + pte = pte_modify(old_pte, vma->vm_page_prot); + pte = pte_mkyoung(pte); + if (writable) + pte = pte_mkwrite(pte, vma); + ptep_modify_prot_commit(vma, vmf->address, vmf->pte, old_pte, pte); + update_mmu_cache_range(vmf, vma, vmf->address, vmf->pte, 1); +} + static vm_fault_t do_numa_page(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; @@ -5159,13 +5173,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) * Make it present again, depending on how arch implements * non-accessible ptes, some can allow access by kernel mode. */ - old_pte = ptep_modify_prot_start(vma, vmf->address, vmf->pte); - pte = pte_modify(old_pte, vma->vm_page_prot); - pte = pte_mkyoung(pte); - if (writable) - pte = pte_mkwrite(pte, vma); - ptep_modify_prot_commit(vma, vmf->address, vmf->pte, old_pte, pte); - update_mmu_cache_range(vmf, vma, vmf->address, vmf->pte, 1); + numa_rebuild_single_mapping(vmf, vma, writable); pte_unmap_unlock(vmf->pte, vmf->ptl); goto out; }