From nobody Sun Feb 8 03:57:49 2026 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (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 945132BE05B for ; Tue, 23 Dec 2025 05:49:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766468944; cv=none; b=iSDVOm78PIMz1UQqAw7lGDo86kQVrELsLl0p7g0z9zqx/WE6aoCD5nSZddmeJje9VEkwAoXDpnUfNgdG8B4SvKzyIvNsR5gr56+pr8fMmm+JTXMPZhUNF08eLJ0UnADUnczs9ryyE31A/h5n8gibf7Ew1LSHh+CSt3vDCcbRB2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766468944; c=relaxed/simple; bh=VXh/o28OXwT6EP2TyzG92ME41my07jcdRQ29RZ/in6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JM3iXSnkEul7u5ALepYIKF3g7voZP7tAJATj0S5Lj2ZBwpDf0twKsW1vN9/9Y6k0idfFHZvEf4pOrfepvNHFKAh3Ng4M7prjVX05NxFclARPyYS2rDocbzJRDvKKqD+297dAkVE44Kdi4u4dqT2UWzokDHons2JKWMiSslt+bgY= 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=F6QcNR32; arc=none smtp.client-ip=115.124.30.112 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="F6QcNR32" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1766468934; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=L8grYI0Jwq9L4Vxa84m+Wpr8ZQOY0j4j8t2HLaHt6zk=; b=F6QcNR32scZ94ZZB2nGdeXuxBO+ySRbl13YTyXMsYXXolVcT+fcT1Mh0Jk1YFCroP4eBvWK/OXJH/nceM62vL/mbGXRZD0PznJFpcnrTQJ+hBDNmlzxirIu62lFd+3mjaWyQjnpIVjs4tcwOtEFVoKk+vAuG7JGOdhwFHvBe6pI= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WvWSzHD_1766468931 cluster:ay36) by smtp.aliyun-inc.com; Tue, 23 Dec 2025 13:48:52 +0800 From: Baolin Wang To: akpm@linux-foundation.org, david@kernel.org, catalin.marinas@arm.com, will@kernel.org Cc: 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, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 5/5] mm: rmap: support batched unmapping for file large folios Date: Tue, 23 Dec 2025 13:48:39 +0800 Message-ID: X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 obser= ve 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 Acked-by: Barry Song Signed-off-by: Baolin Wang Reviewed-by: Ryan Roberts --- mm/rmap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index a0fc05f5966f..7482121d4e92 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1862,9 +1862,10 @@ static inline unsigned int folio_unmap_pte_batch(str= uct folio *folio, end_addr =3D pmd_addr_end(addr, vma->vm_end); max_nr =3D (end_addr - addr) >> PAGE_SHIFT; =20 - /* 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; =20 @@ -2230,7 +2231,7 @@ static bool try_to_unmap_one(struct folio *folio, str= uct 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))) { --=20 2.47.3