From patchwork Tue Apr 2 18:09:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13614460 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 18320CD1292 for ; Tue, 2 Apr 2024 18:09:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C5C56B008C; Tue, 2 Apr 2024 14:09:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94E646B0092; Tue, 2 Apr 2024 14:09:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 816626B0093; Tue, 2 Apr 2024 14:09:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6152D6B008C for ; Tue, 2 Apr 2024 14:09:44 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2E18D1409BC for ; Tue, 2 Apr 2024 18:09:44 +0000 (UTC) X-FDA: 81965379888.25.A8E38EA Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 4B59240004 for ; Tue, 2 Apr 2024 18:09:42 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cZ0FQFD4; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 35UkMZgYKCOAUWTGPDIQQING.EQONKPWZ-OOMXCEM.QTI@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=35UkMZgYKCOAUWTGPDIQQING.EQONKPWZ-OOMXCEM.QTI@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712081382; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=m7C4RwjluY6PPV2k/DozaBVNL1O8v9kM1LCRIQo+73s=; b=MysT8s/e67UYzDQxQZcLRSCO6Y32S88Xw8xSF1/UPRbXJlFRUVB83tdT6Yv1C3KrIDdkFL wCxu6AwKxOMePGraBxPWgHXiFkxWkt4iVO50iTlNj/0GepcEtp5KtpWCpnRoHkt3CCCnIR c11igXkd8j0QNKMo9BoWL+0ZcgQ9iXk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cZ0FQFD4; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 35UkMZgYKCOAUWTGPDIQQING.EQONKPWZ-OOMXCEM.QTI@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=35UkMZgYKCOAUWTGPDIQQING.EQONKPWZ-OOMXCEM.QTI@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712081382; a=rsa-sha256; cv=none; b=kHAYYx4OaskEbeb1fkuAbHu/6Y0dZD6f3mf2uQTWn5yCyhtdpLQJLxNBr9DOBZo9WZK25I dlP5jtw75Yr8oWDe6W+PgT0CS+yfhtxauGage3eDNXv7A3Qe5WvV2YL0PIcNvPmPBhxhph dTJukEkRw7u3TZLWYP4TeYIuKkOAgp8= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a2386e932so100169997b3.1 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=kvack.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=cZ0FQFD4N29tqnUTTGhlOKY1o4yHWJaC8T4WnWCWTAhLZrIjLSgaP59gR3NSRcJmEh qQDSKFjbh/9mJ2KjuOvLgLmMK16ZHsqsxnAHiErsYwUHHQok2Ut7bteWeyDWtlmMgf8t TVu375ToKqXzT9fkEcTQ9OBxcgzEmCM3FLkupNJO3+3rJQWK0bsd+nMQgq+SVA3/Cgio fjsW60IU6W8+UMWIZIk48f3Zz3C7QKPvGU8Pxz8khH5F9uDlmr2XHYUGOtMMfNgJ2XT4 9xDE08MarxMYc6bWcYpLACpU2x6a005NnkGIEx1XPpLHxWCPZrcsLLkIy7gdmJnn33vu zuqQ== 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=uMAUm08EpmrxQ888t7mCQFNk0XaMgNLpiJIbzDeL/xpp6fTErXX47GV4+7BH/dsBl2 l/peRWPxnLmgFaWzknmEeEboWcwTouu8pyHMtN2WmfGPNjKdIAtAur2KC/YuB80eieq9 yykVONrYrSQJrdzcy+KqAfK+n92xHo+SHwanRct47mOlpZvljuLGq49Gba4Z/ChOLUKi QRRzSBauBbPbjNfMdln1lOMojC1ZY5BNq0Us5/346EuR4xzbhDaomhZ8sf4zG4jKL2hY VBmvRlpwQo4FmvGDjDqetwmFa9AfKDUXKP7/kKc0osaY2sj778PvDEXgBK4Mm1xZkWn4 bgHQ== X-Forwarded-Encrypted: i=1; AJvYcCXP4TkbLrBczA/F+FJ8pRMNkYu9/UbrGYjfQwUO/BWFdg1zeuqLv4PXMiSuFJ/4Y2JP31qyrYntDPP3h0fHveHPxM8= X-Gm-Message-State: AOJu0YxZ5FvgZhR87O9iEkV1bMLe3yM4YRhLoQVPOCqPaVYsbByquLwa 5ZmYLnPwD++9YqtVxO/lmEDAq+zLzKKBLijVQPp+BCRRo2zfVZdMrVh2ErX61d7F2+AnbGkUnZi iYQ== X-Google-Smtp-Source: AGHT+IH3Fmk0th3GoFLxNFXqVaLYsG7FFuYRdZ/faT2X8t4SOTXORLSLx8MolmKfz8ERrCJB0nZ+KvX3iNo= 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> 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 X-Rspamd-Queue-Id: 4B59240004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: asca1ndzmdoejz9ut6w4n87nc3o744ei X-HE-Tag: 1712081382-55011 X-HE-Meta: U2FsdGVkX18HI/lpBm3x2+6RULYuAwGQtIyHxPYQHtqochmRy9aOif80fs6WMdjuSSK6R4cyxJ3+KUp94JqOdOdkkcRC/B6q82Qd4pTQym0tDQnK/SUSGjeziNJwHemTMtfOvs9husxK5La/UjyCsgLwWIWIo/ICQHxHCWj7eX6kQ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9TLy4bPGT7Tg4hEsLbb5AG2O9RKfhHxZrmGMe6REc3yjbOdQcPxG6fbDXk9srJsV5TT9kwbd/JqMShoolHZ/bHTzPTNNLVDewLeGTCfIXPQkEGjui0qvy/0dY+KgdTY9k0JUFlwiP2R6FT0+kG8riKwE2cZmBvyLYpXnM37MCwfboX3l2RfX27vbfSY8VloPpU0JPV1ORY+G1amGWKWr5rYneLLqdrESDI+jJlIljoqJ+uV1+eNhG/Uwea+eF3aKI+AUbpmtxbvOyPLQg8vvzEpAybWACA+Qpku0HE1TARaCsaUGZyLbGOSTKfT7wiWIhDgCMgC1VyTE4mJmZUIRbGrgV/YjemcZyfRf6SBdwnbDyKppiWn/CBwdzUOVGwsjvQtPzmlk3h9sgb9PUiqHaq8Kb81OswcMUXvOaIe9p6tnHLhFh5fzT1lkSgI+Ef/Gp7HVdhVaOwu8/cOifTlPDueyAXf7yTzcDFkZa/dWF8aLaQ= 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: 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(-) base-commit: d4cd6840d1dc25963aa10ef5e5b1d01876baebf2 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);