From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (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 CBBC92EDD7E for ; Mon, 9 Feb 2026 14:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770646070; cv=none; b=dhsHxZHS4NPs9oetKjsBqgewkKOxUoGcyg0pVIUFlP+cOWLpPCQg2bqKzUDu0ml5lmW/Abwp77cUKMblyYBHz0h3mbFwhKeqdAKv7lhE5Qea0JMFoSeV76z23UzykeJhgZb3WUIt8XCU6OyJI9UtZX+bD6mxed6EAQGj0UA2LkY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770646070; c=relaxed/simple; bh=DDWunYxuNNyKtP7h3cssWJbxkzUkhB7h+ZeA2T1TpwE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JZH2Gj1gyWEvkQ6KIiOo6ag7Semef2k5/V+gXdKdTTv2EG0nAfRsG+xp33ynX95/ofwQrdI1zgjE9Q7dg7KjgPWKpgTweUKdIVtOmQX5iDtyzcEdEvGQi50g+fUG3VD6ufH7LxmDWfUlcwU4bJd8SuMsXlngFjCXlGPYeIPwBi8= 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=fEa/xyUz; arc=none smtp.client-ip=115.124.30.99 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="fEa/xyUz" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1770646059; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=k1HUXViArmspO18Ot//s5xhWbkVXwA17QN0XfFUufik=; b=fEa/xyUzzTkIM7eSz+nN4rn61qCCZEZWsGfhkqeVXx3vtZXtuLMZwR9z1ZNVNJTjoM7nCaKgJ55UAYHR51My6mfwKJoL0qX3JMRLsd09ESIdaxJieLLSaNsSTC3dvhRa4+J1E9WbN0s7IVKN6v8euLqU51Q4gDAhukoDljELPgo= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WytOcor_1770646056 cluster:ay36) by smtp.aliyun-inc.com; Mon, 09 Feb 2026 22:07:37 +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 v6 0/5] support batch checking of references and unmapping for large folios Date: Mon, 9 Feb 2026 22:07:23 +0800 Message-ID: X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, folio_referenced_one() always checks the young flag for each PTE sequentially, which is inefficient for large folios. This inefficiency is especially noticeable when reclaiming clean file-backed large folios, where folio_referenced() is observed as a significant performance hotspot. Moreover, on Arm architecture, which supports contiguous PTEs, there is already an optimization to clear the young flags for PTEs within a contiguous range. However, this is not sufficient. We can extend this to perform batched operations for the entire large folio (which might exceed the contiguous range: CONT_PTE_SIZE). Similar to folio_referenced_one(), we can also apply batched unmapping for large file folios to optimize the performance of file folio reclamation. By supporting batched checking of the young flags, flushing TLB entries, and unmapping, I can observed a significant performance improvements in my performance tests for file folios reclamation. Please check the performance data in the commit message of each patch. Run stress-ng and mm selftests, no issues were found. Patch 1: Add a new generic batched PTE helper that supports batched checks of the references for large folios. Patch 2 - 3: Preparation patches. patch 4: Implement the Arm64 arch-specific clear_flush_young_ptes(). Patch 5: Support batched unmapping for file large folios. Changes from v5: - Collect reviewed tags from Ryan, Harry and David. Thanks. - Fix some coding style issues (per David). - Skip batched unmapping for uffd case, reported by Dev. Thanks. Changes from v4: - Fix passing the incorrect 'CONT_PTES' for non-batched APIs. - Rename ptep_clear_flush_young_notify() to clear_flush_young_ptes_notify() (per Ryan). - Fix some coding style issues (per Ryan). - Add reviewed tag from Ryan. Thanks. Changes from v3: - Fix using an incorrect parameter in ptep_clear_flush_young_notify() (per Liam). Changes from v2: - Rearrange the patch set (per Ryan). - Add pte_cont() check in clear_flush_young_ptes() (per Ryan). - Add a helper to do contpte block alignment (per Ryan). - Fix some coding style issues (per Lorenzo and Ryan). - Add more comments and update the commit message (per Lorenzo and Ryan). - Add acked tag from Barry. Thanks. Changes from v1: - Add a new patch to support batched unmapping for file large folios. - Update the cover letter Baolin Wang (5): mm: rmap: support batched checks of the references for large folios arm64: mm: factor out the address and ptep alignment into a new helper arm64: mm: support batch clearing of the young flag for large folios arm64: mm: implement the architecture-specific clear_flush_young_ptes() mm: rmap: support batched unmapping for file large folios arch/arm64/include/asm/pgtable.h | 23 ++++++++---- arch/arm64/mm/contpte.c | 62 ++++++++++++++++++++------------ include/linux/mmu_notifier.h | 9 ++--- include/linux/pgtable.h | 35 ++++++++++++++++++ mm/rmap.c | 38 ++++++++++++++++---- 5 files changed, 129 insertions(+), 38 deletions(-) -- 2.47.3