From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47AE029CE9 for ; Wed, 7 Jan 2026 03:31:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767756673; cv=none; b=fies7vMuiyFYufH8x+5XrhGShVZG8ymX6FBIzOO0GuC1YFsfZxwsGu2M3BlA1kDeXmvgBYiltFk4+g0DBdkioeHgtA0fNJmuHo72PLmguQoPJghmffR973LZTZ46CKtx1fQF2MC5H1DEFyINrVQEr1gcxQ80d3nf6wQPNFwX6uQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767756673; c=relaxed/simple; bh=NnAoTos6SQrSuf6HTiM/hQXkSHAnf4AMQ/lqYrSq620=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CU2BS4NK62f/riqFOYRyoqLlseheJtGOSjHe1H1SpaeW4fHAheCeV4lEc3lwr6g0GXKUapvh/cgKmEkHQV6i5HVtOW0Y0E/l3mKXV9dd18vxss49+fMaBUKXTwj6TO2SwFxsz0/K9D3/amSPLUAXr2/hvgbmGmzXMgSUasm85q4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CtuK6eB2; arc=none smtp.client-ip=209.85.208.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CtuK6eB2" Received: by mail-ed1-f65.google.com with SMTP id 4fb4d7f45d1cf-64ba9a00b5aso2262146a12.2 for ; Tue, 06 Jan 2026 19:31:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767756669; x=1768361469; darn=vger.kernel.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ptUxQkZ+K9ShX84WxQzr80zRKVliAxBdsbmpSy77G1U=; b=CtuK6eB2ye57M3olv4TVwysUCMVtAxHCInH8EEcuI7P+qL+JITZOXsSZVU64qIXQWA AYUixDMRyWqotSk7k70JuuAqeDif3wEYh8gykWU2W0C6Yx/hiPwwGmUV+G1q6DoOwzgG l8rmxwzvjwk87Do9taB7ZMKx+6IMZrXKh1cTA0nUYaOLGmj8cIynMA9wbuC77qGK1eil j23pJlG84hgeHj1544LmMULeov70QVsh+CtpYZKnRrovq/nBgioJcY/+Em7grvBxqvYS nB+HIHbcGnB2iUcbWuyeEW0gVqrWXF4hpYNge9wMF6q+ZBYsVtGOVfeeXpxfdeu5yTeI HFUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767756669; x=1768361469; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ptUxQkZ+K9ShX84WxQzr80zRKVliAxBdsbmpSy77G1U=; b=PeJqu+3BKQXS+8KjptMiU08Ez8pGU+VadEi+y+CiiKANFqAT9V9lcXDu07slgxsfvy CXbNFyRaE3btygs7uKkXS6vMx2C5MY1DKqYDM2ZwywbjHnhOqN43TIwSegt41D+nojfl xbq/uqhIHjOJTltx8h811ADlOHESsKZa5ZOBwQWS+LFn0SuE+wt4jr8hk0NyKeKNdjQz 2EEpDCB8mUSTrROR0urbtnU5cK07DQDeZHg67bSc5lJtFr/z/xxVKwrWJyOfIo1hUp9F jamme/IqE+pb+m8NBageTK7nqvOcYgm777ZePPfjSH4etqwnGgQGTaShwyIFjqlC2xsr 9dxQ== X-Forwarded-Encrypted: i=1; AJvYcCWQmIpv3lxtVfPgMICS15+ox6vtXjLLnaQLeMt86difVYiKh2IeS1V9HKu6r5vfoI2cza0RcGPARhE6d5k=@vger.kernel.org X-Gm-Message-State: AOJu0YxJggudFbFHn3xDe/TR6L+ushOWkDSCB4EQ8upY6DckV9m/JpbM IIS9nXfecfB45DvxtC6ikUL8iR1uI/WoAIGtOEvQMH6SCKhJ0jOZOpy/ X-Gm-Gg: AY/fxX7Z34kJd7zW29nwv2imp4AKl92FqSkuQtB7fi0mK+GJgMm8jRPQ2rRtRun1nVO k4TJG+COiuKz1ACQbG95gnA2GjZl3hBbX+iX8AHtoWBabcd4EkTO2mnxjePCHUBOm3Oszxtv0TP 3tW7QMbepkBH34C+NXXAVCpPVn/rlF30F1NSVD+vq0rD2c6lXKqbmiBb1SgsokCthOmyMSJp4/0 Qw2ZCOP9vh2LS2plAgOJgCS3Gz+Y6oodrD6r5UKAvTob+W+SZgac5i/OFO0rQs5/frNKpuD6Onq 1IZSMreKPfBGbRRYhCpMGap+/yrWajkOUV3GJ/VoK06bpmQMF5XVeL90rd2aNsZj0ZRR/1wrlsT Eb9K3SH6u+ONB22Z1hnCSGzck3sItgCnQpnLrMwhq2/ncEA9ZymhaH8a68dxB7UCFLmisGpamYX zyhCez9i8oGA== X-Google-Smtp-Source: AGHT+IHXrUepqohER4eBi/ltvOeG/vWbcCIBmPjJ/7BGwIJoB6JHs+TLloUHrygj8bn21j4DVZ0kQQ== X-Received: by 2002:a17:907:72d2:b0:b6d:4df9:68bc with SMTP id a640c23a62f3a-b8444c59fb8mr112453566b.1.1767756669213; Tue, 06 Jan 2026 19:31:09 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b842a233fb3sm384401966b.12.2026.01.06.19.31.08 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jan 2026 19:31:08 -0800 (PST) Date: Wed, 7 Jan 2026 03:31:08 +0000 From: Wei Yang To: Baolin Wang Cc: Barry Song <21cnbao@gmail.com>, Wei Yang , akpm@linux-foundation.org, david@kernel.org, catalin.marinas@arm.com, will@kernel.org, lorenzo.stoakes@oracle.com, ryan.roberts@arm.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, riel@surriel.com, harry.yoo@oracle.com, jannh@google.com, willy@infradead.org, dev.jain@arm.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 5/5] mm: rmap: support batched unmapping for file large folios Message-ID: <20260107033108.4rspmaq26fewygci@master> Reply-To: Wei Yang References: <142919ac14d3cf70cba370808d85debe089df7b4.1766631066.git.baolin.wang@linux.alibaba.com> <20260106132203.kdxfvootlkxzex2l@master> <20260107014601.dxvq6b7ljgxwg7iu@master> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) On Wed, Jan 07, 2026 at 10:29:18AM +0800, Baolin Wang wrote: > > >On 1/7/26 10:21 AM, Barry Song wrote: >> On Wed, Jan 7, 2026 at 2:46 PM Wei Yang wrote: >> > >> > On Wed, Jan 07, 2026 at 10:29:25AM +1300, Barry Song wrote: >> > > On Wed, Jan 7, 2026 at 2:22 AM Wei Yang wrote: >> > > > >> > > > On Fri, Dec 26, 2025 at 02:07:59PM +0800, Baolin Wang wrote: >> > > > > Similar to folio_referenced_one(), we can apply batched unmapping for file >> > > > > large folios to optimize the performance of file folios reclamation. >> > > > > >> > > > > Barry previously implemented batched unmapping for lazyfree anonymous large >> > > > > folios[1] and did not further optimize anonymous large folios or file-backed >> > > > > large folios at that stage. As for file-backed large folios, the batched >> > > > > unmapping support is relatively straightforward, as we only need to clear >> > > > > the consecutive (present) PTE entries for file-backed large folios. >> > > > > >> > > > > Performance testing: >> > > > > Allocate 10G clean file-backed folios by mmap() in a memory cgroup, and try to >> > > > > reclaim 8G file-backed folios via the memory.reclaim interface. I can observe >> > > > > 75% performance improvement on my Arm64 32-core server (and 50%+ improvement >> > > > > on my X86 machine) with this patch. >> > > > > >> > > > > W/o patch: >> > > > > real 0m1.018s >> > > > > user 0m0.000s >> > > > > sys 0m1.018s >> > > > > >> > > > > W/ patch: >> > > > > real 0m0.249s >> > > > > user 0m0.000s >> > > > > sys 0m0.249s >> > > > > >> > > > > [1] https://lore.kernel.org/all/20250214093015.51024-4-21cnbao@gmail.com/T/#u >> > > > > Reviewed-by: Ryan Roberts >> > > > > Acked-by: Barry Song >> > > > > Signed-off-by: Baolin Wang >> > > > > --- >> > > > > mm/rmap.c | 7 ++++--- >> > > > > 1 file changed, 4 insertions(+), 3 deletions(-) >> > > > > >> > > > > diff --git a/mm/rmap.c b/mm/rmap.c >> > > > > index 985ab0b085ba..e1d16003c514 100644 >> > > > > --- a/mm/rmap.c >> > > > > +++ b/mm/rmap.c >> > > > > @@ -1863,9 +1863,10 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio, >> > > > > end_addr = pmd_addr_end(addr, vma->vm_end); >> > > > > max_nr = (end_addr - addr) >> PAGE_SHIFT; >> > > > > >> > > > > - /* We only support lazyfree batching for now ... */ >> > > > > - if (!folio_test_anon(folio) || folio_test_swapbacked(folio)) >> > > > > + /* We only support lazyfree or file folios batching for now ... */ >> > > > > + if (folio_test_anon(folio) && folio_test_swapbacked(folio)) >> > > > > return 1; >> > > > > + >> > > > > if (pte_unused(pte)) >> > > > > return 1; >> > > > > >> > > > > @@ -2231,7 +2232,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, >> > > > > * >> > > > > * See Documentation/mm/mmu_notifier.rst >> > > > > */ >> > > > > - dec_mm_counter(mm, mm_counter_file(folio)); >> > > > > + add_mm_counter(mm, mm_counter_file(folio), -nr_pages); >> > > > > } >> > > > > discard: >> > > > > if (unlikely(folio_test_hugetlb(folio))) { >> > > > > -- >> > > > > 2.47.3 >> > > > > >> > > > >> > > > Hi, Baolin >> > > > >> > > > When reading your patch, I come up one small question. >> > > > >> > > > Current try_to_unmap_one() has following structure: >> > > > >> > > > try_to_unmap_one() >> > > > while (page_vma_mapped_walk(&pvmw)) { >> > > > nr_pages = folio_unmap_pte_batch() >> > > > >> > > > if (nr_pages = folio_nr_pages(folio)) >> > > > goto walk_done; >> > > > } >> > > > >> > > > I am thinking what if nr_pages > 1 but nr_pages != folio_nr_pages(). >> > > > >> > > > If my understanding is correct, page_vma_mapped_walk() would start from >> > > > (pvmw->address + PAGE_SIZE) in next iteration, but we have already cleared to >> > > > (pvmw->address + nr_pages * PAGE_SIZE), right? >> > > > >> > > > Not sure my understanding is correct, if so do we have some reason not to >> > > > skip the cleared range? >> > > >> > > I don’t quite understand your question. For nr_pages > 1 but not equal >> > > to nr_pages, page_vma_mapped_walk will skip the nr_pages - 1 PTEs inside. >> > > >> > > take a look: >> > > >> > > next_pte: >> > > do { >> > > pvmw->address += PAGE_SIZE; >> > > if (pvmw->address >= end) >> > > return not_found(pvmw); >> > > /* Did we cross page table boundary? */ >> > > if ((pvmw->address & (PMD_SIZE - PAGE_SIZE)) == 0) { >> > > if (pvmw->ptl) { >> > > spin_unlock(pvmw->ptl); >> > > pvmw->ptl = NULL; >> > > } >> > > pte_unmap(pvmw->pte); >> > > pvmw->pte = NULL; >> > > pvmw->flags |= PVMW_PGTABLE_CROSSED; >> > > goto restart; >> > > } >> > > pvmw->pte++; >> > > } while (pte_none(ptep_get(pvmw->pte))); >> > > >> > >> > Yes, we do it in page_vma_mapped_walk() now. Since they are pte_none(), they >> > will be skipped. >> > >> > I mean maybe we can skip it in try_to_unmap_one(), for example: >> > >> > diff --git a/mm/rmap.c b/mm/rmap.c >> > index 9e5bd4834481..ea1afec7c802 100644 >> > --- a/mm/rmap.c >> > +++ b/mm/rmap.c >> > @@ -2250,6 +2250,10 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, >> > */ >> > if (nr_pages == folio_nr_pages(folio)) >> > goto walk_done; >> > + else { >> > + pvmw.address += PAGE_SIZE * (nr_pages - 1); >> > + pvmw.pte += nr_pages - 1; >> > + } >> > continue; >> > walk_abort: >> > ret = false; >> >> >> I feel this couples the PTE walk iteration with the unmap >> operation, which does not seem fine to me. It also appears >> to affect only corner cases. > >Agree. There may be no performance gains, so I also prefer to leave it as is. Got it, thanks. -- Wei Yang Help you, Help me