From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A029C677C4 for ; Wed, 11 Jun 2025 05:27:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8A846B0092; Wed, 11 Jun 2025 01:27:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A62E26B0093; Wed, 11 Jun 2025 01:27:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 978A06B0095; Wed, 11 Jun 2025 01:27:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7993A6B0092 for ; Wed, 11 Jun 2025 01:27:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DD1B21A1CA3 for ; Wed, 11 Jun 2025 05:27:52 +0000 (UTC) X-FDA: 83541987984.01.E59EB6B Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) by imf11.hostedemail.com (Postfix) with ESMTP id D8D3B40009 for ; Wed, 11 Jun 2025 05:27:50 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=a9YMknsx; spf=pass (imf11.hostedemail.com: domain of hao.ge@linux.dev designates 91.218.175.171 as permitted sender) smtp.mailfrom=hao.ge@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749619671; h=from:from:sender: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:dkim-signature; bh=o/2aaI9Jc+UnnUYnd+8Q2hPmP+rI4bqFnbU4LUmieaM=; b=bWHyI3/p96pyPt4JvKFMA9kFrCt++EG8XS07vuCzCWXJCv+oCFEzA6Lf56lA+AFX28uH2n CwfG49QQybcpkx/di4uhyCeAs0pn65/zEuZw0uVM6YGcO1Mc8LwePW+JSP36Ao3gWOzqeo KcoM9AzOK1sbf52y/4aZFvEkpOMkKuw= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=a9YMknsx; spf=pass (imf11.hostedemail.com: domain of hao.ge@linux.dev designates 91.218.175.171 as permitted sender) smtp.mailfrom=hao.ge@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749619671; a=rsa-sha256; cv=none; b=SLObDyL5KOdTdcornebuhy/CbQR4XOyGw3nSH++7wa8fUU0F8S4GN6RjvssL6P2Rni+pyk sre7zDOBVUG/xp/CHMcL50yBH1YSuHK2ASGqzy3O3RXNIw43rj6CZ/LOu25qdnvU4MrlME C1I8O265XX35/8Ts6o2Hz0x/kHjERKM= Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1749619668; 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=o/2aaI9Jc+UnnUYnd+8Q2hPmP+rI4bqFnbU4LUmieaM=; b=a9YMknsxGDwTreHyjLWatAFWBw75aBIZM3CGgiYmylO5UHC/vTMRg2bcuNSh0JqBFBFaVA jVEgQE7Oea84sxvFdlirND2HsaaMOufVAeO3p1bx8RAmepeeuy96omvzhwhzxM94YL6Sf0 lndbskN5nteIuGXCNl9qG9CoFexvg3M= Date: Wed, 11 Jun 2025 13:26:52 +0800 MIME-Version: 1.0 Subject: Re: [PATCH] mm/alloc_tag: add the ARCH_NEEDS_WEAK_PER_CPU macro when statically defining the percpu variable alloc_tag_counters. To: Suren Baghdasaryan Cc: Andrew Morton , Kent Overstreet , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Hao Ge References: <20250529073537.563107-1-hao.ge@linux.dev> <177e1f6b-50f0-4c0a-bb0b-514283e009a2@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hao Ge In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D8D3B40009 X-Stat-Signature: jm5g3fi7ows4jtndmmw3rpbpakx8up4d X-Rspam-User: X-HE-Tag: 1749619670-903520 X-HE-Meta: U2FsdGVkX1/hPD7sev2vWmLZHZE/4qfc30kUrr3F2a8t907FNWmm7R1NROq5hydMC3hND7cZmoKhrmUOdMF3XfZv7eOnOciUszHuvErvCKMUV88Pdizgl/JwRNDwUVEuUzQpnj+WzKFjR4v5Q9KG3MJgy4Qf6oVEXjuW/KmTY26+2lMPSF5moyp+upSKulBWVGFucLrKC/zWEylI3Q7M3llRDCAyjb49Ps90RDplqSAECyl9EghhIycHxwV31PxXqEm0d1alWidzjw9Bs89uyRpsMJyLWMLk5vBzbgsP7srpyvBz1rdlmD8y0m9BKGh0b0ld/YQ32TzZNblNsIFGy0z7I9iRtNK99H71CYebn8+wSy5wSahPNyKkRkHyO2wX+ajU9AS4TuLM30BnutlmdTDjXbYFe3bkDApIl8y1LzstwCgAOQk6F5niFC+9RKvdVClAZxhrdPboGVAl/yr4smHCpgPH9Px0/IRHcPDd2eRNjWJiYDQJw6fzIN7fkt+H6E/hNXFk96DossbZsFSDinsqJ93zrMZC/xQMLrthQTzM3OucKPx6kKd3IRgMLpYpku9stKAEwkvHCVfY5CsaMLmULkFU80cCBL/f4OQFA88nHgrJZNWeJgRkLpzMYPl+xltuEN3J1U/mf7hJCEkiZA3znTjruLv5c9C9Ih6/LzdKf7xUSB2tGwnjDzJNCJChEvnr4OWvZIQwvZ02UXxOxknSDOUX0HaiFpGihQC9wqNewhf8F4vzSiGGKtPtR3oDuVhoPMI51NrLkbFmaXgjLG61vj5xfQiFXjIThTiZ4pnp0VQj8wMx4P66LdrRWWpq8qCLUx45aI2RYBiBeGKFSev92A+Ln6fkB2tX91aFSO15ol26WJpEsrVfHMNwBx85SYjRy/v1NgsBKMG2C6flPAimlvi/mTzzcfQL767GmgFRVcvydpVddHpLzOUYT2WiCSASxOfwoE5v8Y3/XbA rX1ytm0+ 5GWQn4LkXkCHW12O3l/HUVeOJxb7yPFF+6vzQKaW+M8wBYaOeKo7a/J76Fxuq3hWtB7HWWwEfUBfNlgPO1JSDq2IJnDR69JknRRf7uF8mlN5CirSrlR8yMpWYR7FPu3mnvbZmbMbK9/g7WDav9cZMEZ3tRQw9X82yMntVWmwbP5WgHN/IvGVOM/vOzqwbuaLZ1N5ZRkAhgM+NLb3RSo3fEF0Om8AgZRn5gj1DFs1M82Qx+YnXq9CsRva1cKAHfB9u83u5eWMJLmgOBusGIg8tQmcqX+Sa0hqZgbchWIGIxelX79RVcSVKEywvi5f50mjCbSVL4lH7ZgLkXd45yN/pLmJqL/+Csr8npl9QLqIwh6ZtCcCAgg1uPy2Dn1uU4j2E3sQK7QRgOvLaOnM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2025/6/10 00:39, Suren Baghdasaryan wrote: > On Sun, Jun 8, 2025 at 11:08 PM Hao Ge wrote: >> >> On 2025/5/29 15:35, Hao Ge wrote: >>> From: Hao Ge >>> >>> Recently discovered this entry while checking kallsyms on ARM64: >>> ffff800083e509c0 D _shared_alloc_tag >>> >>> If ARCH_NEEDS_WEAK_PER_CPU is not defined,there's no need to statically >>> define the percpu variable alloc_tag_counters. >>> >>> Therefore,add therelevant macro guards at the appropriate location. >>> >>> Fixes: 22d407b164ff ("lib: add allocation tagging support for memory allocation profiling") >>> Signed-off-by: Hao Ge >>> --- >>> lib/alloc_tag.c | 2 ++ >>> 1 file changed, 2 insertions(+) >>> >>> diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c >>> index c7f602fa7b23..d1dab80b70ad 100644 >>> --- a/lib/alloc_tag.c >>> +++ b/lib/alloc_tag.c >>> @@ -24,8 +24,10 @@ static bool mem_profiling_support; >>> >>> static struct codetag_type *alloc_tag_cttype; >>> >>> +#ifdef ARCH_NEEDS_WEAK_PER_CPU >>> DEFINE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag); >>> EXPORT_SYMBOL(_shared_alloc_tag); >>> +#endif /* ARCH_NEEDS_WEAK_PER_CPU */ >>> >>> DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT, >>> mem_alloc_profiling_key); >> Hi Suren >> >> >> I'm sorry to bother you. As mentioned in my commit message, >> >> in fact, on the ARM64 architecture, the _shared_alloc_tag percpu >> variable is not needed. >> >> In my understanding, it will create a copy for each CPU. >> >> The alloc_tag_counters variable will occupy 16 bytes, >> >> and as the number of CPUs increases, more and more memory will be wasted >> in this segment. >> >> I realized that this modification was a mistake. It resulted in a build >> error, and the link is as follows: >> >> https://lore.kernel.org/all/202506080448.KWN8arrX-lkp@intel.com/ >> >> After I studied the comments of DECLARE_PER_CPU_SECTION, I roughly >> understood why this is the case. >> >> But so far, I haven't come up with a good way to solve this problem. Do >> you have any suggestions? > Hi Hao, > The problem here is that ARCH_NEEDS_WEAK_PER_CPU is not a Kconfig > option, it gets defined only on 2 architectures and only when building > modules here https://elixir.bootlin.com/linux/v6.15.1/source/arch/alpha/include/asm/percpu.h#L14 > and here https://elixir.bootlin.com/linux/v6.15.1/source/arch/s390/include/asm/percpu.h#L21. > A nicer way to deal with that is to make if a Kconfig option which is > enabled only for alpha and s390 and then do something like this: > > #if defined(MODULE) && defined(ARCH_NEEDS_WEAK_PER_CPU) > #define MODULE_NEEDS_WEAK_PER_CPU > #endif > > and change all the usages of ARCH_NEEDS_WEAK_PER_CPU with > MODULE_NEEDS_WEAK_PER_CPU. > Did I explain the idea clearly? > Thanks, > Suren. > Hi Suren Thanks for your guidance. I understand this train of thought. I've been thinking about a problem: I only added the ARCH_NEEDS_WEAK_PER_CPU macro to isolate the definition of _shared_alloc_tag. Since s390 defines this macro, why did this build error occur? Could you please help explain it again? Thanks Best Regards Hao >> >> Thanks >> >> Best Regards >> >> Hao >> >> >> >>