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 DB0D4C71133 for ; Wed, 11 Jun 2025 15:24:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D69F6B00A3; Wed, 11 Jun 2025 11:24:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AE7F6B00A5; Wed, 11 Jun 2025 11:24:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EBDB6B00A7; Wed, 11 Jun 2025 11:24:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1D1EA6B00A3 for ; Wed, 11 Jun 2025 11:24:49 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C675480F58 for ; Wed, 11 Jun 2025 15:24:48 +0000 (UTC) X-FDA: 83543492256.03.B3285E0 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf08.hostedemail.com (Postfix) with ESMTP id D0FEB160011 for ; Wed, 11 Jun 2025 15:24:46 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FjytjESA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of surenb@google.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749655486; a=rsa-sha256; cv=none; b=c8x3Bve2NE5FBN0LxDoKPNX5rIix7Wt80HMI1CbQENg0knIpPcx0ePVyZhrPgPt+XTpn+b Z4mkkVYYU4upktyEyILUXuv3iYvpi9pDAD/tldzytqlj7NVp29qRPN1W2y8Dka9mWWGqtP 7bxtGxPjEP2ULYlq0qXbNzvCU2zg9dw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FjytjESA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of surenb@google.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749655486; 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=vCaCBzkui1UDzyO3kyUbEuaCu0ZsnJ9BO/eNavHEABw=; b=X4B8UBCNvfaM0cEZhFvfdT/B3r6fCp/IWDYeWXyWg3gVT7RxqBCxBEJiJwTpjp9PiqT/AX 008vfIbMhNTP2ke7shDk+bHw1Fztg6C7hwOsb7F6zqcUx/2BY9efoWzAAEzoDltEwsOwlA NsXpg9sRUvVgQAIkDqCpCdR5IOMR5JI= Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-47e9fea29easo388601cf.1 for ; Wed, 11 Jun 2025 08:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749655486; x=1750260286; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vCaCBzkui1UDzyO3kyUbEuaCu0ZsnJ9BO/eNavHEABw=; b=FjytjESAa6sPBC2FCYhu53vd6ygGg8Cz63iHgC8Ohz6QK0JtgnkYacmrDORMDbO0cR l0qH6+adYsSM6WQGOWLuepHQ0lbhZy9ZCMqOKYWtF9FOoZuluYiZbXGiEj0VscgsoG58 HzESBQm5QS/zoXM9dofcBp5jRLkejanpnlvoJ3bgSYnOGfu/CkA0wiVO0TbjVJPY7Ydn gPaVDsxucBrwQJ61gaiWoVPt6lH2GXfekkFBRf8CWxZVsAa4wyLWcv7OLdgsnIWKp7ox GHFOCFDlFVa9/q5SnOTR4+tTAGsHZE0E9hTZ0ycAhujrgIgdESDyZlnKt9rzPBbBdAjX jbwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749655486; x=1750260286; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vCaCBzkui1UDzyO3kyUbEuaCu0ZsnJ9BO/eNavHEABw=; b=m5tmdj4DlVTTtVnoiQiBX2YAfaDkF/5VmwlvYKBQgB9CFpw/aT3NIsATx8CpepIH01 uXHRNOBvOgTMz41YM9aWwpVVSFr5www5ByNbio6zvc6oadj8gWHoFF/DX9v2CLuSlomp sbBpLP99vUFRW+Xrni8D1rFAPJ90TpLqbjcoxXJayTBB/OvJZJBigdPDz9d9luWB9Y5E s6/9v+ASnfgy+gFtr2D8IgK9Mp5SCRk28n261e+lpjKKJettSEiMD1TU7qVrxWt19n2N xS+GhvwuvEaEcn6YWwieUGaVw05EVWKZMZdF4I12TbYS/PnzaN4xvDhhXkuRUHf4N9Xl nlXg== X-Forwarded-Encrypted: i=1; AJvYcCUNfy1wT6UQNLPnG5OF3bWGng/jMIuLZTumINs3kPNaDtB0YwQ4LIbt8qInFEYStFOTzpkSNAlcdg==@kvack.org X-Gm-Message-State: AOJu0YzXeKApJ5dzY7e7mOvaDHnOcEEE43tAJZLsMvf6uwNEmzgoSvto W3HRBU428Up0cWVQr16WhB/90gfJ54cYc0gfTTWq09p32gKSvI4fmn8NmDiFZBJd3/88WFQaTgQ v65Jy6P3/iP77K2xr7FXFSfRPFfO1yzUPouDxshe7kbaNiZStAx+Zv6LM5RE= X-Gm-Gg: ASbGnct3QiOVpqXOdpVvGpjKVkaqu48Kvg3zyQZ7ObBKHboMZmmIPy+jjSVCYzEfT/1 rkDrtyEhY6ymvJzqHwaiPTx/nKglIbQdvD71h/2Oda9/dRuMiFQNvX6jpPuaKOifcsP/Le/hqri 4aY2NkkfV6mfGkqpwELBzrhtQOrsOO+eivy0Janznyr/qzCAP+03L0zE4WrvuebThCYqRN74Q8Y g== X-Google-Smtp-Source: AGHT+IGaALA5HOLF2Qc8q+0m2dcXfrcmFj7afCc+J9p/TZJhNBKTdOqSEIlLEe7fCAwa46Vm7qJA5ZayuJKteVEOWUI= X-Received: by 2002:ac8:59c6:0:b0:4a6:f525:e35a with SMTP id d75a77b69052e-4a71739dc8dmr3158121cf.9.1749655485134; Wed, 11 Jun 2025 08:24:45 -0700 (PDT) MIME-Version: 1.0 References: <20250529073537.563107-1-hao.ge@linux.dev> <177e1f6b-50f0-4c0a-bb0b-514283e009a2@linux.dev> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 11 Jun 2025 08:24:33 -0700 X-Gm-Features: AX0GCFthPV7_LeBFMNGhB_8jSOnMn-WFI9CR8rdaYFAYdBGzvtcRNw3_DpDvzmg Message-ID: Subject: Re: [PATCH] mm/alloc_tag: add the ARCH_NEEDS_WEAK_PER_CPU macro when statically defining the percpu variable alloc_tag_counters. To: Hao Ge Cc: Andrew Morton , Kent Overstreet , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Hao Ge Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam01 X-Stat-Signature: 1wkprhdii94rmgagqj4rjzchwmwf7h5k X-Rspamd-Queue-Id: D0FEB160011 X-Rspam-User: X-HE-Tag: 1749655486-671903 X-HE-Meta: U2FsdGVkX1+fUCB1WPNPB/pkbPM/4sqFNzt7OEr8lAYL+BhTZ0m5+wAodIrl2inPczJEFHZPJC58YC+pguokwzGnxsgR6sHdmcPtqyXKqt0NsZzdQ65tvll+gzly3xPrje8R51w7R9a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7A/ZRqT+Z+abxARe++YCg4gCKC8BilpYIgUwpG3Q3BGtH6O9H1rE8FBsWircfuX+d9SUel55RslBYNCid+BLMyyVyQH9RZMTjSpfRsl6cQ+Nx0aMQ16bRIoX0faw== 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 Tue, Jun 10, 2025 at 10:27=E2=80=AFPM Hao Ge wrote: > > > On 2025/6/10 00:39, Suren Baghdasaryan wrote: > > On Sun, Jun 8, 2025 at 11:08=E2=80=AFPM 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 statical= ly > >>> 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_DEFA= ULT, > >>> 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 wast= ed > >> in this segment. > >> > >> I realized that this modification was a mistake. It resulted in a buil= d > >> 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. D= o > >> 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/incl= ude/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 Hi Hao, > > 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? The problem is that ARCH_NEEDS_WEAK_PER_CPU is not a Kconfig option, it's just a definition, for s390 it's here: https://elixir.bootlin.com/linux/v6.15.1/source/arch/s390/include/asm/percp= u.h#L21 So, even for s390 if you are building core kernel code (not a module), ARCH_NEEDS_WEAK_PER_CPU will be undefined, however if you are building a module on s390 then it is defined. So, your change effectively results in _shared_alloc_tag being compiled out in the core kernel while it's used when you build a module. Therefore during linking modules can't link to that symbol in the core kernel. Hope this explains the issue. The way I would fix this is by making ARCH_NEEDS_WEAK_PER_CPU a Kconfig option and enable it for s390 and alpha, would replace old definitions from https://elixir.bootlin.com/linux/v6.15.1/source/arch/s390/include/asm/percp= u.h#L21 and https://elixir.bootlin.com/linux/v6.15.1/source/arch/alpha/include/asm/= percpu.h#L14 with: #if defined(MODULE) && defined(ARCH_NEEDS_WEAK_PER_CPU) #define MODULE_NEEDS_WEAK_PER_CPU #endif Then use MODULE_NEEDS_WEAK_PER_CPU instead of ARCH_NEEDS_WEAK_PER_CPU in all the current places in the kernel code. Lastly, to compile out _shared_alloc_tag your current patch should work fine because on s390 and alpha ARCH_NEEDS_WEAK_PER_CPU will be defined after all these changes. Does that make sense? > > Could you please help explain it again? > > Thanks > Best Regards > Hao > > >> > >> Thanks > >> > >> Best Regards > >> > >> Hao > >> > >> > >> > >>