From mboxrd@z Thu Jan 1 00:00:00 1970 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 BC3691A6829 for ; Thu, 9 Apr 2026 18:23:06 +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=1775758988; cv=none; b=haLFzyQMBnsYXK8icm0rh9q9399mxGlALEhNffNiGJa3Uk7xmARHUo+TW0qDroBUBGVFoyg6U+DbxAcYhNuCjCBb6LjEF57aY7f+i9PlA31yah2dPBuX5FGYo5hiHWipObgqU4B+j9enSJXrKzpQ3eVjP89UX1fjth9Q6YRy/Gc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775758988; c=relaxed/simple; bh=JiDK8eAFj9k7lvB5UkUh1375qbExzI1J1CHrg9bDuxI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dMwk2ABQdWKhH0PVnj0ll0sZsl3QRD6r9RVIN5jZB07LkIRcG3m2pfgi9KwXI2LwVseUm392CvFsI6pCREJ7+X0T3Vdqdgv6O3M02ovxMSHFU+u+5i+CmKu5zLcTfQuGArzp43PmYUCAYPTZcbQoK4FPC6mrumfHHG1rYPmV/M0= 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=IDfnOATZ; 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="IDfnOATZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775758985; 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=tp1d8ZS+UHvbq4+BjkPrR72AeyAn3NvEQozPe2yXurA=; b=IDfnOATZ4ygI5Yh+gaAvzia9plFqUPqXKwif8U+qQ/H6eyXQzYbXf78RNcTW/DaDIxz/mi LskknNIdrtZ1aX1xjlbl8VQ+9stmlrexXYzpXyFT9c4m/zlTEiGcAm/qaGs2m+Ioyz9c4u cwTV9m1Oj670dcM2w6kQ0wO9TWIpCXs= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-pmyBq3-COR-l14hFDKO1Fw-1; Thu, 09 Apr 2026 14:23:02 -0400 X-MC-Unique: pmyBq3-COR-l14hFDKO1Fw-1 X-Mimecast-MFC-AGG-ID: pmyBq3-COR-l14hFDKO1Fw_1775758982 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8d65190e52fso214609785a.1 for ; Thu, 09 Apr 2026 11:23:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775758982; x=1776363782; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tp1d8ZS+UHvbq4+BjkPrR72AeyAn3NvEQozPe2yXurA=; b=YuwtfmfDpf8/YCe62ocjRoInZJ6Xp1cj0rNL/FcSXH6FcLPx5VeCaAkZ6E/6SstDvo eqf2yZ6vhUA5SEyHjYIiq5qCPMqF/hO78MmNXcOlI06VpfP3gerLuYlASN9Jk1mf1XbH /X6xAdg4Q/8DRagCBlNTptk6g68lj7lgHSIpHZ9Xxdio/PKFP0IcdNv8rapfbE++Rsfe n0iGyxWpl7jYK9U5DzKDbzd2KTq5zkpduwDbfHghva6jVJPcDQhzTnV4sqs/UcOvOvjy yNcbb68KWAV9t4OiYot3cjtJ9IV+pdBdAw1VvzA17maQXb8ZT4qexIf81GmRoCTOlJOT daHg== X-Gm-Message-State: AOJu0YzR+j05WLhWzMTRfdWyz0rVxvNT0m+h1ndEtPju8YFeziaC+YXu WYwmJsrAZh53PoO50nz+Rjor25p9eI2aRHf6CssUnrdSpKbV5mMVlTKri8G0XH0Sdns4RjHTbpI nrheNZy/6o1yCoPdYXeGpdfFLbqwXdi7dgtd37LybDZpUMiIZT9TzmW7FdzOpOUKZyw== X-Gm-Gg: AeBDietsecMPqBdzyVRvkxkOrU+MTsZGRGYVpHN/xHJ/mFRkdAsrhhw0hCQh71FeXCx z99IyCGYE9OInIGLVnn2D1cclAmvrQWeU3aYeCpMwLpJVCA9Xt/a9rQxX+u70l3G1yCBFqBI9cp aVx68lbio88n0LhmpsdSrrXjmBsyyMSWZROyVdzFpFnbDL1DcfjejKb+k4DfzsUMaENDmVZNrQ/ dP34XL9vPX9NL8VnTZ48uAlcd++d4wLkinu27QdIO0RP9mD8AZdJDPadYKZ3U8p9kZnTNpMZ1U4 ycrMgBc4aP8CbKcBnJuQfB/IkC0CUY2AoPONmijVUL6e9RKF2HO4kE9yg4y3ZY83+9QNFEjJl8v ZAfHwddVw9X0Wrt6gYfakNLpBmQ== X-Received: by 2002:a05:620a:2908:b0:8cf:d62a:c814 with SMTP id af79cd13be357-8d41c2be534mr3849126385a.19.1775758981864; Thu, 09 Apr 2026 11:23:01 -0700 (PDT) X-Received: by 2002:a05:620a:2908:b0:8cf:d62a:c814 with SMTP id af79cd13be357-8d41c2be534mr3849120585a.19.1775758981349; Thu, 09 Apr 2026 11:23:01 -0700 (PDT) Received: from [192.168.2.110] ([69.159.169.238]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8ddb8d6bf40sm12146785a.29.2026.04.09.11.23.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Apr 2026 11:23:01 -0700 (PDT) Message-ID: <0f354976-854f-431d-a10b-0910fe6831b6@redhat.com> Date: Thu, 9 Apr 2026 14:22:49 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 02/10] mm: introduce pgtable_has_pmd_leaves() To: Lance Yang 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 References: <20260409122654.42622-1-lance.yang@linux.dev> Content-Language: en-US, en-CA From: Luiz Capitulino In-Reply-To: <20260409122654.42622-1-lance.yang@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026-04-09 08:26, Lance Yang wrote: > +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: This looks like a good suggestion, if nobody opposes I can do this for v4 (although it may delay inclusion a bit). > > 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 >