From patchwork Wed Mar 16 01:08:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: bibo mao X-Patchwork-Id: 12782021 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 9AF06C433FE for ; Wed, 16 Mar 2022 01:08:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F29428D0002; Tue, 15 Mar 2022 21:08:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED81D8D0001; Tue, 15 Mar 2022 21:08:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC6EB8D0002; Tue, 15 Mar 2022 21:08:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id CEA2C8D0001 for ; Tue, 15 Mar 2022 21:08:44 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9581660F01 for ; Wed, 16 Mar 2022 01:08:44 +0000 (UTC) X-FDA: 79248464568.14.DA31B87 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by imf05.hostedemail.com (Postfix) with ESMTP id D438A100019 for ; Wed, 16 Mar 2022 01:08:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.2.5.185]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxTxOVODFi5PQJAA--.6644S2; Wed, 16 Mar 2022 09:08:37 +0800 (CST) From: Bibo Mao To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: add access/dirty bit on numa page fault Date: Tue, 15 Mar 2022 21:08:36 -0400 Message-Id: <20220316010836.1137084-1-maobibo@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf9DxTxOVODFi5PQJAA--.6644S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ur47tr13AF4DJFW3Ww45KFg_yoW8ArWUpF 93C3yjganrXrn7Aa13GFn0yr15Xa48Ka48Ar9xtw1qqws8Wrn7uayUW3yS9aykGry8tw4D Jr4UWFW8CF48Xw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Rspamd-Queue-Id: D438A100019 X-Stat-Signature: koh6kcqqb1db1z3jmzazojrnobs56myj X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn X-Rspamd-Server: rspam02 X-HE-Tag: 1647392921-510220 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: During numa page fault, dirty bit can be added for old pte if fail to migrate on write fault. And if it succeeds to migrate, access bit can be added for migrated new pte, also dirty bit can be added for write fault. Signed-off-by: Bibo Mao --- mm/memory.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index c125c4969913..65813bec9c06 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4404,6 +4404,22 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) if (migrate_misplaced_page(page, vma, target_nid)) { page_nid = target_nid; flags |= TNF_MIGRATED; + + /* + * update pte entry with access bit, and dirty bit for + * write fault + */ + spin_lock(vmf->ptl); + pte = *vmf->pte; + pte = pte_mkyoung(pte); + if (was_writable) { + pte = pte_mkwrite(pte); + if (vmf->flags & FAULT_FLAG_WRITE) + pte = pte_mkdirty(pte); + } + set_pte_at(vma->vm_mm, vmf->address, vmf->pte, pte); + update_mmu_cache(vma, vmf->address, vmf->pte); + pte_unmap_unlock(vmf->pte, vmf->ptl); } else { flags |= TNF_MIGRATE_FAIL; vmf->pte = pte_offset_map(vmf->pmd, vmf->address); @@ -4427,8 +4443,11 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) 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 (was_writable) + if (was_writable) { pte = pte_mkwrite(pte); + if (vmf->flags & FAULT_FLAG_WRITE) + pte = pte_mkdirty(pte); + } ptep_modify_prot_commit(vma, vmf->address, vmf->pte, old_pte, pte); update_mmu_cache(vma, vmf->address, vmf->pte); pte_unmap_unlock(vmf->pte, vmf->ptl);