From patchwork Thu Apr 17 00:02:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 14054651 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 ED236846C for ; Thu, 17 Apr 2025 00:07:28 +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=1744848450; cv=none; b=qlqTKxj4uE6gtIElSP+cRNCCdDsmFYM+KE/7RpSvD5TFhhnCfhpa5pWbpCdi3SobHqr4sl9fzx2U+h5XKmJnY+REu99UocW9vH9o8cFSx9PwZiJTPO3lO4UjKrWMGMZF0+leNes/omqpwo2nOX5c0nXAVHuEziLot44ExN+5CWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744848450; c=relaxed/simple; bh=oltoYPMQc50i+E0eWwNf5tbHqCPAnW3mSrRMCnH/NtM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k+M2k7g1mB/tTP4C4AkzlYX/SDSbjQ4Kml7s3l7d4fXIvFL2M8vF7fF4PF1PCziQNPA/zSe7sbgVsuc5LlK5iEYIJztLzQS1gsyKD8bzWVUHhc9bKWD/SnakbgoXKT1WmwGTAq+sLlMKNuOO5Uk/cnHZAKY5J9YvRUa/lOrucyk= 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=cVHPt5s9; 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="cVHPt5s9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744848447; 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=lT7Le5l3OvCTeyxGbSyLQ+XqGfqD4qwGKJUaU5ZKhXs=; b=cVHPt5s9RDYPxIUG8vqbmIeqyXoW7AWB+gU7XWCpLZTwAFt2CsilD7zxC5/xOMlEiEMLXL pfeoNHthCR5bQ+uwdpxMn9ewk8o1S+XcyFDnRFCkfn53d9kTsm0BHzwCwzzZ4+hGBoxUu3 NH+MKHDxOUkqNw0p85YGB5a2KbYEyqs= 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-445-eXBT7ml8MMi_oRCb4gBEvA-1; Wed, 16 Apr 2025 20:07:23 -0400 X-MC-Unique: eXBT7ml8MMi_oRCb4gBEvA-1 X-Mimecast-MFC-AGG-ID: eXBT7ml8MMi_oRCb4gBEvA_1744848439 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A0230180036E; Thu, 17 Apr 2025 00:07:19 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.88.34]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4933F180045B; Thu, 17 Apr 2025 00:07:11 +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 Subject: [PATCH v4 09/12] khugepaged: avoid unnecessary mTHP collapse attempts Date: Wed, 16 Apr 2025 18:02:35 -0600 Message-ID: <20250417000238.74567-10-npache@redhat.com> In-Reply-To: <20250417000238.74567-1-npache@redhat.com> References: <20250417000238.74567-1-npache@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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 383aff12cd43..738dd9c5751d 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1366,6 +1366,23 @@ static int khugepaged_scan_bitmap(struct mm_struct *mm, unsigned long address, collapsed += (1 << order); continue; } + /* + * Some ret values indicate all lower order will also + * fail, dont trying to collapse smaller orders + */ + if (ret == SCAN_EXCEED_NONE_PTE || + ret == SCAN_EXCEED_SWAP_PTE || + ret == SCAN_EXCEED_SHARED_PTE || + ret == SCAN_PTE_NON_PRESENT || + ret == SCAN_PTE_UFFD_WP || + ret == SCAN_ALLOC_HUGE_PAGE_FAIL || + ret == SCAN_CGROUP_CHARGE_FAIL || + ret == SCAN_COPY_MC || + ret == SCAN_PAGE_LOCK || + ret == SCAN_PAGE_COUNT) + goto next; + else + break; } next: