From nobody Mon Feb 9 10:26:01 2026 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 533942957BC for ; Mon, 28 Apr 2025 18:14:05 +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=1745864047; cv=none; b=I2OyHlCaF6ZqWqvID86OQ2ole5NsONDUV8ZlVWgv3oSDKSsrflNnapkFiAHjyK7iipEhTzPV8/zf2moLZXkYRVRHghDfC2kG2GWYFoDWZvyFqwZHiI4NH4tCB+JwjLHLCy5WFnAI3nnu4pSW9mIT40Szn7wDmxBasVtI3DH/jOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745864047; c=relaxed/simple; bh=z4qGqVAHteYb356O98TgDOjX3bm35nFfTIwL8OhB43A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FAy3l6+ngXsEcjWk4L4c0/3LsIRaH6xFwJU6ydsKJyYrba917niSPFNIeqE8L3Nl3gyqXPpk3Z32s2Hbx7VeVvAiWuSrEoON879cMP1qyWfIv+RmLBeAclHF2W+H/qas8KHN+Vz0kbfzfqg5JmF2YLJvhPGDOZD0xTamFdfkX6U= 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=XPIK+v8P; 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="XPIK+v8P" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745864044; 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=VXX1Q1S6YWWF7541obLgN0IKvQHRe1QaMnMvIKwwN+I=; b=XPIK+v8PrFWu6hNIooNl2WybPrUhPPWJQ4LMTkg7kbD7AuRvLxShrIfRivJDzGVrKJISpA KIPqOM69fqLEXo4ViziL/Z0EVOySxde7UHlBR+LZmODaYdBgl/mVzsaTuu284qbSy9P8fx V7WQyxmGTgYKZwyklRnIFMgVP8yq3oU= Received: from mx-prod-mc-04.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-365-W2x8u2p5MKSMnDVTbh193Q-1; Mon, 28 Apr 2025 14:13:59 -0400 X-MC-Unique: W2x8u2p5MKSMnDVTbh193Q-1 X-Mimecast-MFC-AGG-ID: W2x8u2p5MKSMnDVTbh193Q_1745864036 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A99171955DC5; Mon, 28 Apr 2025 18:13:55 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.65.12]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BEC2018001DA; Mon, 28 Apr 2025 18:13:48 +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: akpm@linux-foundation.org, corbet@lwn.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, david@redhat.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, ryan.roberts@arm.com, willy@infradead.org, peterx@redhat.com, ziy@nvidia.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, dev.jain@arm.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, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com Subject: [PATCH v5 09/12] khugepaged: avoid unnecessary mTHP collapse attempts Date: Mon, 28 Apr 2025 12:12:15 -0600 Message-ID: <20250428181218.85925-10-npache@redhat.com> In-Reply-To: <20250428181218.85925-1-npache@redhat.com> References: <20250428181218.85925-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" There are cases where, if an attempted collapse fails, all subsequent orders are guaranteed to also fail. Avoid these collapse attempts by bailing out early. Signed-off-by: Nico Pache --- mm/khugepaged.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 86d1153ce9e8..5e6732cccb86 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1365,6 +1365,23 @@ static int khugepaged_scan_bitmap(struct mm_struct *= mm, unsigned long address, collapsed +=3D (1 << order); continue; } + /* + * Some ret values indicate all lower order will also + * fail, dont trying to collapse smaller orders + */ + if (ret =3D=3D SCAN_EXCEED_NONE_PTE || + ret =3D=3D SCAN_EXCEED_SWAP_PTE || + ret =3D=3D SCAN_EXCEED_SHARED_PTE || + ret =3D=3D SCAN_PTE_NON_PRESENT || + ret =3D=3D SCAN_PTE_UFFD_WP || + ret =3D=3D SCAN_ALLOC_HUGE_PAGE_FAIL || + ret =3D=3D SCAN_CGROUP_CHARGE_FAIL || + ret =3D=3D SCAN_COPY_MC || + ret =3D=3D SCAN_PAGE_LOCK || + ret =3D=3D SCAN_PAGE_COUNT) + goto next; + else + break; } =20 next: --=20 2.48.1