Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2330172rdb; Mon, 12 Feb 2024 00:37:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBAT5SzaluUufSTkVWszBBQhXr0prEWKIj/+qlpAXMM1SNDomlDcQQzZgh0PJD74Uiixk8 X-Received: by 2002:a05:620a:460c:b0:785:d39e:adc7 with SMTP id br12-20020a05620a460c00b00785d39eadc7mr4121731qkb.66.1707727069091; Mon, 12 Feb 2024 00:37:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707727069; cv=pass; d=google.com; s=arc-20160816; b=wNIQG7wokNnteVfon8sB0CRar0kP/X8akq8uO0eA+eLd+5NEgoeb/ePRVUcm51JX87 YWsvVq3y2P7F8eSozDlA41ubdrI/CYkank+gZ/AJA3dhIfD5r7kXI3IE/nCcIZhhtxJr FmBsrVOn2LEX4m3viQ/fLbJ3j3VpHPY1LQKfAdBZYmkTfWkXbUJcNAVaqN/NRTKGOafh 5hH00i4CmHLtl520WDFkfwAmxMXMGEgU2NA/ryVwAQtC6T93+fl3GKa0qAB7iOCbLzyH DKJFGl/5HZytw+ebxeXevrXj0WnmMlprM64SRpxG2TbP+hvQx2q+NaxlGwFMiD+HpzFE FjcA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=WZbo6DkxozIBrYfyEfieDKnWm3+ElUe0ZnyDKdiEH4s=; fh=mragsyouEyeuwyqCji1iHHi4SeQGkw/87nqospwlFNM=; b=irxYvz2aY6FPwH+AosDuSMqJlMpntrrDywgvws0XmvnfREd6i9BhGstIRpgYf2bAdP VoytisfNc0ZrZGCIyqr7/NZvPb0ZPEO2PvP29tylCforxzDtqupWZt6NryAhH3ayYYCZ cmizIC49ClR7P14Vh6xv+y3GKbWQ03Xv1Fh3eTWtVmvuzW9Tjad+ThPA0bvL7WE2mFAp Ep16hY9A7ltyokIffzzoUQcbReZACWOtsBHqTL/6GifXLnduenv8t4LhdkVOMaEIHY8o 5M2k/zBy6u6c2a/4seZAjMZwNH732M+1pmF7yuGp4Mwy3SHptO52dlGcrSiI6WFrQHyJ Tc2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-61212-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61212-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVwpHuSztUaDtRs7I9TR6HoQJG5uXK7bZPZXX8krjzNXVpwyXZcWHfz40XGrFM+tEIXEqasyCFkFg6IRNkWk+lT0bTVqKhBZK3BLd+NcQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v25-20020a05620a091900b00785d54bfd50si1998688qkv.150.2024.02.12.00.37.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 00:37:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61212-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-61212-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61212-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C7E8B1C20937 for ; Mon, 12 Feb 2024 08:37:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9CEC6F9D1; Mon, 12 Feb 2024 08:37:39 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F14333F7; Mon, 12 Feb 2024 08:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707727059; cv=none; b=R5MIpdzvld6WrTjKyjruProFH53DkZU+cxglg2haTuvk0XriZpkXvS7Hgl8ccSXGntOJyHmAlkNIDqzE2NCMw+0k/Q6UqczvJ2VZEQCX3r+FuaJp2CDDfbJFYXfuOuitHIuE+n82qtD1wyS8HYAeDRolZwR11Gs9w4FtPDPum0g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707727059; c=relaxed/simple; bh=Gb03w9GjFy0RW+c0j9zZ7K/5lxbYES/OXeUcepSVlp4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nfY1AYBrxRdhSGeqpNRU+wQ/RKmNnq//ujlsLNJDvC1+7Aic38cdTWj/wX28P8o25ju0Sy1+CdT6kCEhVZie0GyJH6Lmy6PkH2qA/pw8MuX6vvnwoctyOCYPI4hP73SfkX0bi0VmLO06OyEelh/MQPefnq2G4qaOD53eLe7mTu8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 5C332DA7; Mon, 12 Feb 2024 00:38:17 -0800 (PST) Received: from [10.57.78.115] (unknown [10.57.78.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BB68C3F762; Mon, 12 Feb 2024 00:37:32 -0800 (PST) Message-ID: Date: Mon, 12 Feb 2024 08:37:31 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 01/10] mm/memory: factor out zapping of present pte into zap_present_pte() Content-Language: en-GB To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Catalin Marinas , Yin Fengwei , Michal Hocko , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Michael Ellerman , Christophe Leroy , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org References: <20240209221509.585251-1-david@redhat.com> <20240209221509.585251-2-david@redhat.com> From: Ryan Roberts In-Reply-To: <20240209221509.585251-2-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 09/02/2024 22:15, David Hildenbrand wrote: > Let's prepare for further changes by factoring out processing of present > PTEs. > > Signed-off-by: David Hildenbrand Reviewed-by: Ryan Roberts > --- > mm/memory.c | 94 ++++++++++++++++++++++++++++++----------------------- > 1 file changed, 53 insertions(+), 41 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 7c3ca41a7610..5b0dc33133a6 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -1532,13 +1532,61 @@ zap_install_uffd_wp_if_needed(struct vm_area_struct *vma, > pte_install_uffd_wp_if_needed(vma, addr, pte, pteval); > } > > +static inline void zap_present_pte(struct mmu_gather *tlb, > + struct vm_area_struct *vma, pte_t *pte, pte_t ptent, > + unsigned long addr, struct zap_details *details, > + int *rss, bool *force_flush, bool *force_break) > +{ > + struct mm_struct *mm = tlb->mm; > + struct folio *folio = NULL; > + bool delay_rmap = false; > + struct page *page; > + > + page = vm_normal_page(vma, addr, ptent); > + if (page) > + folio = page_folio(page); > + > + if (unlikely(!should_zap_folio(details, folio))) > + return; > + ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); > + arch_check_zapped_pte(vma, ptent); > + tlb_remove_tlb_entry(tlb, pte, addr); > + zap_install_uffd_wp_if_needed(vma, addr, pte, details, ptent); > + if (unlikely(!page)) { > + ksm_might_unmap_zero_page(mm, ptent); > + return; > + } > + > + if (!folio_test_anon(folio)) { > + if (pte_dirty(ptent)) { > + folio_mark_dirty(folio); > + if (tlb_delay_rmap(tlb)) { > + delay_rmap = true; > + *force_flush = true; > + } > + } > + if (pte_young(ptent) && likely(vma_has_recency(vma))) > + folio_mark_accessed(folio); > + } > + rss[mm_counter(folio)]--; > + if (!delay_rmap) { > + folio_remove_rmap_pte(folio, page, vma); > + if (unlikely(page_mapcount(page) < 0)) > + print_bad_pte(vma, addr, ptent, page); > + } > + if (unlikely(__tlb_remove_page(tlb, page, delay_rmap))) { > + *force_flush = true; > + *force_break = true; > + } > +} > + > static unsigned long zap_pte_range(struct mmu_gather *tlb, > struct vm_area_struct *vma, pmd_t *pmd, > unsigned long addr, unsigned long end, > struct zap_details *details) > { > + bool force_flush = false, force_break = false; > struct mm_struct *mm = tlb->mm; > - int force_flush = 0; > int rss[NR_MM_COUNTERS]; > spinlock_t *ptl; > pte_t *start_pte; > @@ -1555,7 +1603,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, > arch_enter_lazy_mmu_mode(); > do { > pte_t ptent = ptep_get(pte); > - struct folio *folio = NULL; > + struct folio *folio; > struct page *page; > > if (pte_none(ptent)) > @@ -1565,45 +1613,9 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, > break; > > if (pte_present(ptent)) { > - unsigned int delay_rmap; > - > - page = vm_normal_page(vma, addr, ptent); > - if (page) > - folio = page_folio(page); > - > - if (unlikely(!should_zap_folio(details, folio))) > - continue; > - ptent = ptep_get_and_clear_full(mm, addr, pte, > - tlb->fullmm); > - arch_check_zapped_pte(vma, ptent); > - tlb_remove_tlb_entry(tlb, pte, addr); > - zap_install_uffd_wp_if_needed(vma, addr, pte, details, > - ptent); > - if (unlikely(!page)) { > - ksm_might_unmap_zero_page(mm, ptent); > - continue; > - } > - > - delay_rmap = 0; > - if (!folio_test_anon(folio)) { > - if (pte_dirty(ptent)) { > - folio_mark_dirty(folio); > - if (tlb_delay_rmap(tlb)) { > - delay_rmap = 1; > - force_flush = 1; > - } > - } > - if (pte_young(ptent) && likely(vma_has_recency(vma))) > - folio_mark_accessed(folio); > - } > - rss[mm_counter(folio)]--; > - if (!delay_rmap) { > - folio_remove_rmap_pte(folio, page, vma); > - if (unlikely(page_mapcount(page) < 0)) > - print_bad_pte(vma, addr, ptent, page); > - } > - if (unlikely(__tlb_remove_page(tlb, page, delay_rmap))) { > - force_flush = 1; > + zap_present_pte(tlb, vma, pte, ptent, addr, details, > + rss, &force_flush, &force_break); > + if (unlikely(force_break)) { > addr += PAGE_SIZE; > break; > }