From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 136DF3ACF0D for ; Tue, 10 Mar 2026 08:31:56 +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=1773131519; cv=none; b=nr5bCNC7ZYz4HD0ew51qmo8b/dxUpjqVcxMDPFVPB3toj45x5IexexKOqF5Lwn/+mknvYVu6DC8a++TWQPmdVEHdlDLuOjwD3bOOb2PEY80N0LeXKDFwX6I3B+KyH29hL2fADDVHUd9/RJVSUPtlh0fEc7vLGh43uB/yL+ATWII= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773131519; c=relaxed/simple; bh=Go4YQ70RooQCvYTCoGgJDrAqmD2J7GEgNxGMjf+gh3A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kdcJDMTfoU2OyZT8+Lauzotpq59mHrcf/ZvTovVg/mRU98IOnClPw/gBcVKBbCxGTdhqz1X2JYKNv87QKvNoIjbVRhD9huMmAad6XcqKTlAfObZ0gHn+0An7Rc7XjWdFfbLExJBxOZpurqCyx5Lp9wkMPaLWb/W9YgLOFdSWvyQ= 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 DC948169C; Tue, 10 Mar 2026 01:31:49 -0700 (PDT) Received: from [10.164.19.59] (unknown [10.164.19.59]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4E5263F7BD; Tue, 10 Mar 2026 01:31:47 -0700 (PDT) Message-ID: <58b3878a-24fe-4ed1-a870-604b44da71f7@arm.com> Date: Tue, 10 Mar 2026 14:01:44 +0530 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 2/9] mm/rmap: initialize nr_pages to 1 at loop start in try_to_unmap_one To: "Lorenzo Stoakes (Oracle)" 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 References: <20260310073013.4069309-1-dev.jain@arm.com> <20260310073013.4069309-3-dev.jain@arm.com> <92b8f168-b135-4c2b-a0be-36c8f8079684@lucifer.local> Content-Language: en-US From: Dev Jain In-Reply-To: <92b8f168-b135-4c2b-a0be-36c8f8079684@lucifer.local> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 10/03/26 1:40 pm, Lorenzo Stoakes (Oracle) wrote: > 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. Sure :) I'll try to break this down. > > I'm not sure it's really worth having this as a separate commit either, it's > pretty trivial. Hmm...well, as I explain above, it's not trivial for me :) it is difficult for me to reason here whether nr_pages can be reused without a reset in a future iteration. > >> >> 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 >>