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 551221AF0BB for ; Tue, 19 May 2026 13:14:50 +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=1779196491; cv=none; b=UyNdwNDBgyJv5NoB+UwqO7Seu9RPfWI5UevTdwgXuqQOZBvEfbRk1y30EGNGj/ID634Mxea65SkCPSHrVXx9pWAkz2G+OCeNBsInDT2LShbOUyofohE8JCr4FvVXSTB8hVLG/LvZTxD0KTfzmhafLGdT0KL9ADTyALEOfc0hZZs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779196491; c=relaxed/simple; bh=xLW/CsEPt0PuUENPEKKbCyh0lefEW9x+Itp8IyPSGwI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=cjkDwEGSy9x2AEk1Vf2nfirLM0RjBQ1Se6iwNsNplSRuD1mYQ+ftkIj9wqqWOSXJXOAXySds67nwYU33f3lp47pq0P37Jp9FbOK/15PSgYTwIQfnBB68fPIblwOCzoBKNqHP5/kFcSNq8F1JWDSwufHl4+9S9czvxDezI2QEO+w= 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=PWmih7kM; 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="PWmih7kM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779196489; 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=xYip3+Ws9lw4cpdgrl7SfSSzS0ynQwK4dAkAviqi5Tc=; b=PWmih7kM25FPZNK9rmUYkIFtwVHzYLTh5XihS0FjfiG1F9ShgSfJGzTb0l7dybx2Old2QE jZjk2LMDWRlYyFVKgJXjcwnFkQBtsdqKAVkLiQGRKqZ22aXFeGQvnC8b61/jARUwk3gXRO jIFrxzbJvB034Q7OBYMpRD30pXIRACo= 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-551-A0qi3Gp5NiK5ne9w4SEBzg-1; Tue, 19 May 2026 09:14:46 -0400 X-MC-Unique: A0qi3Gp5NiK5ne9w4SEBzg-1 X-Mimecast-MFC-AGG-ID: A0qi3Gp5NiK5ne9w4SEBzg_1779196486 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-913fcc4c164so704005285a.1 for ; Tue, 19 May 2026 06:14:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779196486; x=1779801286; 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=xYip3+Ws9lw4cpdgrl7SfSSzS0ynQwK4dAkAviqi5Tc=; b=HxkxQSFO5cwNEJuxfmsC2a9TyDP+iTzZhsMj61pQHrz1JBGs2bBmjGcic6O2jD3Icp q2pu3DAchaNfyoqbSLRl4UgV+tWXmtxBACz8wRlGy8UNovfB+WVkruCKSKVGfbh+CUxz IJgAUIcXbbDKjS+5Cnh1RzojLg0Qp7yU7+zhKtpd3n9Ywb42VgcrKjRcHge/OUtkVJx5 A4uY9ZLk8l7s0b7FQAr4Os4P5dxSZm0WJSfesrrvLFf4MeBxAE/3/fI2z9PjxhWbG7eX mr29MHgx+Uyk4UFFlw//h2tDBRTKC9RX2R2Beucz+4DJ5sLise1IB/zq1AqO/xHCuzzN KpGA== X-Gm-Message-State: AOJu0Yy9aUgQAfcO2v2zj842Rs7Zc0XIEHjexRNmjKQPr6WLXkxU0y56 rq474GusU9YE7AnTVkJP1xNrDr6noUtc67EPMlqrXvjlFN0kXw/tzF19azI6sS8sWEqbnL5aUiU uQYPaNwUJWgjcr/IJCRfsI53htSPep6lVjkQ2TXlRSzk9NL04cPOycYR/kIs7oPOlPE4atQ+Z12 0j X-Gm-Gg: Acq92OEJROFuSPtaY1SabvCMYiTfdLKoS7WO5Z6SKel99S1cfW0Ke1HH6X8lfhsQ8TX hx5LzmxSIOApa8U8ot5rK6R5j0eAmNOvciehP6PamCtjmHL8QqX0fxOB0Q1Bg/on4kYUtQ/iIvl sfmm0gClBa4P4/fVZvgWP6E0VquzUBGlIBbjj8jOOOqTESudWYXr521FpY4vl1ao4ZPM4rei91/ AR2agdKADWYqPrBo342dYC5aYF5lNjoD9MhSkv+H3Ha0BuyjnP6d44XGJwdeOPKQ1LftS3dpsx7 MSfkK0fv6wHc014/f96CZOFQCRlh7EnJT8LAdnMore/NE7pKf8SpsvMh71h7hVEvagH6W/m73/M Z+CX+b6EIT+EgmoLzwTPgPt/y X-Received: by 2002:ac8:7f8a:0:b0:515:189c:e0f8 with SMTP id d75a77b69052e-5165a04a50emr267406921cf.17.1779196485766; Tue, 19 May 2026 06:14:45 -0700 (PDT) X-Received: by 2002:ac8:7f8a:0:b0:515:189c:e0f8 with SMTP id d75a77b69052e-5165a04a50emr267406201cf.17.1779196484951; Tue, 19 May 2026 06:14:44 -0700 (PDT) Received: from [192.168.2.110] ([70.53.202.134]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-516456b6856sm163535441cf.7.2026.05.19.06.14.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 May 2026 06:14:44 -0700 (PDT) Message-ID: <3e300090-bc25-4ee1-a0f9-5e92d5200378@redhat.com> Date: Tue, 19 May 2026 09:14:33 -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 v4 2/9] mm: introduce pgtable_has_pmd_leaves() To: Lance Yang , david@kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, baolin.wang@linux.alibaba.com, ziy@nvidia.com, corbet@lwn.net, tsbogend@alpha.franken.de, maddy@linux.ibm.com, mpe@ellerman.id.au, agordeev@linux.ibm.com, gerald.schaefer@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, x86@kernel.org, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com References: <1f4bccaf-6472-4e4c-92d0-28ac05f6f838@redhat.com> <20260517124149.90033-1-lance.yang@linux.dev> Content-Language: en-US, en-CA From: Luiz Capitulino In-Reply-To: <20260517124149.90033-1-lance.yang@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026-05-17 08:41, Lance Yang wrote: > > On Wed, May 13, 2026 at 10:18:48PM -0400, Luiz Capitulino wrote: >> On 2026-05-13 11:36, David Hildenbrand (Arm) wrote: >>> On 5/1/26 21:18, 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. >>> >>> Oh, one more thing: what will be the semantics regarding >>> CONFIG_TRANSPARENT_HUGEPAGE? >>> >>> I assume it will only return true if CONFIG_TRANSPARENT_HUGEPAGE is enabled, >>> correct? >>> >>> That is, for example, relevant for patch #2. >>> >>> We could later change these semantics, but for now we should be very clear about >>> what it means. >> >> I intended to decouple the API from CONFIG_TRANSPARENT_HUGEPAGE,so my >> goal was to return true as long as PMD-sized pages are supported[*]. If >> arch_has_pmd_leaves() is not implemented by the arch, we default to >> CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE, not CONFIG_TRANSPARENT_HUGEPAGE. > > After patch #07, what still confuses me a bit is that the arch hoooks for > arch_has_pmd_leaves() still seems to be guarded by > CONFIG_TRANSPARENT_HUGEPAGE, not CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE .. > > For example, x86 only define arch_has_pmd_leaves() when > CONFIG_TRANSPARENT_HUGEPAGE=y, Same for s390 and mips, unless I missed > something. > > So is the intended meaning: > > "this arch can support PMD leaves" > > or > > "this CPU actually supports PMD leaves" > > ? > > If it's the second one, shouldn't the arch_has_pmd_leaves hooks move > out of the CONFIG_TRANSPARENT_HUGEPAGE guards as well? Yes, Sashiko caught this as well. I'll fix this for v5. >> Now, do you mean to say that the API should still be tied to >> CONFIG_TRANSPARENT_HUGEPAGE? If yes, why? >> >> * Sashiko found out that the current arch_has_pmd_leaves() >> implementation for x86 (and possibly the other archs) is guarded by >> CONFIG_TRANSPARENT_HUGEPAGE, so we may return true without the >> hardware check. But that's a bug > > Not sure whether that bug can actually happen ... > > But decoupling them looks cleaner to me :) > > CONFIG_TRANSPARENT_HUGEPAGE controls whether THP code is built, while > arch_has_pmd_leaves() is about PMD-leaf capability. Agreed.