Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp433017rdb; Tue, 23 Jan 2024 04:25:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMLGz4e66OfuueZpYoOojAS0AvMqkw7pBAugAcJyTBijMz0wIhJRUiiTpCSDjRPqcNZ495 X-Received: by 2002:a17:902:be12:b0:1d5:f59f:e6bb with SMTP id r18-20020a170902be1200b001d5f59fe6bbmr3402669pls.79.1706012722623; Tue, 23 Jan 2024 04:25:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706012722; cv=pass; d=google.com; s=arc-20160816; b=Mn6VCxwVf0eU8xT1EjR68nyV8JYGWJ3ePKx3D2DCxoS9FYYxSD4UCQSa+rDRZGXXaR DLKeZfWtUEkbuDrGK4RJXerR//xzc0cJ7H+JgIooc4TxntPm+BB1Q/M+r8IbmX1Q6E9R HixAX1o6fwA1ONPESsirtezlFRgFO4Q4vOx26L+TiIIKzwZJ4YRquHhwiW5MpWSU5hO/ 1ppQkrU6eXXr6BVGYxbNv/ZhtXb08IOgW8/lvuruGz77TRQsLIQ5cBqv/TJeoMlwfj9X d7tacrUinHr3gK0zJoJz+PfpDhFRAbIVJexTfPCk7O7rd6hqlWrqZXepsp+2PgwPhHkO 4b9Q== 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=DH+wKZQhvSsC3o94lfZ7+LDJv42WMu5N2QuCCegNsdI=; fh=cLjkAanmB8aobrGIK/HTftjty0FQAaQ+aRvIv8PHcYU=; b=ShPsbzzPF/27v49PbDNcYij/SUgyaHC7f+IEqTd4gCADSHijNCGaoVCXCLtwTbhDuM vvgbi5a/OHU8fDpj2MXJ0swhDJu45X4LfCuPTlKtpqqLaPLh7AgmooNsxRvjSTi48Rlo IwdVqwF1GK2kxG2LKLFJpKb/MxExkSY474v/XeA02Vr/l4dMu1z4RmMbkpaeu0dspm8K xSFiqsbyRe7MdSikfSfSOzYue5CP3OqUGu+eWCw2ixTYFlEZQ0gbC4Kv9RUeZ+KoibP4 61UTHTwHAJN3+0aSIYKgiYPTB165yd9oaap972Q46ZefZvMafDBFuM2jAYPhYEimX94g XXgg== 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-35245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p7-20020a170902b08700b001d733d03e6esi5260537plr.648.2024.01.23.04.25.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 04:25:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-35245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35245-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 46BCC288749 for ; Tue, 23 Jan 2024 12:25:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6AE75DF33; Tue, 23 Jan 2024 12:25:14 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5D4F5DF2D; Tue, 23 Jan 2024 12:25:11 +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=1706012714; cv=none; b=c/EqlYFPO55eLPYoq5Mot0m/uTa4XS2a2qk/1o99YZ4kPCZP1296RmsS3Kq/ZozekIQ4F6SwaVsx9fiomtgsBicRy++2/jVVtoOKbk+5PaI5ZjiG3K1IpA2DY7D95NNv4Z0BU61lgd1VssvNSDejRFrztJGhSJXU91OfPn7+eX8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706012714; c=relaxed/simple; bh=gDuBiOjwlxA//+QgJwW0i0xvy0XhKfsDkSnLAVR8E8A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=fOVxxfPLCEnDqfiYJj+1PbC3xDQGgFyEg+BI9zCU6RwBkiVmnFuYNaZZ5j2wIa7uWoOdlATtPSCPY4eedHC19o8FUkocbzAI+D1AGROaEEzz6rw/0OjN0JIDSY+yg/3UL+45iNsMWGD0DIdAMYs6KY532tWQnObAosiJ7jfVBcA= 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 69D231FB; Tue, 23 Jan 2024 04:25:56 -0800 (PST) Received: from [10.57.77.165] (unknown [10.57.77.165]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C6A213F762; Tue, 23 Jan 2024 04:25:05 -0800 (PST) Message-ID: <59592b50-fe89-4b32-8490-2e6c296f972f@arm.com> Date: Tue, 23 Jan 2024 12:25:04 +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 v1 10/11] mm/memory: ignore dirty/accessed/soft-dirty bits in folio_pte_batch() Content-Language: en-GB To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Russell King , Catalin Marinas , Will Deacon , Dinh Nguyen , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org References: <20240122194200.381241-1-david@redhat.com> <20240122194200.381241-11-david@redhat.com> From: Ryan Roberts In-Reply-To: <20240122194200.381241-11-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 22/01/2024 19:41, David Hildenbrand wrote: > Let's ignore these bits: they are irrelevant for fork, and will likely > be irrelevant for upcoming users such as page unmapping. > > Signed-off-by: David Hildenbrand > --- > mm/memory.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index f563aec85b2a8..341b2be845b6e 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -953,24 +953,30 @@ static __always_inline void __copy_present_ptes(struct vm_area_struct *dst_vma, > set_ptes(dst_vma->vm_mm, addr, dst_pte, pte, nr); > } > > +static inline pte_t __pte_batch_clear_ignored(pte_t pte) > +{ > + return pte_clear_soft_dirty(pte_mkclean(pte_mkold(pte))); > +} > + > /* > * Detect a PTE batch: consecutive (present) PTEs that map consecutive > * pages of the same folio. > * > * All PTEs inside a PTE batch have the same PTE bits set, excluding the PFN. nit: last char should be a comma (,) not a full stop (.) > + * the accessed bit, dirty bit and soft-dirty bit. > */ > static inline int folio_pte_batch(struct folio *folio, unsigned long addr, > pte_t *start_ptep, pte_t pte, int max_nr) > { > unsigned long folio_end_pfn = folio_pfn(folio) + folio_nr_pages(folio); > const pte_t *end_ptep = start_ptep + max_nr; > - pte_t expected_pte = pte_next_pfn(pte); > + pte_t expected_pte = __pte_batch_clear_ignored(pte_next_pfn(pte)); > pte_t *ptep = start_ptep + 1; > > VM_WARN_ON_FOLIO(!pte_present(pte), folio); > > while (ptep != end_ptep) { > - pte = ptep_get(ptep); > + pte = __pte_batch_clear_ignored(ptep_get(ptep)); > > if (!pte_same(pte, expected_pte)) > break; I think you'll lose dirty information in the child for private mappings? If the first pte in a batch is clean, but a subsequent page is dirty, you will end up setting all the pages in the batch as clean in the child. Previous behavior would preserve dirty bit for private mappings. In my version (v3) that did arbitrary batching, I had some fun and games tracking dirty, write and uffd_wp: https://lore.kernel.org/linux-arm-kernel/20231204105440.61448-2-ryan.roberts@arm.com/ Also, I think you will currently either set soft dirty on all or none of the pages in the batch, depending on the value of the first. I previously convinced myself that the state was unimportant so always cleared it in the child to provide consistency.