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.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 6CC463E1220 for ; Wed, 6 May 2026 18:12:57 +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=1778091178; cv=none; b=YGtsJKrH4MxudsUO5J+HWFGuZxe1vifbu+Kg7DZA+iaq3JOtak/KlAj4QtlIHnVp+vV7ZByqGAtxlGY1ob2G54nJm7G5t6FtJt6Ip8YsV9cLG+YbZghpw3VT2/sjsTzuBQs5HwZ/Q9VdCH3lOCCpulAhBz7VeNllIdMnoZaRIcQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778091178; c=relaxed/simple; bh=9049y54VzhIDU/UVUtjXZhbb+MhGV3LVOLZsBITfGDU=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=TpWATk41S1GNdFxSEiMH36okzCMybQpfgBUQ7G/VNj8eq7kP09EBRsMbrbR4ASNKncJAqldP5gWbl9Cl1pKvNStDf+BZ3wG9IAdwIL84bzp0ns1CgRiV1azcHIufeep4mebDqGaJSPTvy0hdt+okjSZi5J6IEAVRfDeNH6RJSLE= 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=VGbCQhgf; 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="VGbCQhgf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778091176; 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=9bqKNq3m1Md+hrBs+SSGkueZdf4I+Fy2SNIbnUQ7AlE=; b=VGbCQhgfSX0TX46jIQYm3XrO3IbOf0ZpG5he0MZ65OsdpjtvtLzNpsXhDpSDa/8OJE/n9m 39DHsvwR8JtYv/mW/h8NaS8D8stD7NLgGC08o/Ss5Gz4++JU1Sp/YU1uQ5OLH1agxesfe8 972PtZQvIBIQB0BvZJNIBlDVu4KO/js= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-hB6ITQ6gPKKd0BpdMigRxw-1; Wed, 06 May 2026 14:12:53 -0400 X-MC-Unique: hB6ITQ6gPKKd0BpdMigRxw-1 X-Mimecast-MFC-AGG-ID: hB6ITQ6gPKKd0BpdMigRxw_1778091173 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-8b5f089a5c3so150494586d6.3 for ; Wed, 06 May 2026 11:12:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778091173; x=1778695973; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from: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=9bqKNq3m1Md+hrBs+SSGkueZdf4I+Fy2SNIbnUQ7AlE=; b=gYjFVYoSr2txkuGrrLRkOnIAsuR0QpO1C+9nTX6ckQuUXU+se6DlgxMs9LZEUCV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ac:b48f:9fa4 with SMTP id 6a1803df08f44-8bc447bcbf9mr68588776d6.35.1778091172852; Wed, 06 May 2026 11:12:52 -0700 (PDT) X-Received: by 2002:a05:6214:5908:b0:8ac:b48f:9fa4 with SMTP id 6a1803df08f44-8bc447bcbf9mr68587306d6.35.1778091171770; Wed, 06 May 2026 11:12:51 -0700 (PDT) Received: from [192.168.2.110] (bras-base-aylmpq0104w-grc-22-70-53-202-134.dsl.bell.ca. [70.53.202.134]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8b53ca982a1sm207894306d6.38.2026.05.06.11.12.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 May 2026 11:12:51 -0700 (PDT) Message-ID: Date: Wed, 6 May 2026 14:12:41 -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: (sashiko review) Re: [PATCH v4 6/9] mm: shmem: drop has_transparent_hugepage() usage From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@kernel.org, baolin.wang@linux.alibaba.com, ziy@nvidia.com, lance.yang@linux.dev Cc: 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: Content-Language: en-US, en-CA In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026-05-01 15:18, Luiz Capitulino wrote: > Shmem uses has_transparent_hugepage() in the following ways: > > - shmem_parse_one() and shmem_parse_huge(): Check if THP is built-in and > if the CPU supports PMD-sized pages > > - shmem_init(): Since the CONFIG_TRANSPARENT_HUGEPAGE guard is outside > the code block calling has_transparent_hugepage(), the > has_transparent_hugepage() call is exclusively checking if the CPU > supports PMD-sized pages > > While it's necessary to check if CONFIG_TRANSPARENT_HUGEPAGE is enabled > in all cases, shmem can determine mTHP size support at folio allocation > time. Therefore, drop has_transparent_hugepage() usage while keeping the > CONFIG_TRANSPARENT_HUGEPAGE checks. > > Reviewed-by: Baolin Wang > Reviewed-by: Lance Yang > Acked-by: Zi Yan > Signed-off-by: Luiz Capitulino > --- > mm/shmem.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/mm/shmem.c b/mm/shmem.c > index 3b5dc21b323c..1948d73fb1e3 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -689,7 +689,7 @@ static int shmem_parse_huge(const char *str) > else > return -EINVAL; > > - if (!has_transparent_hugepage() && > + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && > huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) > return -EINVAL; > > @@ -4656,8 +4656,7 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) > case Opt_huge: > ctx->huge = result.uint_32; > if (ctx->huge != SHMEM_HUGE_NEVER && > - !(IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && > - has_transparent_hugepage())) > + !IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) > goto unsupported_parameter; > ctx->seen |= SHMEM_SEEN_HUGE; > break; """ By dropping the has_transparent_hugepage() check, will mount -t tmpfs -o huge=always now succeed on hardware lacking PMD support? If so, since hugepage_init() still sets the TRANSPARENT_HUGEPAGE_UNSUPPORTED flag, thp_disabled_by_hw() will unconditionally block all large folio allocations in shmem_allowable_huge_orders(). Does this create an intermediate state where the mount silently succeeds but no huge pages of any size can actually be allocated? I see this is resolved later in the series by commit cd27430097e8 ("mm: replace thp_disabled_by_hw() with pgtable_has_pmd_leaves()") and commit 641a20ae032f ("mm: thp: always enable mTHP support"). """ The mount -t tmpfs -o huge=always succeeding on hardware without PMD support can happen in this patch, yes. But this seems very minor, the impact seems to be someone doing bisection, landing on this patch and their reproducer is depedent on mounting tmpfs with -o huge=always on hardware without PMD size support? I can fix it if others feel strong about this. > @@ -5449,7 +5448,7 @@ void __init shmem_init(void) > #endif > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > - if (has_transparent_hugepage() && shmem_huge > SHMEM_HUGE_DENY) > + if (shmem_huge > SHMEM_HUGE_DENY) > SHMEM_SB(shm_mnt->mnt_sb)->huge = shmem_huge; > else > shmem_huge = SHMEM_HUGE_NEVER; /* just in case it was patched */ """ Also, by allowing shmem_huge to be set to SHMEM_HUGE_ALWAYS on systems without PMD support, does this incorrectly affect shmem_getattr()? shmem_getattr() relies on shmem_huge_global_enabled(), which only checks the software configuration and not hardware PMD support. Consequently, shmem_getattr() will erroneously report stat->blksize = HPAGE_PMD_SIZE to userspace. Since subsequent patches in the series do not appear to update shmem_getattr(), could this misleading block size cause userspace tools to over-allocate IO buffers on hardware where PMD-sized pages are structurally impossible? """ This a real issue (albeit small one), the problem is this check in shmem_getattr(): if (shmem_huge_global_enabled(inode, 0, 0, false, NULL, 0)) stat->blksize = HPAGE_PMD_SIZE; So, we may report HPAGE_PMD_SIZE even when PMD size is not supported. Looks like we may over-report today as well for the SHMEM_HUGE_WITHIN_SIZE case? In any case, I'll fix this.