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.129.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 6E17427A918 for ; Thu, 15 May 2025 03:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747278353; cv=none; b=JQxGP9ITi2OeSEf3lrp766gXHdEbWn27WmjnShWtKeKXJahqotfTWD121rco0nq7JQg8rk2q8VmsOD4nm7/Fzc4tH3L78cu0eHsCE6UifnVZhDAwFPISx+1BXKiFYkNy6e72REehbz3yRDLid/PNmnHIVdk8dqYrswh32RWUEU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747278353; c=relaxed/simple; bh=dQ/iV4cb1Q+FJyAyu9gz9VD2gwHkq5d/kGbL87xQpBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aJvzHjpyVK95N/htJ1DX15/Iy46MEuvT63gXtrrBzLP7FTkGH8QiR0ZRTW6fIpiUrEO01Uth8awSB9qr0jRzMA7bOZeAQEFcmcfwam1wUkGoGwwGwdhLVFDDnMpIAM8XjhsmjYx7ho4gmrMY4kDP+e6yXN0xmPgkbPVt0qn4beo= 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=XZnnlwHW; arc=none smtp.client-ip=170.10.129.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="XZnnlwHW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747278351; 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=OrKdsqD76fFlVfD/sTRJDFrWM3KIaHlqn6po5lq3sK8=; b=XZnnlwHWGP3T9sTF3kTCwIA9lT1VvL473pxvbJ7YeIS4yCXEvkhvBzg1gaR4I30CEIQhTz EMm2OT5J+0AlDmLcLYM2jIwtbKi/v06EGir+rrRpLSAEaw80iUAIdlSMkpAtbvU4iaCCeD gK3zfGbx1GE57TFAB6oaA1z4KjXozLc= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-pckoVNStNzCBKLY7OttxnA-1; Wed, 14 May 2025 23:05:47 -0400 X-MC-Unique: pckoVNStNzCBKLY7OttxnA-1 X-Mimecast-MFC-AGG-ID: pckoVNStNzCBKLY7OttxnA_1747278343 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2BD99180036F; Thu, 15 May 2025 03:05:43 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.88.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 012751800268; Thu, 15 May 2025 03:05:27 +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, kirill.shutemov@linux.intel.com, 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 Subject: [PATCH v6 08/12] khugepaged: skip collapsing mTHP to smaller orders Date: Wed, 14 May 2025 21:03:08 -0600 Message-ID: <20250515030312.125567-9-npache@redhat.com> In-Reply-To: <20250515030312.125567-8-npache@redhat.com> References: <20250515030312.125567-1-npache@redhat.com> <20250515030312.125567-2-npache@redhat.com> <20250515030312.125567-3-npache@redhat.com> <20250515030312.125567-4-npache@redhat.com> <20250515030312.125567-5-npache@redhat.com> <20250515030312.125567-6-npache@redhat.com> <20250515030312.125567-7-npache@redhat.com> <20250515030312.125567-8-npache@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-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.93 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: Baolin Wang Co-developed-by: Dev Jain Signed-off-by: Dev Jain Signed-off-by: Nico Pache --- mm/khugepaged.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index afad75fc01b7..5920d4715a11 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -625,7 +625,12 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, folio = page_folio(page); VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio); - /* See hpage_collapse_scan_pmd(). */ + if (order != HPAGE_PMD_ORDER && folio_order(folio) >= order) { + result = SCAN_PTE_MAPPED_HUGEPAGE; + goto out; + } + + /* See khugepaged_scan_pmd(). */ if (folio_maybe_mapped_shared(folio)) { ++shared; if (order != HPAGE_PMD_ORDER || (cc->is_khugepaged && -- 2.49.0