From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 2B205944F for ; Thu, 26 Feb 2026 01:30:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772069423; cv=none; b=kpmud+fFRKxlXYHmLwPIcoGmyZEtCmfHBiW6xiv6dbStE45Tj4d9wwe57BtpG6wWCO/8vOpTJWcRlhSjizknwiSkptUReiZhV/igkMWmlJT0V9Acz/fNSFEz7vKAziDnnpKwzHQUWc2o1f1nBC2GSIYIauJiBpXXf7b70Hp/8ko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772069423; c=relaxed/simple; bh=ilnGoLuY6JJJL+FoX3zDJQP9xpus/qy+rN3EvVEcrHs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NDC0rap+g8YV8P910WyUJ5GDDq9U6eh9h+3jhi/Wy3PombfHeKSr17AqeMAsweukDYAzy+r4w6TVmvq5ARXj3RhlG3shI+Gk4qZzT+36cIqk/fVu1rKPQk423vyBmAH4o4AcY6HgORXxKLWJEbTuAl1cT4ZejDa3dkcj/CaNKuM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Db7uNFQu; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Db7uNFQu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772069421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=M0YEBPy3Jmhtqggio/qwqreiYc/B8zsRq7a21Upohf8=; b=Db7uNFQukclN3WVdm76dD7A8twT0qgxMgeAbE8RU1IhIAUDSmp5HQwosxbo8LA0+ZG6cbW DhhayUPcvV3WM9OY4684ME14CWjweW8/G4/XvQqQoCyCl7VFg33qfiBvQpBiHDA7HOSCGo Rz/odnSzbAaSvazQLx+eUXXXv6TiX74= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-xMjun1dOPHqI75pONalX4Q-1; Wed, 25 Feb 2026 20:30:19 -0500 X-MC-Unique: xMjun1dOPHqI75pONalX4Q-1 X-Mimecast-MFC-AGG-ID: xMjun1dOPHqI75pONalX4Q_1772069418 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A259F1956052; Thu, 26 Feb 2026 01:30:18 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.64.173]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BFDB33003D88; Thu, 26 Feb 2026 01:30:02 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: aarcange@redhat.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, apopple@nvidia.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, byungchul@sk.com, catalin.marinas@arm.com, cl@gentwo.org, corbet@lwn.net, dave.hansen@linux.intel.com, david@kernel.org, dev.jain@arm.com, gourry@gourry.net, hannes@cmpxchg.org, hughd@google.com, jackmanb@google.com, jack@suse.cz, jannh@google.com, jglisse@google.com, joshua.hahnjy@gmail.com, kas@kernel.org, lance.yang@linux.dev, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, mathieu.desnoyers@efficios.com, matthew.brost@intel.com, mhiramat@kernel.org, mhocko@suse.com, npache@redhat.com, peterx@redhat.com, pfalcato@suse.de, rakie.kim@sk.com, raquini@redhat.com, rdunlap@infradead.org, richard.weiyang@gmail.com, rientjes@google.com, rostedt@goodmis.org, rppt@kernel.org, ryan.roberts@arm.com, shivankg@amd.com, sunnanyong@huawei.com, surenb@google.com, thomas.hellstrom@linux.intel.com, tiwai@suse.de, usamaarif642@gmail.com, vbabka@suse.cz, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, will@kernel.org, willy@infradead.org, yang@os.amperecomputing.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, zokeefe@google.com Subject: [PATCH mm-unstable v2 0/5] mm: khugepaged cleanups and mTHP prerequisites Date: Wed, 25 Feb 2026 18:29:24 -0700 Message-ID: <20260226012929.169479-1-npache@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 The following series contains cleanups and prerequisites for my work on khugepaged mTHP support [1]. These have been separated out to ease review. The first patch in the series refactors the page fault folio to pte mapping and follows a similar convention as defined by map_anon_folio_pmd_(no)pf(). This not only cleans up the current implementation of do_anonymous_page(), but will allow for reuse later in the khugepaged mTHP implementation. The second patch adds a small is_pmd_order() helper to check if an order is the PMD order. This check is open-coded in a number of places. This patch aims to clean this up and will be used more in the khugepaged mTHP work. The third patch also adds a small DEFINE for (HPAGE_PMD_NR - 1) which is used often across the khugepaged code. The fourth and fifth patch come from the khugepaged mTHP patchset [1]. These two patches include the rename of function prefixes, and the unification of khugepaged and madvise_collapse via a new collapse_single_pmd function. Patch 1: refactor do_anonymous_page into map_anon_folio_pte_(no)pf Patch 2: add is_pmd_order helper Patch 3: Add define for (HPAGE_PMD_NR - 1) Patch 4: Refactor/rename hpage_collapse Patch 5: Refactoring to combine madvise_collapse and khugepaged Testing: - Built for x86_64, aarch64, ppc64le, and s390x - ran all arches on test suites provided by the kernel-tests project - selftests mm V2 Changes: - patch1: add missing pte_sw_mkyoung [2] - patch1: the switch to maybe_mkwrite introduced a functional change causing pte_mkdirty to no longer run conditionally. switch back to the original call format [2] - patch1: fix minor formatting issues [3] - patch2: found/added more open-coded is_pmd_order() checks - patch3: only use the define for cases referring to the khugepaged limits. [4] - patch5: Move the last bits of the new writeback retry logic into collapse_single_pmd. My previous version had this logic split across madvise_collapse and collapse_single_pmd. [5](Thanks David!) - did not add review/ack's on patch 1 or 5 due to the above changes. V1 - https://lore.kernel.org/lkml/20260212021835.17755-1-npache@redhat.com/ A big thanks to everyone that has reviewed, tested, and participated in the development process. [1] - https://lore.kernel.org/all/20260122192841.128719-1-npache@redhat.com/ [2] - https://lore.kernel.org/lkml/CAA1CXcC7SPkehNLT8FUnnUf6m0vm3GbhZuDZyMMW4X0DHDs6Mg@mail.gmail.com/ [3] - https://lore.kernel.org/lkml/20260212155539.2083102-1-joshua.hahnjy@gmail.com/ [4] - https://lore.kernel.org/lkml/493d7898-c959-42ee-ad09-35ffc631ec21@kernel.org/ [5] - https://lore.kernel.org/lkml/92e9d637-988a-4201-8c8b-c29987b727bb@kernel.org/ Nico Pache (5): mm: consolidate anonymous folio PTE mapping into helpers mm: introduce is_pmd_order helper mm/khugepaged: define COLLAPSE_MAX_PTES_LIMIT as HPAGE_PMD_NR - 1 mm/khugepaged: rename hpage_collapse_* to collapse_* mm/khugepaged: unify khugepaged and madv_collapse with collapse_single_pmd() include/linux/huge_mm.h | 5 + include/linux/mm.h | 4 + mm/huge_memory.c | 2 +- mm/khugepaged.c | 206 +++++++++++++++++++++------------------- mm/memory.c | 61 ++++++++---- mm/mempolicy.c | 2 +- mm/mremap.c | 2 +- mm/page_alloc.c | 4 +- mm/shmem.c | 3 +- 9 files changed, 163 insertions(+), 126 deletions(-) -- 2.53.0