From nobody Tue Oct 7 07:17:56 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 E62BC1487F4 for ; Mon, 14 Jul 2025 00:35:10 +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=1752453312; cv=none; b=qxTs6zWjJn+OK6LcVGn241nbcAWACElg+dNqBo606wSCImk/nirqzw/Ed1IF1plu11Gm9j+fHal1XvuQg33aFZZWUPi2SVggdsu8Iki0Pd4EKQm515xCMEK8v5N7ONyZnaRMadDf1uiQXBZ3ZD1MkD47SFXfGaXZpeP3H+Spivg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752453312; c=relaxed/simple; bh=uP345dm49Iik13gh5fWta0zX9s4/3nA6rJzwThamf10=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jgneu8nCAkVbkrOlg4DJ+h8pbZskR8Onkz0bistpQmqMmVkgVdS+n9tBYPK0SOY81Opb5eVRxmehyTGgMfnVfGV/a3BOZwthBLowKVw3strAIEEWmv1qJuJcqkncO45W+3ObrnE83o52tZWKZ3jjQ81EM5JPxpOHFlWcTS21LJs= 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=L7kF3ass; 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="L7kF3ass" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752453309; 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=BY0uq/JwVuLAVo6hhpefEsrpjrJB6SfsaEu6VQnxYkM=; b=L7kF3assVXUh8JTQmpAb3Myk55DEyU5pPUugq5TLZ/V9vlq7GytZCOCNLJMARfgqcQEz6x UI6zBzDUHqW5qab+/bK0gJIVwxle+9dmEtYiOFjqwPEcH5zeUbESYIAfBzYAqty8d4Rr75 6geb2SyonhIHPzozjFkcFuxF98f2DMM= Received: from mx-prod-mc-06.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-486-vOWgCFvjO7-Cger7x3lYig-1; Sun, 13 Jul 2025 20:35:05 -0400 X-MC-Unique: vOWgCFvjO7-Cger7x3lYig-1 X-Mimecast-MFC-AGG-ID: vOWgCFvjO7-Cger7x3lYig_1752453301 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3302A1800289; Mon, 14 Jul 2025 00:35:01 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.64.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 789A730001A1; Mon, 14 Jul 2025 00:34: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: 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, hughd@google.com Subject: [PATCH v9 10/14] khugepaged: allow khugepaged to check all anonymous mTHP orders Date: Sun, 13 Jul 2025 18:32:03 -0600 Message-ID: <20250714003207.113275-11-npache@redhat.com> In-Reply-To: <20250714003207.113275-1-npache@redhat.com> References: <20250714003207.113275-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.4 Content-Type: text/plain; charset="utf-8" From: Baolin Wang We have now allowed mTHP collapse, but thp_vma_allowable_order() still only checks if the PMD-sized mTHP is allowed to collapse. This prevents scanning and collapsing of 64K mTHP when only 64K mTHP is enabled. Thus, we should modify the checks to allow all large orders of anonymous mTHP. Signed-off-by: Baolin Wang Signed-off-by: Nico Pache Acked-by: David Hildenbrand --- mm/khugepaged.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 7a9c4edf0e23..3772dc0d78ea 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -491,8 +491,11 @@ void khugepaged_enter_vma(struct vm_area_struct *vma, { if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && hugepage_pmd_enabled()) { - if (thp_vma_allowable_order(vma, vm_flags, TVA_ENFORCE_SYSFS, - PMD_ORDER)) + unsigned long orders =3D vma_is_anonymous(vma) ? + THP_ORDERS_ALL_ANON : BIT(PMD_ORDER); + + if (thp_vma_allowable_orders(vma, vm_flags, TVA_ENFORCE_SYSFS, + orders)) __khugepaged_enter(vma->vm_mm); } } @@ -2624,6 +2627,8 @@ static unsigned int collapse_scan_mm_slot(unsigned in= t pages, int *result, =20 vma_iter_init(&vmi, mm, khugepaged_scan.address); for_each_vma(vmi, vma) { + unsigned long orders =3D vma_is_anonymous(vma) ? + THP_ORDERS_ALL_ANON : BIT(PMD_ORDER); unsigned long hstart, hend; =20 cond_resched(); @@ -2631,8 +2636,8 @@ static unsigned int collapse_scan_mm_slot(unsigned in= t pages, int *result, progress++; break; } - if (!thp_vma_allowable_order(vma, vma->vm_flags, - TVA_ENFORCE_SYSFS, PMD_ORDER)) { + if (!thp_vma_allowable_orders(vma, vma->vm_flags, + TVA_ENFORCE_SYSFS, orders)) { skip: progress++; continue; --=20 2.50.0