From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3683361DA3 for ; Tue, 10 Mar 2026 08:10:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773130232; cv=none; b=dee90zmJqmyeIL4XbrDieK+i0n8s9P4CZcbJ/uRs6+KaGaXqJ5pn2GF/VcKHLOYneac0i3X18NmXamTzJ32ucn2JKMrwrtwlEmToNR6SSiSW3ehyLSZdIR76MtO/aU0k0hNroMurCDUnYFobW1hSjP7Rxj85b8yRN5VyWAh9A6s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773130232; c=relaxed/simple; bh=u08KMBTx5tv08lCkpWxnrhuJz/6gwcsx9mpAQVrzOWY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mUyuhB313EGbzta81WeY6DCOTZqbLByVXT14rOPPv+xX2dXYU4cpmQIz3J57GCwSriPcUqlfpBk24pMBJqCMoJbn2lVmq9G0MHinpEdzsR3cMUzqW7gc+qutDyHDX6V8xB0nz9Sb2kfcHjfG1cnXCiEN23CJ9ja0PWY10rR01iw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=etPBCatw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="etPBCatw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59300C19423; Tue, 10 Mar 2026 08:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773130232; bh=u08KMBTx5tv08lCkpWxnrhuJz/6gwcsx9mpAQVrzOWY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=etPBCatwxDtpg6nAJGISl9a9A4kQKbPEFHduEraDOnh3urqN+nHcBg5s5QSiS30V3 eFMKi7Pt3NamhZriFd1psR+5ZJW41b2tcaol0RuF3Vn+5KKjpJrb6D21RJ44vO9LWa ysQsmdGZpsjBYYktkXCFM21VEPcMVLaaQU3YVoZ+W1C/rP0YZjt2jKa64LJ1l4A/7Y Da1imeFP7JWqYhYcjc56AWo+ntasG6Flr78aBmLdZDVfc36yx4Orrt6oSZWlLg2AI4 y2XuZ0GAo0Z7f9LN4GSJ3Zersidb0gOMCTRcfp9UFkomL74wskO+hOys4VQIMCYMyu lP3jrDuXc0fEQ== Date: Tue, 10 Mar 2026 08:10:22 +0000 From: "Lorenzo Stoakes (Oracle)" To: Dev Jain Cc: akpm@linux-foundation.org, axelrasmussen@google.com, yuanchu@google.com, david@kernel.org, hughd@google.com, chrisl@kernel.org, kasong@tencent.com, weixugc@google.com, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, riel@surriel.com, harry.yoo@oracle.com, jannh@google.com, pfalcato@suse.de, baolin.wang@linux.alibaba.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, bhe@redhat.com, baohua@kernel.org, youngjun.park@lge.com, ziy@nvidia.com, kas@kernel.org, willy@infradead.org, yuzhao@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, anshuman.khandual@arm.com Subject: Re: [PATCH 2/9] mm/rmap: initialize nr_pages to 1 at loop start in try_to_unmap_one Message-ID: <92b8f168-b135-4c2b-a0be-36c8f8079684@lucifer.local> References: <20260310073013.4069309-1-dev.jain@arm.com> <20260310073013.4069309-3-dev.jain@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260310073013.4069309-3-dev.jain@arm.com> On Tue, Mar 10, 2026 at 01:00:06PM +0530, Dev Jain wrote: > Initialize nr_pages to 1 at the start of the loop, similar to what is being > done in folio_referenced_one(). It may happen that the nr_pages computed > from a previous call to folio_unmap_pte_batch gets reused without again > going through folio_unmap_pte_batch, messing up things. Although, I don't > think there is any bug right now; a bug would have been there, if in the > same instance of a call to try_to_unmap_one, we end up in the > pte_present(pteval) branch, then in the else branch doing pte_clear() for > device-exclusive ptes. This means that a lazyfree folio has some present > entries and some device entries mapping it. Since a pte being > device-exclusive means that a GUP reference on the underlying folio is > held, the lazyfree unmapping path upon witnessing this will abort > try_to_unmap_one. Dude, paragraphs. PARAGRAPHS :) this is one dense set of words. It's also a very compressed 'stream of consciousness' hard-to-read block here. I'm not sure it's really worth having this as a separate commit either, it's pretty trivial. > > Signed-off-by: Dev Jain > --- > mm/rmap.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/mm/rmap.c b/mm/rmap.c > index 087c9f5b884fe..1fa020edd954a 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1982,7 +1982,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, > unsigned long end_addr; > unsigned long pfn; > unsigned long hsz = 0; > - long nr_pages = 1; > + long nr_pages; > int ptes = 0; > > /* > @@ -2019,6 +2019,8 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, > mmu_notifier_invalidate_range_start(&range); > > while (page_vma_mapped_walk(&pvmw)) { > + nr_pages = 1; > + This seems valid but I really hate how we default-set it then in some branch set it to something else. But I think fixing that would be part of a bigger cleanup... > /* > * If the folio is in an mlock()d vma, we must not swap it out. > */ > -- > 2.34.1 >