From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 735B133F8CA for ; Sat, 21 Mar 2026 05:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774072789; cv=none; b=pmGhx9T29aW+PcoXOhkgoNT61mPWIdeoOjJda2HaBI6afKP16C9C7aVMYJTzlYpaP4gyYKMTtjPM6gUjcxLph3aECDjQLqJSPhoNu7+l3V3vFQ1xmCBvKFyP4xB8hWGWbkXvhl3lwBwVUy9RqyVtTRl2UvyhQlZEbr2AGeLyRrE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774072789; c=relaxed/simple; bh=F6O2dUHBQZaWfakrSQGA46H4KHCW4vYHoKc01H+JPpo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bKUNOfCMOyJygua1uvzzSHGoedjDKIJ5jLRCW7CuRCITQGxrLybOXOXNTeOQevz6Ij2HeKqCVxiR3NDfHiYvusTGge3WBgPcmui62qrTG6ekiJeXyEwXpAVyddlvyPiiMnt5UMY1Ma1RVE3oTVP+15lHlWm1v0DDBOmgxsUgXPg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=q930L0tb; arc=none smtp.client-ip=115.124.30.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="q930L0tb" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1774072778; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=tB8N/EDzD0rrPaEsXZHYue0cF2DWaunMlW/oScwdeko=; b=q930L0tbB3Xptm0RGeAWVUcrSR593wS2dFymc2Ouo2FX6fAwwX3z3A4oYbRep+CqtoA3LdNFZc00wR78/IVy+dAwzWLWgZ4b8bA8O+6Z6koKlpgf4LqK64eZtP5HyyOe/a8ZYXYNn9pIRPvl4CtGPI3QKTKC09bI3enhwJPC0BA= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0X.O8CIH_1774072775; Received: from 30.42.98.36(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X.O8CIH_1774072775 cluster:ay36) by smtp.aliyun-inc.com; Sat, 21 Mar 2026 13:59:36 +0800 Message-ID: Date: Sat, 21 Mar 2026 13:59:34 +0800 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 v3 10/13] mm/huge_memory: separate out the folio part of zap_huge_pmd() To: "Lorenzo Stoakes (Oracle)" , Andrew Morton Cc: 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 References: <6c4db67952f5529da4db102a6149b9050b5dda4e.1774029655.git.ljs@kernel.org> From: Baolin Wang In-Reply-To: <6c4db67952f5529da4db102a6149b9050b5dda4e.1774029655.git.ljs@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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. With that, Reviewed-by: Baolin Wang