From nobody Sun Feb 8 05:29:50 2026 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 1F68429D281 for ; Fri, 26 Dec 2025 06:08:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766729305; cv=none; b=gMXuDzNGIfSsZa6YdkFsVZ5QuA7Q6P/iw8LJVWUi9jQjrR0534kUlddaEtOyJoDSpEjtMP7Qm09MUZHpdI0EuGXLk8me4IZdcdnafJIDxnmoDjKYNAL1a4o49/DcM2BQpFhMGajKyxtCPzbvZzPrAN5aIviLuiE52rM9LTvqHIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766729305; c=relaxed/simple; bh=MfxlhrA88ORfcYR+9tQiZZEpWEDCsoJAyiNjy15xW5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KctUy5SjaHigsW3gTDYwLC4Gb1VRg7HbNHcRdBW59rDl4L9X6SVxyR4SNvDBdwFf/gnIDT+/xGG+SZKR5gJJjCiMNpHcqliKZOMeS2mX/kG+V+KjQZ4i/JNsbpD5Qa0SsV9SwV1bNNJy1ISp3v1YcTO0RH1aUHwZKlGthEhf2as= 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=g+ec1C/i; arc=none smtp.client-ip=115.124.30.97 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="g+ec1C/i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1766729295; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=AZ9WfEpVe/JlQetyc2ZwVRBQF0W+yj98KQzc8zM0fSE=; b=g+ec1C/iGT09Sv2dj9lVFXA/jBxqHE2dC+98DdCNHfnpKMj7s1zJxBO+5yBm3gdWVE4yjqHOcc8tpIrTNj+Wm+sOX/dotDMbv4hjQKwginWmPTT+22ZQnwtBQlIg+ClwEfNURYrRzS2kysvwor4vtFhiumvGXgCpSExhBwB/tbE= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WvgZmTZ_1766729292 cluster:ay36) by smtp.aliyun-inc.com; Fri, 26 Dec 2025 14:08:13 +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 v5 5/5] mm: rmap: support batched unmapping for file large folios Date: Fri, 26 Dec 2025 14:07:59 +0800 Message-ID: <142919ac14d3cf70cba370808d85debe089df7b4.1766631066.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.47.3 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 Reviewed-by: Ryan Roberts Acked-by: Barry Song Signed-off-by: Baolin Wang Reviewed-by: Harry Yoo --- 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(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 @@ -2231,7 +2232,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