From patchwork Tue Mar 15 09:23:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: bibo mao X-Patchwork-Id: 12781219 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 9F420C433F5 for ; Tue, 15 Mar 2022 09:23:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 152F58D0002; Tue, 15 Mar 2022 05:23:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1031A8D0001; Tue, 15 Mar 2022 05:23:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F336D8D0002; Tue, 15 Mar 2022 05:23:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id E018B8D0001 for ; Tue, 15 Mar 2022 05:23:29 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8BD9818206D4C for ; Tue, 15 Mar 2022 09:23:29 +0000 (UTC) X-FDA: 79246082538.20.02DA7DA Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by imf18.hostedemail.com (Postfix) with ESMTP id D96CD1C000A for ; Tue, 15 Mar 2022 09:23:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.2.5.185]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9BxAM8LWzBiLrAJAA--.30383S2; Tue, 15 Mar 2022 17:23:24 +0800 (CST) From: Bibo Mao To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: add access/dirty bit on numa page fault Date: Tue, 15 Mar 2022 05:23:23 -0400 Message-Id: <20220315092323.620610-1-maobibo@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf9BxAM8LWzBiLrAJAA--.30383S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ur47tr13AF4DJFW3Ww45KFg_yoW8ArWUpF 93C3yjganrXrn7Aa13GFn0yr15Xa48Ka48Ar9xtw1qqws8Wrn7uayUW3yS9aykGry8tw4D Jr4UWFW8CF48Xw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D96CD1C000A X-Stat-Signature: o3qy5kocj66wa5ioa171ze3ju9mqsz8x X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn X-HE-Tag: 1647336207-267656 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);