From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (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 43899347FFE for ; Thu, 9 Apr 2026 12:27:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775737627; cv=none; b=Tbyj4LvDyI6sbiSXUCQE61FPd3lppaEgTMeLdrBIkcckC/eP2R3/BmIBC+oUIaDcrtwuRXEbYjIWJ7v2eJo7JuN2u6rxAxWK7f6z920/WXEcimUPg/Ey6djGDKY7X8VS+rrC04HTo2pgfVOJk/tblZMjcY1uK2ThgyOs0ZGg2kE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775737627; c=relaxed/simple; bh=TFvB+6WukVsjYjf3T1Bs6pMavgU1xbY8wtQH5XRQX1U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ckgcSRMLoOEF4kqopUmCP4FkfwJLSojbwcjE7ygZTkT4g/pwKEzBgHVoQAbXRPH3BONONUoq1vYawHsRkVyVT5YbmCtxm81X8y+N4ZxUb7z9Rm6YKswWP6KE8LsOyuo1BQcWqeyGYjuzNqat4Vagqa82o+Vig7MyiZhtBmztmmg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=NdjVnTZO; arc=none smtp.client-ip=91.218.175.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NdjVnTZO" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1775737624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U3oXadcBSvUPE7/YuHb+1ucWRDTMk1lo2RkRiHv3tFw=; b=NdjVnTZO0EcZ7FGk7OwErKClpXCrJ+wym/hO8gCDLMWoV5eueKOhD9JYuSZcti0C3TMPa2 tYcbVnxIvqwmPYNY0w6Z19y987FYCm7U21aBrjHqLwVfB2votxdRpFYhODsC3aXvi/AdIW xmK0fuLVE3OqXp07QzLjF3PkSbzS0sM= From: Lance Yang To: luizcap@redhat.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@kernel.org, baolin.wang@linux.alibaba.com, ryan.roberts@arm.com, akpm@linux-foundation.org, ljs@kernel.org, ziy@nvidia.com, Liam.Howlett@oracle.com, baohua@kernel.org, dev.jain@arm.com, npache@redhat.com, Lance Yang Subject: Re: [PATCH v3 02/10] mm: introduce pgtable_has_pmd_leaves() Date: Thu, 9 Apr 2026 20:26:54 +0800 Message-Id: <20260409122654.42622-1-lance.yang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT +Cc THP On Wed, Apr 08, 2026 at 04:22:57PM -0400, Luiz Capitulino wrote: >Currently, we have two helpers that check for PMD-sized pages but have >different names and slightly different semantics: > >- has_transparent_hugepage(): the name suggests it checks if THP is > enabled, but when CONFIG_TRANSPARENT_HUGEPAGE=y and the architecture > implements this helper, it actually checks if the CPU supports > PMD-sized pages > >- thp_disabled_by_hw(): the name suggests it checks if THP is disabled > by the hardware, but it just returns a cached value acquired with > has_transparent_hugepage(). This helper is used in fast paths > >This commit introduces a new helper called pgtable_has_pmd_leaves() >which is intended to replace both has_transparent_hugepage() and >thp_disabled_by_hw(). pgtable_has_pmd_leaves() has very clear semantics: >it returns true if the CPU supports PMD-sized pages and false otherwise. >It always returns a cached value, so it can be used in fast paths. Set once at boot and then read in hot paths, would a static key be a better fit there instead? Something like: DEFINE_STATIC_KEY_FALSE(arch_has_pmd_leaves_key); static inline bool pgtable_has_pmd_leaves(void) { return static_branch_unlikely(&arch_has_pmd_leaves_key); } void __init init_arch_has_pmd_leaves(void) { if (has_transparent_hugepage()) static_branch_enable(&arch_has_pmd_leaves_key); } Cheers, Lance