Received: by 2002:a05:7208:3003:b0:81:def:69cd with SMTP id f3csp4244541rba; Tue, 2 Apr 2024 11:10:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWQW/iMyXNqDSUe3JurFaqJ7d6KHH0+3TFJ/6SanKxghBhPWIKZSMATT30KA9Nax4hB7gm6WaAip6FkSY/jBPn/7+kkAwiVqQMxjatG2w== X-Google-Smtp-Source: AGHT+IGHH+MDxC9pFRivGvCODVsVfk+7c7vMD1HX1Ir+utIhMaEjP1GkLERRqLPtWHntbBQgNirM X-Received: by 2002:a05:6830:d8:b0:6e6:94cc:d2d2 with SMTP id x24-20020a05683000d800b006e694ccd2d2mr393845oto.37.1712081416778; Tue, 02 Apr 2024 11:10:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712081416; cv=pass; d=google.com; s=arc-20160816; b=PkLPEB+mIc3ROV9N23b3VgDxMEl/y6FMzdXxddtrfNcJZFC+fMh4YwtNq+BEthXg7C GhMJAzlrZnRqzQd6FlzKsbG/1j/sCBlpDM9lwMj3PnJ4GEnStWc3XrkODN5bWKqKJTey 9Gruy+amj0fI7418ZWTfNAwWCu6WSipRr+Nc8Maqb00NlOsKIAKctqa+Cwk0DPhsi/fz 5Cbb1UlfwWHbYu3NSGd4vOG/oABwd3QD6zRlO/Z2TwaP5YqBuf0s/Qq2pf9KO8rRxCn3 VmKdlXIzJWeMgrTRGLFK2tgbDUNXcTQULIC1Y9zaDjHCW7K49m+kgtA8ryi17QlvRurp L3aw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=m7C4RwjluY6PPV2k/DozaBVNL1O8v9kM1LCRIQo+73s=; fh=bstx+bYa4kCAN0C5bV5qwd7avagLfo5J/NK0LzbOQPY=; b=V3BDtRsx2EGVkAkTk+2vd32CQC809BpiPrc0hjcrRH3SdchOGZmjNTOnEEHuJ1KR7i X6YtSBAyV57NWZA6jEsnt7+Tm2/TaR8GAPnJi2IfylZBHfOwm02JHkZpZz2kKDdL9a0P jooAcLxXg2yyk2YKQo1phYc1v444XlaE2b3gfN6D1bmurVqggyyiw5arqbuDMpUBE+lG P4nO8wBFI3rplCDvsWsmnIdTn2gUYV3KNHHeDvGB3/HjOaisWynzYV1HHAbW37LvFYDX xplKbpSJN/HWTZgcUtMQ47aRb3F5y93LqYmTO/XOyoDCyNz4mhP7rX1TJxTBVVfj6a3d W39g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Ypqi/Njw"; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-128488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t6-20020a056214118600b0069913b33142si2720743qvv.398.2024.04.02.11.10.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 11:10:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Ypqi/Njw"; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-128488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 725501C20A3A for ; Tue, 2 Apr 2024 18:10:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD0E915B0F1; Tue, 2 Apr 2024 18:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ypqi/Njw" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 7707F15ADAC for ; Tue, 2 Apr 2024 18:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712081384; cv=none; b=d1R9VVjNJUA++m22pb6aUMZOnbudg9wAuFbo5ftElrAzO+1JbcCxXww8c27goM89mY4DY5ctHhZz5V4gUeHIQiLr0+Uhm8vLGzDXB+f7O336VuYkRfNQ1KoCPw7YUh+jwrvIJI2fHAH5bG+zsEaXd2RBKSMabpSc0vCPxRcct/Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712081384; c=relaxed/simple; bh=IhhMTuUF4I1RrsCKiK+mrn7pbcjFVg70m8/FZRI+vXM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XxyPZagbRvdk7iIEZUUwADJnr3GI7sfTRWt6g+ieeLXenRI42LLJwk8fcehiuGHwMBTgUsGpM6cYRoP+n/JRY+mTuG1aodWyAwdTzB4W8ihiGUXOIxcwogIr8J7wpTfFEiPhZmIHEl5jp9c3WcPUWY/65l6VRXEWpveIkOExF2U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ypqi/Njw; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-610c23abd1fso100940577b3.0 for ; Tue, 02 Apr 2024 11:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712081381; x=1712686181; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=m7C4RwjluY6PPV2k/DozaBVNL1O8v9kM1LCRIQo+73s=; b=Ypqi/NjwUxBVLpk+2oHDSLAnOYty2CNV9YpeTpo5zFvhQ1qvHv2+Fsxxq2Xi+g/lLE zXpD/nzmSl4HlySBpiFmxzny1jNM3V0EkyXy+RfdDaHiwXIw1n9N0IEnVmpArqsYXaNh Qqtp23DKCBb2FqU64/bSJDo2RFcZ/GaHYGybXbyQmGwPDxNG777apBY4fg4tVaLqFjZp 7CwkCS05qZ1b1SDEgdm1wG8skNSmbwbB9BJZ0ZNJk3Uvi/ZxtTVKnkxI0KpmCfl3A8PE S4swpHl2Do78RttJo9shxfqdhCDETEtg9RJgGYgCuOLiPUMC/2KHKXFU7stYIEYoLP4E M6xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712081381; x=1712686181; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=m7C4RwjluY6PPV2k/DozaBVNL1O8v9kM1LCRIQo+73s=; b=F6UEs5tDcSy5lIfaRjWdGMchqbH9LoJ9eljaP83zuWKj7RGb6a2mrv8kricEdCh9NB 7NZGebUDjQOtAw9f5OD70soDGrio9UP05vjACAl5UfvDofsP3GHRzjCw4H1Nprx6S+6G B3P9Byk3ylm2+XhOCUz+SP6ShvyetAijQQRMnT3rTV4zS7ug1jc/ZvEWuLxoH0WylW2V 1DTVQL3ezGXR5uyfdSpqKtJM5jzHc4fNsmcByzf3cVIPEe76bnmWDJdFoRH7LpyXEx6Q C6CoqWh038s7UAtVesAlgZ/BJ6bqB6gty9PMEEiVOOStXYJnCadWkwjJ71JMMxgDDkpi hURg== X-Forwarded-Encrypted: i=1; AJvYcCVQUjOCEr70p1WUeuZFuN/66MnI1hoct7fJfVOWBNh8rOM+zEL/6NarM2ZwDcI7DrrOoiIhFSw6yggHNaoKg/BkiZLPPrcVKHF/H15t X-Gm-Message-State: AOJu0Yxw5So4+ANLeT8EJE883Ox0ulWIJKl0NTDvPZjjtT7CT09WWeq/ 8q47i1S76mD4ncshvqlDveUYbnebPmpg0C/oTfDq+CsCsUA2xi03fSKxdi7ZInoQ7K8OhMsUeoH Eow== X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:61fa:96f4:c395:2882]) (user=surenb job=sendgmr) by 2002:a05:6902:1613:b0:dc6:eea0:1578 with SMTP id bw19-20020a056902161300b00dc6eea01578mr4184874ybb.13.1712081381432; Tue, 02 Apr 2024 11:09:41 -0700 (PDT) Date: Tue, 2 Apr 2024 11:09:33 -0700 In-Reply-To: <20240402180933.1663992-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240402180933.1663992-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240402180933.1663992-2-surenb@google.com> Subject: [PATCH 1/1] lib: do limited memory accounting for modules with ARCH_NEEDS_WEAK_PER_CPU From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: sfr@canb.auug.org.au, kent.overstreet@linux.dev, surenb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel test robot Content-Type: text/plain; charset="UTF-8" ARCH_NEEDS_WEAK_PER_CPU does not allow percpu variable definitions inside a function, therefore memory allocation profiling can't use it. This definition is used only for modules, so we still can account core kernel allocations and for modules we can do limited allocation accounting by charging all of them to a single counter. This is not ideal but better than no accounting at all. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202403290334.USWrYrMw-lkp@intel.com/ Signed-off-by: Suren Baghdasaryan --- include/linux/alloc_tag.h | 14 ++++++++++++-- lib/alloc_tag.c | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 100ddf66eb8e..e867461585ff 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -68,9 +68,17 @@ static inline struct alloc_tag *ct_to_alloc_tag(struct codetag *ct) /* * When percpu variables are required to be defined as weak, static percpu * variables can't be used inside a function (see comments for DECLARE_PER_CPU_SECTION). + * Instead we will accound all module allocations to a single counter. */ -#error "Memory allocation profiling is incompatible with ARCH_NEEDS_WEAK_PER_CPU" -#endif +DECLARE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag); + +#define DEFINE_ALLOC_TAG(_alloc_tag) \ + static struct alloc_tag _alloc_tag __used __aligned(8) \ + __section("alloc_tags") = { \ + .ct = CODE_TAG_INIT, \ + .counters = &_shared_alloc_tag }; + +#else /* ARCH_NEEDS_WEAK_PER_CPU */ #define DEFINE_ALLOC_TAG(_alloc_tag) \ static DEFINE_PER_CPU(struct alloc_tag_counters, _alloc_tag_cntr); \ @@ -79,6 +87,8 @@ static inline struct alloc_tag *ct_to_alloc_tag(struct codetag *ct) .ct = CODE_TAG_INIT, \ .counters = &_alloc_tag_cntr }; +#endif /* ARCH_NEEDS_WEAK_PER_CPU */ + DECLARE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT, mem_alloc_profiling_key); diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index e24830c44783..b37e3430ed92 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -10,6 +10,9 @@ static struct codetag_type *alloc_tag_cttype; +DEFINE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag); +EXPORT_SYMBOL(_shared_alloc_tag); + DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT, mem_alloc_profiling_key); base-commit: d4cd6840d1dc25963aa10ef5e5b1d01876baebf2 -- 2.44.0.478.gd926399ef9-goog