From nobody Thu Oct 2 21:54:45 2025 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 7E4D272613 for ; Fri, 12 Sep 2025 03:30:56 +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=1757647858; cv=none; b=Jf60NrNE1MORqTn66IdEV7T6dwYxYjUHXCWAFYuFp4krpHZoN9basfAVRDeS7j74YawsyYjo1IHQPadzLGI4D0+Mk9lgDKtP+8i5SrrK91ogUvCEqKpkIreSI45oSkq5VT1REKEsqQK35Z84f06Og96SfPMry8gFwPd2/lw82tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757647858; c=relaxed/simple; bh=qSZr/HiNxE8+FqedU8EAcRa7l0+8fuT7AyBwMXmIz3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SpxVoHeacT+cayLDuknRgXfxi1Pc/MjkhawBNF/IcrTseiHhtWpHbJN7H0yCvs+Ysz8YjKFMyVStlatbHgnby/ivgPeQuMQrldYNtINSVmtKrTDfCk2gO/OTI/q9xoKOWLlwmiSf8vTLHIl8O5jBnxlbhK6VaQ9R8XJ0BRo9drE= 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=QdO9fSHl; 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="QdO9fSHl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757647855; 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: in-reply-to:in-reply-to:references:references; bh=9kc/D3R1E4tB3N46/xRvTcnE3zMFjQQ6ARvrOttPH00=; b=QdO9fSHlDwoYx2IAdMWwJGjzy+D4RzQlp9HPz1aXvrxgfczU+/GEc1UZsfjWiLUgJNRRBW bUzU8XPJSG52q/EwkAa3UG4VXNTcSuOxSUE9WntjF1eRe5sEwtgmUxn53/NqOsSMv24ude h9CXaPJwa7+k914CQSpwu55uXF5B2v0= Received: from mx-prod-mc-01.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-322-iImcHlBZOBqp8n-HOYvhmg-1; Thu, 11 Sep 2025 23:30:49 -0400 X-MC-Unique: iImcHlBZOBqp8n-HOYvhmg-1 X-Mimecast-MFC-AGG-ID: iImcHlBZOBqp8n-HOYvhmg_1757647839 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A3EDD1953943; Fri, 12 Sep 2025 03:30:39 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.28]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0FD5A180035E; Fri, 12 Sep 2025 03:30:29 +0000 (UTC) From: Nico Pache To: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: david@redhat.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, dev.jain@arm.com, corbet@lwn.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, baohua@kernel.org, willy@infradead.org, peterx@redhat.com, wangkefeng.wang@huawei.com, usamaarif642@gmail.com, sunnanyong@huawei.com, vishal.moola@gmail.com, thomas.hellstrom@linux.intel.com, yang@os.amperecomputing.com, kas@kernel.org, aarcange@redhat.com, raquini@redhat.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, tiwai@suse.de, will@kernel.org, dave.hansen@linux.intel.com, jack@suse.cz, cl@gentwo.org, jglisse@google.com, surenb@google.com, zokeefe@google.com, hannes@cmpxchg.org, rientjes@google.com, mhocko@suse.com, rdunlap@infradead.org, hughd@google.com, richard.weiyang@gmail.com, lance.yang@linux.dev, vbabka@suse.cz, rppt@kernel.org, jannh@google.com, pfalcato@suse.de Subject: [PATCH v11 08/15] khugepaged: skip collapsing mTHP to smaller orders Date: Thu, 11 Sep 2025 21:28:03 -0600 Message-ID: <20250912032810.197475-9-npache@redhat.com> In-Reply-To: <20250912032810.197475-1-npache@redhat.com> References: <20250912032810.197475-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" khugepaged may try to collapse a mTHP to a smaller mTHP, resulting in some pages being unmapped. Skip these cases until we have a way to check if its ok to collapse to a smaller mTHP size (like in the case of a partially mapped folio). This patch is inspired by Dev Jain's work on khugepaged mTHP support [1]. [1] https://lore.kernel.org/lkml/20241216165105.56185-11-dev.jain@arm.com/ Reviewed-by: Lorenzo Stoakes Reviewed-by: Baolin Wang Acked-by: David Hildenbrand Co-developed-by: Dev Jain Signed-off-by: Dev Jain Signed-off-by: Nico Pache --- mm/khugepaged.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 248947e78a30..ebcc0c85a0d6 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -610,6 +610,15 @@ static int __collapse_huge_page_isolate(struct vm_area= _struct *vma, folio =3D page_folio(page); VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio); =20 + /* + * TODO: In some cases of partially-mapped folios, we'd actually + * want to collapse. + */ + if (order !=3D HPAGE_PMD_ORDER && folio_order(folio) >=3D order) { + result =3D SCAN_PTE_MAPPED_HUGEPAGE; + goto out; + } + /* See collapse_scan_pmd(). */ if (folio_maybe_mapped_shared(folio)) { ++shared; --=20 2.51.0