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 2386A391856 for ; Wed, 8 Apr 2026 20:38:03 +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=1775680685; cv=none; b=s63wjB/33JDxtFAwAGb9GJ/uBbnaXSESbv0bkB8pdaOQfl2tcc7Etj0Oah9GGeiMG2V8R+BXcsLX7DVAnFD4ZKmlnLqZx0zuNssQxqPzqvidkOEV+cuEQeYRQ8q5FgbDyEUME/8eQ4CIDsIk1M6t63DODt826ulkivCm4epSk7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775680685; c=relaxed/simple; bh=5GTuM8gmSLV+Sa0VYCr8bV0d10sDvQUE0KDytz84qyI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=B4XBnrrV8Gt1hw8EtP2po2JDzn5ct0hRSVwLqYO5GuBBY6roqrlxTBksoujCVWX+V8UgxZ4SXYx46FoCBnWXQhUzFdFyP3UqPIfyiyrtpD72VcZ5hFr6j6qgONLUPvApnJnN8Nnbk7ioibJmnH9GquXguuQOMOvfVlTpHhLy1Zo= 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=Fgb2OH9K; 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="Fgb2OH9K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775680683; 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=LjYnu4owpf/zaSuq0bbFHdaqsldn4LQ2NanTgIzt0b0=; b=Fgb2OH9KR46JDGSoZVh12KMZme7vHrIVlRhWaf4V0IDPqQ1P6kjjbPjW1XwkIomjnvrROR k/mvpi2F9M+/Xh3aDRucWJTmjr6IehbTMAq7dlcYcIWTmCk4yu+vQLgu3x9OmpBq5oiDo/ oiOnh+BmQt8csQ9/wvEjXvg0UPN0aR4= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-WpV9nXTnM1W4HhdFPyQ2Yw-1; Wed, 08 Apr 2026 16:38:01 -0400 X-MC-Unique: WpV9nXTnM1W4HhdFPyQ2Yw-1 X-Mimecast-MFC-AGG-ID: WpV9nXTnM1W4HhdFPyQ2Yw_1775680681 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-8d3a8df9a52so55375285a.1 for ; Wed, 08 Apr 2026 13:38:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775680681; x=1776285481; 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=LjYnu4owpf/zaSuq0bbFHdaqsldn4LQ2NanTgIzt0b0=; b=E6iv5hxjCDH2Uh8Qpjw5M5T8ze02Oi/zrFx9pvWLq7AMbWePLrY6DPHNF+TCBm0iKh ZQoz61xsWWOZHCq40nTGxRCSICzs57bjINiBdvexTVsAs/iFF5rL7O/zkJGmMbYee9DM j7DLVtr5rfP2rpUb2BnIONTvvOP2rrCksAI4B/0GenbzA2p74JC0x4p8cC9aT7s+0rui YGvlYwPMTY62EH8zbMpKQ2zn9iFdjF5I/v8abzWDcb0ygqApm1piHtjG71ElhFM9rz8G 2C8bf19oUAxsXpOhpCURggHp6GV4Byzbi0zc5NHIp0BkY7UjP78wAXYSXri0fen66hr7 x3hA== X-Forwarded-Encrypted: i=1; AJvYcCXB1xQdkW4UXGbIf/2zk+ZseJ6yur0LvsJztS/uHhMbkP2l6AK34JLnSUgCXlMcVjDOXLcWtzKjwosWzas=@vger.kernel.org X-Gm-Message-State: AOJu0Yzl+XwHoCqXMWLdsZpsJSAY3tsYXqTVUjYjMGg5r3q3Tzp5ygGY wM7DgEmRdV51pFMBtSjDUfwOQQx05hOrxehWHKoYQhBwRtNX2CQLmesYcif5KISNBhKWaIsKR0x 3XM+m1sL32JnBnL8z+/6EosqrEijxtOm2XnNPHfL7QZNZp18Ko0L6W6FR1ZT6lss5eg== X-Gm-Gg: AeBDieviZFvVJmH5xRJTTwKCGNKLd64G3PJCSoo+F/7+2eMmp0Am9Uxk/L1Fzbgv7Wi v5LMzbJ/EbGdD/TnkEj3A7xnFH8k4gkhdOqnrA0tNGPtyxYgXyF7n+MtAYY8ZXa2TMcmpoPfXM8 Cd3VbuSGlGqUWQrR59nB1nzRBqAB8vpkMviyHRyky2XZLf8GEVLXQ1dLG5ggcb57t2OlRbeD7Wi dE3J0CssD0SlikYdmOJ+cuzEJbVRq7sVqKzjh7GMSF0hOr6NrF0fcHO6awerZC2cwZzvzCQ9kwp h01SRD238rz2ALjSxqWV1l5dcgwD6CosLMnr8OwGqZvD9GEwnumWOgqznNQRBHOlwzEzKVKJCr1 ZDMvW9wROFuaDhssTq+iVllsydA== X-Received: by 2002:a05:620a:198f:b0:8cf:e0fe:f22f with SMTP id af79cd13be357-8dc3bbece88mr175182185a.18.1775680681162; Wed, 08 Apr 2026 13:38:01 -0700 (PDT) X-Received: by 2002:a05:620a:198f:b0:8cf:e0fe:f22f with SMTP id af79cd13be357-8dc3bbece88mr175178285a.18.1775680680629; Wed, 08 Apr 2026 13:38:00 -0700 (PDT) Received: from [192.168.2.110] ([69.159.169.238]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a8c29f00sm1562313885a.45.2026.04.08.13.38.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Apr 2026 13:38:00 -0700 (PDT) Message-ID: <0d9bfc3e-dad1-4856-9319-040135bed91b@redhat.com> Date: Wed, 8 Apr 2026 16:37: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 v2 10/11] mm: thp: always enable mTHP support To: Baolin Wang , linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@kernel.org Cc: ryan.roberts@arm.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com References: <29e8dfc2772af4b6e0db24134ca3563ec422b91a.1770675272.git.luizcap@redhat.com> Content-Language: en-US, en-CA From: Luiz Capitulino In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026-02-10 04:56, Baolin Wang wrote: > > > On 2/10/26 6:14 AM, Luiz Capitulino wrote: >> If PMD-sized pages are not supported on an architecture (ie. the >> arch implements arch_has_pmd_leaves() and it returns false) then the >> current code disables all THP, including mTHP. >> >> This commit fixes this by allowing mTHP to be always enabled for all >> archs. When PMD-sized pages are not supported, its sysfs entry won't be >> created and their mapping will be disallowed at page-fault time. >> >> Similarly, this commit implements the following changes for shmem: >> >> - In shmem_allowable_huge_orders(): drop the pgtable_has_pmd_leaves() >> check so that mTHP sizes are considered >> - In shmem_alloc_and_add_folio(): don't consider PMD and PUD orders >> when PMD-sized pages are not supported by the CPU >> >> Signed-off-by: Luiz Capitulino >> --- >> mm/huge_memory.c | 11 +++++++---- >> mm/shmem.c | 4 +++- >> 2 files changed, 10 insertions(+), 5 deletions(-) >> >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index 1e5ea2e47f79..882331592928 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -115,6 +115,9 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, >> else >> supported_orders = THP_ORDERS_ALL_FILE_DEFAULT; >> + if (!pgtable_has_pmd_leaves()) >> + supported_orders &= ~(BIT(PMD_ORDER) | BIT(PUD_ORDER)); >> + >> orders &= supported_orders; >> if (!orders) >> return 0; >> @@ -122,7 +125,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, >> if (!vma->vm_mm) /* vdso */ >> return 0; >> - if (!pgtable_has_pmd_leaves() || vma_thp_disabled(vma, vm_flags, forced_collapse)) >> + if (vma_thp_disabled(vma, vm_flags, forced_collapse)) >> return 0; >> /* khugepaged doesn't collapse DAX vma, but page fault is fine. */ >> @@ -806,6 +809,9 @@ static int __init hugepage_init_sysfs(struct kobject **hugepage_kobj) >> } >> orders = THP_ORDERS_ALL_ANON | THP_ORDERS_ALL_FILE_DEFAULT; >> + if (!pgtable_has_pmd_leaves()) >> + orders &= ~(BIT(PMD_ORDER) | BIT(PUD_ORDER)); > > I think you should also handle the 'huge_anon_orders_inherit' setting in this function if pgtable_has_pmd_leaves() returns false. Shmem as well. > > if (!anon_orders_configured) > huge_anon_orders_inherit = BIT(PMD_ORDER); I added the check you suggested in the other email for this in v3. One more item below. > >> + >> order = highest_order(orders); >> while (orders) { >> thpsize = thpsize_create(order, *hugepage_kobj); >> @@ -905,9 +911,6 @@ static int __init hugepage_init(void) >> int err; >> struct kobject *hugepage_kobj; >> - if (!pgtable_has_pmd_leaves()) >> - return -EINVAL; >> - >> /* >> * hugepages can't be allocated by the buddy allocator >> */ >> diff --git a/mm/shmem.c b/mm/shmem.c >> index 1c98e84667a4..cb325d1e2d1e 100644 >> --- a/mm/shmem.c >> +++ b/mm/shmem.c >> @@ -1827,7 +1827,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, >> vm_flags_t vm_flags = vma ? vma->vm_flags : 0; >> unsigned int global_orders; >> - if (!pgtable_has_pmd_leaves() || (vma && vma_thp_disabled(vma, vm_flags, shmem_huge_force))) >> + if (vma && vma_thp_disabled(vma, vm_flags, shmem_huge_force)) >> return 0; >> global_orders = shmem_huge_global_enabled(inode, index, write_end, >> @@ -1935,6 +1935,8 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, >> if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) >> orders = 0; >> + else if (!pgtable_has_pmd_leaves()) >> + orders &= ~(BIT(PMD_ORDER) | BIT(PUD_ORDER)); > > Moving this check into shmem_allowable_huge_orders() would be more appropriate. I kept this check for v3 because I found that it's consistent with the IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) check. If you feel strong about your suggestion, then I think we should move both checks to shmem_allowable_huge_orders() (which would require a small refactoring to shmem_allowable_huge_orders() so that we return the allowable orders from a single point). > >> if (orders > 0) { >> suitable_orders = shmem_suitable_orders(inode, vmf, >