From patchwork Tue Mar 26 11:51:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13603988 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 1E84BCD11DD for ; Tue, 26 Mar 2024 11:51:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E1856B0087; Tue, 26 Mar 2024 07:51:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55EED6B008A; Tue, 26 Mar 2024 07:51:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 314B06B0087; Tue, 26 Mar 2024 07:51:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E4A086B0088 for ; Tue, 26 Mar 2024 07:51:43 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BD1DBC0AA9 for ; Tue, 26 Mar 2024 11:51:43 +0000 (UTC) X-FDA: 81939025686.19.AB9DF35 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by imf11.hostedemail.com (Postfix) with ESMTP id 21C884000C for ; Tue, 26 Mar 2024 11:51:40 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=QsKTLewt; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.119 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711453902; 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=AwEXLIJvfOIlKePIj3JTyBX7Gpl2aDHZTADkmkUue0Y=; b=NF47rxloFaH7SEORptnxewR+RvCj20T9QZ540VMOoV79wRv2QkwLNulEm0i31CMpGVDnlB dacinqP4g1QioEEpvPm5vPS8HB6Sv1fGN/4eQEgsHX3e2UctAKG8RClpn3y6cswc1TkTFn 18dxYHwpq3df0NiQlX6W5jf7ot733Sc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711453902; a=rsa-sha256; cv=none; b=gxhe12D+eMJlvXAOvfa69fCwDNBWC5ZbH/oHrfg+7jWwcHzqYIJp+G0M13I2havdsbjGaZ WbtO1JBnUF/6XN4lGoIsF/HHgVnLbM2CWKPa13EnN6F685hWqQ1DZsxnuIYInhL6VN2CKn 4hoOmFVuU4ef8BxBpGaUum+nF7Dlg/o= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=QsKTLewt; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.119 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1711453897; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=AwEXLIJvfOIlKePIj3JTyBX7Gpl2aDHZTADkmkUue0Y=; b=QsKTLewt7yKU+OYDzWcgEmrYwIixcDmWJ+MM+/SH7nddUnOPZDvTr6b8PVyVBtHfqF0rQ2vhEuo+YLEmNixcreQMgJl5WQJtedGOCgnyD7IP886LLyc4ueak2SACOLCAxd8j2sGqf+Pylx9VSL1Xz4eXFWUHKP41IIwuR8EzL+c= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0W3LK4ka_1711453896; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W3LK4ka_1711453896) by smtp.aliyun-inc.com; Tue, 26 Mar 2024 19:51:36 +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 1/2] mm: factor out the numa mapping rebuilding into a new helper Date: Tue, 26 Mar 2024 19:51:24 +0800 Message-Id: <0c9df470bd2a62af8cc707cf01e42c7c744dd927.1711453317.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: 21C884000C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: fd4rz43bh8odnyqos7ttw4tut1xhoaab X-HE-Tag: 1711453900-574469 X-HE-Meta: U2FsdGVkX19FSO2nE7U+TJ2skBGgKGEtnla4ARwHb5DPFvGLEvq3bCnkTNvt+7p2TJJ2kidgwbx6N68j6naX3WWSGCXSSmuOEXsgsZFannPHVC+GROr5pN9lwRdscMFCXhASpqP5R9/7O+mk6+7CiIwqr/Q8z636dNGvbAyf2AYE1R/WfqztzvZK5El6hMIbWDgTdZ75CF1LeAYQ0yevaVXR3wnE9sEABm0Q/O2++whnlXMIWwqbvrVRLidyB9Snq4ClqDvjR92lGd12cuHkCSLTFkr5G6kM7JO1e2bUAPLE41vNK7qJPB5xaDi0CCUqRAtybA1YZfmZs8X8xlK2OyX+iyCuRB3Ot+oWKNlo/VPVgUnh38hHzhJ/RZXr3bd0d/gCUQrpMxkMHqilYoALJUaskamEGFYtPllKegcJFylOExVyly9P1WlqUfv9sFCir1PobdEG2nphwesqRS18GjQ0fpZmUlKBQ/oaOoiSn+8iHgHk104w/Bsvw0JoXCv/tKVOvmNrsMoRAmKdYBYVbepjPvxQCVdXBHlNK8d/GzLTtk41FaIJq5ZxIu1hvDRHj0ms4eCDx8VRGM7Qu3ieTagZBu18vcj287WcKlMEwyQU7dhRcwhBBEC7/5Gs/iR2bsj8rGsFscT0G9nfYUdrGC9IRzqtsdJO/2gU8aocWbQc7lytR6r7Z1R8dixBfIVP5zXS9FQTBOxizauNZ9+5dnYURSmuyIxfd4eyF2qznFHXFPDK92IOzvjAQ6N8bN0iZJXH5KEvzPSK3jT/d0UNWPwbOkrRjlQk59Hf0ZkjUyPr8Hs3OrkLL9Lmft3h+FcL7/mgpj5OlizB7msr0TXW7RVDvaDw9zGSxIh2gnuAY2UA0tmCGjW0CrJ1iE4/1APOCAk68gYX4CgklmAI0a8OjH8EBZDcgIizUlRxH6GTIj5WqkdiUkMXExvcCRoA0h0YWtAJEf/M4hPN1zx1MDt DPtqugJa vsEVp8JpMTVrjdIUORSdvUUKJyMG4eLMdW6YLm7J4rT0QsU3WoP1XRQT/uP0OrcLg6uMWx+FWPJXFzUq5Kjt1aAHI2zVen8ny5PPY+EGQFIIMN1kthV4OLfXxKkJPuit7imrLMmLjsUiAAlk6zQKvpMhtcLWeXWhUsJiZeW+OQcFiSwPE/hm1dHBHwPXiN0ZLzBHoFH70QEI0jQ7IPXsjvh2o/dcLL5/jkAFhWKdLpIXVVwAO2oLhAuYBwpxX5GpxJ85rAWtPTQLM1WI= 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 --- 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; }