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 8CFDB63CB for ; Mon, 14 Jul 2025 00:34:39 +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=1752453281; cv=none; b=BEA/OdvwFCnQ7jPrnkRdAxBGQskLV+d2BjtES/tguOga2dxQF3uLy5QduOruIinIeBwQj8LIusUh8J3exzj1pXl4zlhETTGcewXn4noicqWeoe4Sww4L2Sr0AGQ40xHHMmoF3NaoY8ZtdK+oJh4P/bTBmOu8cuWe/yGX/tH548g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752453281; c=relaxed/simple; bh=qJh2MdilikLFO+mVWggjFb6+Olw5U5zw1OBUvvvtXMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pq0a5PhCzGH9ZyJ+MOAH9i5uaC7vj8BK88HWGkyQMjJKZ9GwWbnvtb374atLzqcWJIayF9nm4epYu4AEi6RTrunRxRy/3UCqxzA0MjSUwj/EmPezj8rfDoOEqh50kILBHmqnMDp1HYiyBvn/2ciIWWThip6/YoPSHlPLbDNpiCA= 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=NBMa40cr; 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="NBMa40cr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752453278; 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=W+J7kSzbC+P3Afm1dYs56pHBZuXjXuwK76sETip7T+g=; b=NBMa40crvEFcnEOaaXHAG9yRcYx9XAT3gJ31iTVCa/0VLsIzTGRmnO0HZgg6qxmXKEPjHB r64Cnzp3a5fzuvsAtjWJj9JzLyES+EqLcQSV8r7Xz23x2YH5XzPvmvNQ9HWeBZUEgbXhVs m6NGdrXJJeSVrbWB4SakUbLzwhc0svw= 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-536-hp-nHdCEO9GNmvkLaEQZTQ-1; Sun, 13 Jul 2025 20:33:28 -0400 X-MC-Unique: hp-nHdCEO9GNmvkLaEQZTQ-1 X-Mimecast-MFC-AGG-ID: hp-nHdCEO9GNmvkLaEQZTQ_1752453204 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 82E9C19373DC; Mon, 14 Jul 2025 00:33:23 +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 E4B4230001B5; Mon, 14 Jul 2025 00:33:09 +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 03/14] khugepaged: generalize hugepage_vma_revalidate for mTHP support Date: Sun, 13 Jul 2025 18:31:56 -0600 Message-ID: <20250714003207.113275-4-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" For khugepaged to support different mTHP orders, we must generalize this to check if the PMD is not shared by another VMA and the order is enabled. To ensure madvise_collapse can support working on mTHP orders without the PMD order enabled, we need to convert hugepage_vma_revalidate to take a bitmap of orders. No functional change in this patch. Reviewed-by: Baolin Wang Co-developed-by: Dev Jain Signed-off-by: Dev Jain Signed-off-by: Nico Pache Acked-by: David Hildenbrand --- mm/khugepaged.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 47a80638af97..fa0642e66790 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -907,7 +907,7 @@ static int collapse_find_target_node(struct collapse_co= ntrol *cc) static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long add= ress, bool expect_anon, struct vm_area_struct **vmap, - struct collapse_control *cc) + struct collapse_control *cc, unsigned long orders) { struct vm_area_struct *vma; unsigned long tva_flags =3D cc->is_khugepaged ? TVA_ENFORCE_SYSFS : 0; @@ -919,9 +919,10 @@ static int hugepage_vma_revalidate(struct mm_struct *m= m, unsigned long address, if (!vma) return SCAN_VMA_NULL; =20 + /* Always check the PMD order to insure its not shared by another VMA */ if (!thp_vma_suitable_order(vma, address, PMD_ORDER)) return SCAN_ADDRESS_RANGE; - if (!thp_vma_allowable_order(vma, vma->vm_flags, tva_flags, PMD_ORDER)) + if (!thp_vma_allowable_orders(vma, vma->vm_flags, tva_flags, orders)) return SCAN_VMA_CHECK; /* * Anon VMA expected, the address may be unmapped then @@ -1123,7 +1124,8 @@ static int collapse_huge_page(struct mm_struct *mm, u= nsigned long address, goto out_nolock; =20 mmap_read_lock(mm); - result =3D hugepage_vma_revalidate(mm, address, true, &vma, cc); + result =3D hugepage_vma_revalidate(mm, address, true, &vma, cc, + BIT(HPAGE_PMD_ORDER)); if (result !=3D SCAN_SUCCEED) { mmap_read_unlock(mm); goto out_nolock; @@ -1157,7 +1159,8 @@ static int collapse_huge_page(struct mm_struct *mm, u= nsigned long address, * mmap_lock. */ mmap_write_lock(mm); - result =3D hugepage_vma_revalidate(mm, address, true, &vma, cc); + result =3D hugepage_vma_revalidate(mm, address, true, &vma, cc, + BIT(HPAGE_PMD_ORDER)); if (result !=3D SCAN_SUCCEED) goto out_up_write; /* check if the pmd is still valid */ @@ -2788,7 +2791,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsi= gned long start, mmap_read_lock(mm); mmap_locked =3D true; result =3D hugepage_vma_revalidate(mm, addr, false, &vma, - cc); + cc, BIT(HPAGE_PMD_ORDER)); if (result !=3D SCAN_SUCCEED) { last_fail =3D result; goto out_nolock; --=20 2.50.0