From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FC7521A92F for ; Thu, 5 Feb 2026 05:53:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770270803; cv=none; b=PhhXdWB2SlP1ubHhp5hbSqyk0RjilzHsb9JOkH7sBMPgg8Y/YN9JAz3aGwP4T4fypZl+Skqdp0geq6/5RsTlFgLiLdlmZfnMskakKGJ/NIA2y8y+jxuDGr83CY9ZLigMWKHinZg3tpb0Fwk4/4Vfktzp6/oam7EPDgyFR+dEb60= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770270803; c=relaxed/simple; bh=q+416f561LdAeNhf6BcnGk4guHg2s/P+D/glVzFA5AU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EhWsCv2PxYgYmjdTyAl1JhlpP62IK4Go41WwUn6guwHi6/eyJyQSbnMVaHtIqk4H8OQaygqZyt5CXLOAMmLYL+oQ654gvDsHrGdGscZpGejztvnKd25O1VmFu5vOcRBuIwyxfCvrhq0ms6lHn05OSZnKndQ+fOHmvtsZKOurnx8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NDjClBC1; arc=none smtp.client-ip=74.125.82.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NDjClBC1" Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-2b71320f501so907482eec.1 for ; Wed, 04 Feb 2026 21:53:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770270803; x=1770875603; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=iZkQCAZc4aOUYGMOWyP4b/GxoSCdG2JdZhnubn5ATyM=; b=NDjClBC1sRrNNoO1rsw9Ezkuhjn+Z2zCwnBgfdF/2PEGs56Go5MuVYw9yWk55AIP9t RXVTREQXWwiIFyCnMzfL5N8n2XTNmnUOGlu47grM8cqau+sIhp8JWRaWFQ+/gWWWHU63 500R+fVvnlOEtIGRsyg3ZYJgYEZ5Vv0NUKsMlQPhQJyRyJTFwjKMgaj2ravqCCNIa3aO mKCtFVdsOR1cQdILxb9MaVGIWNahl+Do5Q6xDjcfuxoVEpafE2794RVWi3FhM4MKh5xH 8pZEiC9dB+9s40md8tULqi+M1nDucKoznbzeOL6jKUtq7rCBFKajMggNRpWvelBzTYri uI/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770270803; x=1770875603; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language: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=iZkQCAZc4aOUYGMOWyP4b/GxoSCdG2JdZhnubn5ATyM=; b=gZyDrtkoxBWf/kH2hvP4sRGdROeFo/M/rQlPmFkCT76t1g4r3GX/sm8b6/PKZSlMBG ZCnePGtip2eoINVooDRF2U3a9+gmWAIAvaWSe8ZFVK7X6Ys4GDnbylNkoyIOrDCJO2LI NNukrk9nyCbMw8FB7gV6LqowkqaPEK8orkK+9rJvDkJ+3vkL0tMZb7+RYvhdvQW9DZMv m9Cp0WvPFnUkEfrZRF9WPDbQjwPD1tpaU+2txaP/fuDTXfqgfW9IGIUbhFG4m9K1GGix 6mm5Vu5akU6WSodxMZ+UhAHW/2G19UlPnD61JSi/uVnaYo4nwGrOAzjHSXJDNGLlzjMf 1r7g== X-Forwarded-Encrypted: i=1; AJvYcCXUAPWEYMyP1QbpmUuBeTiF3M97bywmAwky+eFZrrY9ZRK6Ck7EhNsZo5+y0uUHT/D9u4tt1kUpKYysA+Y=@vger.kernel.org X-Gm-Message-State: AOJu0YyUCENu465wz7Z4w9oSmLACtxmhvi5EVwpiziy9Ov7mvSA2Vo86 rNk/5Xxc8+X9FXlAVqdF4XgknbCoaCO9ky8kgZJTbO08AOLXgqMhWbMO X-Gm-Gg: AZuq6aLIia4a5rA3km98hyzJKSB7qQlU+xqAhWUx2clOPHtZao0yTs26dMpJ7y4ZUc0 JuQjiBh4pKklezqF1cmap69gya1+AsK9UQdwHEUAIq69IqPJ2GDZoiysvLXE18vBoPbPIJ2kTRk Er/tNn5D/N3yOeX6pnQjk8ei0J0qmFfMCGRYSixb03TT6Z1SeZz/ElaPMQ7RKzYwdCr1bmvS0k6 skk6w2lSnt0TBLVCNrqGafOSEGGjrodiJbwmTZmoYYsP8C706pUJW8D0af4wFC56ET81yvInQ7t dtR2Nh1sF4RumrD5/5YPks/1FRPL9H7P/EU6qoVl50ri5n+Li/Zp7vVgqVNCRxybYhXNcBIkD1J W4pECeQQwxCMt79+9bisQbR8s7v6z+WVFVB1NFccb0Lcpx4lTV+iGuMyvws0vcSiWifWfkDJLjR ghAKYnNhWibmFX0DNG58MeSO2BtRUReywZZg== X-Received: by 2002:a05:7301:678a:b0:2a4:3593:646a with SMTP id 5a478bee46e88-2b832a56456mr2841583eec.26.1770270802562; Wed, 04 Feb 2026 21:53:22 -0800 (PST) Received: from [10.36.158.92] ([50.175.227.221]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b832e4c9c1sm2988962eec.10.2026.02.04.21.53.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Feb 2026 21:53:22 -0800 (PST) Message-ID: <0bd16d42-8f55-4965-ba21-9d7fa6ecbdd7@gmail.com> Date: Wed, 4 Feb 2026 21:53:21 -0800 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: [RFC 02/12] mm/thp: add mTHP stats infrastructure for PUD THP Content-Language: en-GB To: Lorenzo Stoakes Cc: ziy@nvidia.com, Andrew Morton , David Hildenbrand , linux-mm@kvack.org, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, kas@kernel.org, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, npache@redhat.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, vbabka@suse.cz, lance.yang@linux.dev, linux-kernel@vger.kernel.org, kernel-team@meta.com References: <20260202005451.774496-1-usamaarif642@gmail.com> <20260202005451.774496-3-usamaarif642@gmail.com> From: Usama Arif In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 02/02/2026 03:56, Lorenzo Stoakes wrote: > On Sun, Feb 01, 2026 at 04:50:19PM -0800, Usama Arif wrote: >> Extend the mTHP (multi-size THP) statistics infrastructure to support >> PUD-sized transparent huge pages. >> >> The mTHP framework tracks statistics for each supported THP size through >> per-order counters exposed via sysfs. To add PUD THP support, PUD_ORDER >> must be included in the set of tracked orders. >> >> With this change, PUD THP events (allocations, faults, splits, swaps) >> are tracked and exposed through the existing sysfs interface at >> /sys/kernel/mm/transparent_hugepage/hugepages-1048576kB/stats/. This >> provides visibility into PUD THP behavior for debugging and performance >> analysis. >> >> Signed-off-by: Usama Arif > > Yeah we really need to be basing this on mm-unstable once Nico's series is > landed. > > I think it's quite important as well for you to check that khugepaged mTHP works > with all of this. > >> --- >> include/linux/huge_mm.h | 42 +++++++++++++++++++++++++++++++++++++---- >> mm/huge_memory.c | 3 ++- >> 2 files changed, 40 insertions(+), 5 deletions(-) >> >> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h >> index e672e45bb9cc7..5509ba8555b6e 100644 >> --- a/include/linux/huge_mm.h >> +++ b/include/linux/huge_mm.h >> @@ -76,7 +76,13 @@ extern struct kobj_attribute thpsize_shmem_enabled_attr; >> * and including PMD_ORDER, except order-0 (which is not "huge") and order-1 >> * (which is a limitation of the THP implementation). >> */ >> -#define THP_ORDERS_ALL_ANON ((BIT(PMD_ORDER + 1) - 1) & ~(BIT(0) | BIT(1))) >> +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD >> +#define THP_ORDERS_ALL_ANON_PUD BIT(PUD_ORDER) >> +#else >> +#define THP_ORDERS_ALL_ANON_PUD 0 >> +#endif >> +#define THP_ORDERS_ALL_ANON (((BIT(PMD_ORDER + 1) - 1) & ~(BIT(0) | BIT(1))) | \ >> + THP_ORDERS_ALL_ANON_PUD) > > Err what is this change doing in a 'stats' change? This quietly updates > __thp_vma_allowable_orders() to also support PUD order for anon memory... Can we > put this in the right place? > Yeah I didnt place it in the right place. Thanks! >> >> /* >> * Mask of all large folio orders supported for file THP. Folios in a DAX >> @@ -146,18 +152,46 @@ enum mthp_stat_item { >> }; >> >> #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && defined(CONFIG_SYSFS) >> + >> +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD > > By the way I'm not a fan of us treating an 'arch has' as a 'will use'. > >> +#define MTHP_STAT_COUNT (PMD_ORDER + 2) > > Yeah I hate this. This is just 'one more thing to remember'. > >> +#define MTHP_STAT_PUD_INDEX (PMD_ORDER + 1) /* PUD uses last index */ >> +#else >> +#define MTHP_STAT_COUNT (PMD_ORDER + 1) >> +#endif >> + >> struct mthp_stat { >> - unsigned long stats[ilog2(MAX_PTRS_PER_PTE) + 1][__MTHP_STAT_COUNT]; >> + unsigned long stats[MTHP_STAT_COUNT][__MTHP_STAT_COUNT]; >> }; >> >> DECLARE_PER_CPU(struct mthp_stat, mthp_stats); >> >> +static inline int mthp_stat_order_to_index(int order) >> +{ >> +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD >> + if (order == PUD_ORDER) >> + return MTHP_STAT_PUD_INDEX; > > This seems like a hack again. > >> +#endif >> + return order; >> +} >> + >> static inline void mod_mthp_stat(int order, enum mthp_stat_item item, int delta) >> { >> - if (order <= 0 || order > PMD_ORDER) >> + int index; >> + >> + if (order <= 0) >> + return; >> + >> +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD >> + if (order != PUD_ORDER && order > PMD_ORDER) >> return; >> +#else >> + if (order > PMD_ORDER) >> + return; >> +#endif > > Or we could actually define a max order... except now the hack contorts this > code. > > Is it really that bad to just take up memory for the order between PMD_ORDER and > PUD_ORDER? ~72 bytes * cores and we avoid having to do this silly dance. So up until a few hours before I sent the series. What you are saying is exactly what I was doing, i.e. allocating up until PUD order. Its not a lot of memory wastage, but it is there, and I saw this patch as an easy solution to it. For a server with 512 cores, this is 36KB. Its not a lot because a server with 512 cores will also have several 100GBs or TBs of memory. I know its not elegant, but I do like the approach in this patch more. If there is a very strong preference to switch to having all order to PUD as it would the make the code more elegant, than I can switch to it. > >> >> - this_cpu_add(mthp_stats.stats[order][item], delta); >> + index = mthp_stat_order_to_index(order); >> + this_cpu_add(mthp_stats.stats[index][item], delta); >> } >> >> static inline void count_mthp_stat(int order, enum mthp_stat_item item) >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index 3128b3beedb0a..d033624d7e1f2 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -598,11 +598,12 @@ static unsigned long sum_mthp_stat(int order, enum mthp_stat_item item) >> { >> unsigned long sum = 0; >> int cpu; >> + int index = mthp_stat_order_to_index(order); >> >> for_each_possible_cpu(cpu) { >> struct mthp_stat *this = &per_cpu(mthp_stats, cpu); >> >> - sum += this->stats[order][item]; >> + sum += this->stats[index][item]; >> } >> >> return sum; >> -- >> 2.47.3 >>