From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3587C83F27 for ; Tue, 22 Jul 2025 11:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j7FmrljgJWMqEho9n3tScbu6030nDFWUZ/1cCus/DR0=; b=wiHUde1yUwbRUa0v9VpLlf29zi 14C9Xuy1w/S0L+DFYAO5N+7U54KutB1LhqZUiRnpKkg/WfnzctUKQRstkXrMSWeYM2Dgb4rBIgwaN lq3l9g54vs/xr/4ddR/WaVSfVFfgBQhgUQQSyLW0sJmO7qcG1eJulspXmcmIE8N3SMpU/ss9NyfK6 cLPuThIRPyvK60bOeSQHEWJrslTkdj426JaohlSWRCYOtkiTJky7GNkmgyEkk20WckyFpwKGeOre8 EH81ydrjTVnucxFxaLLxvs0yUFUfMAu0xoPK9yrglWLB0KwvpWeqrLN5kKePdSOR3t5Q1cP93uLnO 5kXJDrTg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1ueB9s-00000002Hbo-1hXJ; Tue, 22 Jul 2025 11:27:44 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1ueB7M-00000002H6Z-0gQa for linux-arm-kernel@lists.infradead.org; Tue, 22 Jul 2025 11:25:09 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EBEB8152B; Tue, 22 Jul 2025 04:24:58 -0700 (PDT) Received: from [10.1.30.167] (XHFQ2J9959.cambridge.arm.com [10.1.30.167]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5C27A3F66E; Tue, 22 Jul 2025 04:25:01 -0700 (PDT) Message-ID: Date: Tue, 22 Jul 2025 12:25:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 1/7] mm: Refactor MM_CP_PROT_NUMA skipping case into new function Content-Language: en-GB To: Dev Jain , akpm@linux-foundation.org Cc: david@redhat.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, anshuman.khandual@arm.com, peterx@redhat.com, joey.gouly@arm.com, ioworker0@gmail.com, baohua@kernel.org, kevin.brodsky@arm.com, quic_zhenhuah@quicinc.com, christophe.leroy@csgroup.eu, yangyicong@hisilicon.com, linux-arm-kernel@lists.infradead.org, hughd@google.com, yang@os.amperecomputing.com, ziy@nvidia.com References: <20250718090244.21092-1-dev.jain@arm.com> <20250718090244.21092-2-dev.jain@arm.com> From: Ryan Roberts In-Reply-To: <20250718090244.21092-2-dev.jain@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250722_042508_285003_3980E17A X-CRM114-Status: GOOD ( 20.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 18/07/2025 10:02, Dev Jain wrote: > Reduce indentation by refactoring the prot_numa case into a new function. > No functional change intended. > > Signed-off-by: Dev Jain > --- > mm/mprotect.c | 101 +++++++++++++++++++++++++++----------------------- > 1 file changed, 55 insertions(+), 46 deletions(-) > > diff --git a/mm/mprotect.c b/mm/mprotect.c > index 88709c01177b..2a9c73bd0778 100644 > --- a/mm/mprotect.c > +++ b/mm/mprotect.c > @@ -83,6 +83,59 @@ bool can_change_pte_writable(struct vm_area_struct *vma, unsigned long addr, > return pte_dirty(pte); > } > > +static bool prot_numa_skip(struct vm_area_struct *vma, unsigned long addr, > + pte_t oldpte, pte_t *pte, int target_node) > +{ > + struct folio *folio; > + bool toptier; > + int nid; > + > + /* Avoid TLB flush if possible */ > + if (pte_protnone(oldpte)) > + return true; > + > + folio = vm_normal_folio(vma, addr, oldpte); > + if (!folio) > + return true; > + > + if (folio_is_zone_device(folio) || folio_test_ksm(folio)) > + return true; > + > + /* Also skip shared copy-on-write pages */ > + if (is_cow_mapping(vma->vm_flags) && > + (folio_maybe_dma_pinned(folio) || folio_maybe_mapped_shared(folio))) > + return true; > + > + /* > + * While migration can move some dirty pages, > + * it cannot move them all from MIGRATE_ASYNC > + * context. > + */ > + if (folio_is_file_lru(folio) && folio_test_dirty(folio)) > + return true; > + > + /* > + * Don't mess with PTEs if page is already on the node > + * a single-threaded process is running on. > + */ > + nid = folio_nid(folio); > + if (target_node == nid) > + return true; > + > + toptier = node_is_toptier(nid); > + > + /* > + * Skip scanning top tier node if normal numa > + * balancing is disabled > + */ > + if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL) && toptier) > + return true; > + > + if (folio_use_access_time(folio)) > + folio_xchg_access_time(folio, jiffies_to_msecs(jiffies)); Perhaps this bit should be kept in the original location? It's got nothing to do with determining if the pte should be skipped. Thanks, Ryan > + return false; > +} > + > static long change_pte_range(struct mmu_gather *tlb, > struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr, > unsigned long end, pgprot_t newprot, unsigned long cp_flags) > @@ -117,53 +170,9 @@ static long change_pte_range(struct mmu_gather *tlb, > * pages. See similar comment in change_huge_pmd. > */ > if (prot_numa) { > - struct folio *folio; > - int nid; > - bool toptier; > - > - /* Avoid TLB flush if possible */ > - if (pte_protnone(oldpte)) > - continue; > - > - folio = vm_normal_folio(vma, addr, oldpte); > - if (!folio || folio_is_zone_device(folio) || > - folio_test_ksm(folio)) > - continue; > - > - /* Also skip shared copy-on-write pages */ > - if (is_cow_mapping(vma->vm_flags) && > - (folio_maybe_dma_pinned(folio) || > - folio_maybe_mapped_shared(folio))) > - continue; > - > - /* > - * While migration can move some dirty pages, > - * it cannot move them all from MIGRATE_ASYNC > - * context. > - */ > - if (folio_is_file_lru(folio) && > - folio_test_dirty(folio)) > - continue; > - > - /* > - * Don't mess with PTEs if page is already on the node > - * a single-threaded process is running on. > - */ > - nid = folio_nid(folio); > - if (target_node == nid) > - continue; > - toptier = node_is_toptier(nid); > - > - /* > - * Skip scanning top tier node if normal numa > - * balancing is disabled > - */ > - if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL) && > - toptier) > + if (prot_numa_skip(vma, addr, oldpte, pte, > + target_node)) > continue; > - if (folio_use_access_time(folio)) > - folio_xchg_access_time(folio, > - jiffies_to_msecs(jiffies)); > } > > oldpte = ptep_modify_prot_start(vma, addr, pte);