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 40604184 for ; Mon, 23 Mar 2026 10:42:51 +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=1774262572; cv=none; b=pzZVpQb41PvqqxG+SCfqolXzSeeFTFEV6aJ4un5uIYjw1AaGR9VF5kXWuH7tvnGAP9aJJp7ZUs1wSlLlV8P0NnRd53qGzaPTC3B4bjZPR7Bcvrpzb//C2Ierci9L6puUs7wTMaKyM/n+XmjttuSLkj5kPUVyO5+BhuXkC/Dj7sk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774262572; c=relaxed/simple; bh=kxiLoYmlf4q3ke2uGxZ7iSgE18S0jNgx4Yf9uf826Gs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Utv1K0ut0UeXuKpW+a5175RwHk4wQB7MpSfDbOXocgUwKT3n4TZuvzVwnkLwvm52vJDF6nXrCiOM/OVddzD7ey4dZyhUoKqD27ikj/hH272Cl1/FNCZ3e0ta3bqRWbYksdesdeHphBjXluc4jzMIhynbgVIo78+tUAUmUGlJJPQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JAN43XMC; 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="JAN43XMC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B536C2BC87; Mon, 23 Mar 2026 10:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774262571; bh=kxiLoYmlf4q3ke2uGxZ7iSgE18S0jNgx4Yf9uf826Gs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JAN43XMCFGd9Ew29jBoMUxset0rjSufmFyTX8A97NfjSPz9m6uH6ufeayplDx2FJl 8SnErMDsP4gx7h2lP7GTzcezJd3SK6vyIrI82J4Bubbf1qXi+ZGSr7WUAENmuWv9OL Fd5oGcdVoMxSvNh0H03OVve7Me51FK2unI72h4N+Ynvl4SqmxAN6Ob+e4mv82A3hxc 22WYsRXX6fNzsKXJ9CldUwU9KqflMPDnKd1LcZy+2ynCEAFjeJPdshC0IU8q83PivN L/wgbmi+UWQqxi3DnnxllYN2Dq4ocspCN4jxeJfyH21mMGkMvjrHX6Z3rtbP4l7JGu 4UNpN/S+HRVdg== Date: Mon, 23 Mar 2026 10:42:49 +0000 From: "Lorenzo Stoakes (Oracle)" To: Baolin Wang Cc: Andrew Morton , David Hildenbrand , Zi Yan , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kiryl Shutsemau , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 10/13] mm/huge_memory: separate out the folio part of zap_huge_pmd() Message-ID: <2f8decdb-4ff7-4482-b50d-6718f25df8f9@lucifer.local> References: <6c4db67952f5529da4db102a6149b9050b5dda4e.1774029655.git.ljs@kernel.org> 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: On Sat, Mar 21, 2026 at 01:59:34PM +0800, Baolin Wang wrote: > > > On 3/21/26 2:07 AM, Lorenzo Stoakes (Oracle) wrote: > > Place the part of the logic that manipulates counters and possibly updates > > the accessed bit of the folio into its own function to make zap_huge_pmd() > > more readable. > > > > Also rename flush_needed to is_present as we only require a flush for > > present entries. > > > > Additionally add comments as to why we're doing what we're doing with > > respect to softleaf entries. > > > > This also lays the ground for further refactoring. > > > > Signed-off-by: Lorenzo Stoakes (Oracle) > > --- > > mm/huge_memory.c | 61 +++++++++++++++++++++++++++--------------------- > > 1 file changed, 35 insertions(+), 26 deletions(-) > > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index 673d0c4734ad..9ddf38d68406 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -2325,6 +2325,37 @@ static inline void zap_deposited_table(struct mm_struct *mm, pmd_t *pmd) > > mm_dec_nr_ptes(mm); > > } > > +static void zap_huge_pmd_folio(struct mm_struct *mm, struct vm_area_struct *vma, > > + pmd_t pmdval, struct folio *folio, bool is_present, > > + bool *has_deposit) > > +{ > > + const bool is_device_private = folio_is_device_private(folio); > > + > > + /* Present and device private folios are rmappable. */ > > + if (is_present || is_device_private) > > + folio_remove_rmap_pmd(folio, &folio->page, vma); > > + > > + if (folio_test_anon(folio)) { > > + *has_deposit = true; > > + add_mm_counter(mm, MM_ANONPAGES, -HPAGE_PMD_NR); > > + } else { > > + add_mm_counter(mm, mm_counter_file(folio), > > + -HPAGE_PMD_NR); > > + > > + /* > > + * Use flush_needed to indicate whether the PMD entry > > + * is present, instead of checking pmd_present() again. > > + */ > > + if (is_present && pmd_young(pmdval) && > > + likely(vma_has_recency(vma))) > > + folio_mark_accessed(folio); > > Nit: these comments were added by me to explain why 'flush_needed' was > used:). Since it has been renamed to the more readable 'is_present', these > comments are now redundant and can be removed. Ack, I think it's _probably_ ok to leave that as a later commit removes it anyway, if that works for you? > > With that, > Reviewed-by: Baolin Wang Thanks! Cheers, Lorenzo