From patchwork Thu Dec 26 21:16:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13921428 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 24132E77188 for ; Thu, 26 Dec 2024 21:16:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 322BB6B0082; Thu, 26 Dec 2024 16:16:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D2E96B0083; Thu, 26 Dec 2024 16:16:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E9576B0085; Thu, 26 Dec 2024 16:16:46 -0500 (EST) 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 016566B0082 for ; Thu, 26 Dec 2024 16:16:45 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5E527141A4C for ; Thu, 26 Dec 2024 21:16:45 +0000 (UTC) X-FDA: 82938368226.23.447E6D5 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf04.hostedemail.com (Postfix) with ESMTP id D999340011 for ; Thu, 26 Dec 2024 21:15:59 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="sC1gHEY/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3usdtZwYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3usdtZwYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735247784; 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: references:dkim-signature; bh=Q6FNZCc0sjlAu9/bhUu0wi3B3hcHiZVxRsWdZ9fDpqQ=; b=RTyArMEbiZDfUkfPfbimh0dK794CVnOhpUlU7khd9WVxvZX93WFrWNumRq/Nc0j3hQgUvj b0Q6jfkLflWGWNW4P6zL6jkQpP1N6rA9BIvfLuzSvYLf2BrfDRRuJKLU6Eu693NUk+rClb naEx5DnHFQFBn5nxhbqCfUgq1tqVAuU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735247784; a=rsa-sha256; cv=none; b=3ZUVrPm9R+jd74wbRmDIfA7JHowMkc6dlrZPfWQiAJdgmnjWw/8UBaxDag7sXS1BwJmhSF AW3nLIm9TTczFdTupNz0j1pv2j/NVs93Y3IR4bb4q9RY4U5enRA7nA8SFGJld/IJyrmGCI KVZB3q/tyrm8+QA7ZvXsEATGKT61buE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="sC1gHEY/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3usdtZwYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3usdtZwYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2165433e229so83878705ad.1 for ; Thu, 26 Dec 2024 13:16:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1735247802; x=1735852602; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Q6FNZCc0sjlAu9/bhUu0wi3B3hcHiZVxRsWdZ9fDpqQ=; b=sC1gHEY/1NMmw2n4xkTzKboWAmh+nu/NcdVnI743lOo8BrMVzwIzWhrfFTZW3AVCP7 YQ4rmKSCMrvf0R1HjjUyQbgMbuEZpDSToiZAkfUYQ/3XH7ZE4F958r+UGppfSmzAiPxg 1Faumm4hd2T+gH7VaMwxt6DbKZmTLHxNqua1wmnJ/qQIrLcwj/IW0hB9HgCrvvqYqRpV msh7zXRVSRn54uKloxQp90UZe6JnXbILCYUxlNVoSRrpfoTGwFkDN4nu+oLE/OOobXN+ DUrXmCTRCsuLLDeu3oKvleVbw1+SpVc7wrBHSSSX4+qh+EDraIlBaqApOpn9Kt7cWvUZ D8Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735247802; x=1735852602; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Q6FNZCc0sjlAu9/bhUu0wi3B3hcHiZVxRsWdZ9fDpqQ=; b=hOV4MCjWZH2yayZ5QSTrIBmYJXSQERd/m0ZNLN06IgMjR3zRtnseSvZ4Ln2jVv3VD0 2mgtGa8hClrpAKkCR/KiI4GIBY9OydqatvB4MlMt9sEU5GD3Dr078I/LgMTxos3ywqSs R8zyao7QRnyol5sOP93scSETGXiITo5HDdQOohw1a5ovjwQbtj+hUH9HpABSPJeyMJ6X MvvT1v2S28DtFy4qkf05Z4sSypMpD/2z+SsDSGN2luWZ6z1KEy7cRNiKECt6cqxybQ52 0mpf/WCI79LYpPfcD903n4cpSMEF2bgQop7K2Ee9LnTYuet2tsGj3+vpQ7nnPzG5fIXu m78A== X-Forwarded-Encrypted: i=1; AJvYcCVF6f5i0Q2NLAPeCQkj99qLVZyD1yLGyFY7usVtZGfWVwOuhyj96+94l7Jd0MZUijmoCpSdoR1piQ==@kvack.org X-Gm-Message-State: AOJu0YyGRKhaK54RnooSbLN/YSZEgZNFIAuN+oIb0kdh2+QZgGKq0yxy RXkVsbCBO/DcfYeHAQwZLoQcEEmdAqVULioQDkgucVo8SRF62A+QOqWBvIMqoQlB9Dwbq6B3J/x iRA== X-Google-Smtp-Source: AGHT+IGsluvjCQPIRlC11GbC/0U5YyE5MLWsBDKc3jJjY6kkkDpn4HpS6bMUSx/UCZvtrYHO7zXLvRubfMA= X-Received: from plly7.prod.google.com ([2002:a17:902:7c87:b0:219:21b2:3071]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d4cf:b0:216:2426:767f with SMTP id d9443c01a7336-219e6f25d6bmr291166905ad.49.1735247802375; Thu, 26 Dec 2024 13:16:42 -0800 (PST) Date: Thu, 26 Dec 2024 13:16:38 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241226211639.1357704-1-surenb@google.com> Subject: [PATCH 1/2] alloc_tag: avoid current->alloc_tag manipulations when profiling is disabled From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, yuzhao@google.com, 00107082@163.com, quic_zhenhuah@quicinc.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Suren Baghdasaryan , stable@vger.kernel.org X-Stat-Signature: itzhd5ydzfgfiow1asp84mcz7qaxsxi4 X-Rspamd-Queue-Id: D999340011 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1735247759-353169 X-HE-Meta: U2FsdGVkX1+lcIiD78ROgtflsPuV165Ddk8itrevJUDXHJc5pKKscGpRtTgpv/QGdSec+BY6rLQdChJSQQPXJgwYaRKaPYcdrsMgOotp71/XR2sE6oqen2bWNFzqxjIjde1Tsls6hYxyW5udXTLhdlxlGGhTTr8x/BS53G+4IAJrWlMJPSSzeiMO/Ri8on8zTcT1qs7bdUZQ/7bs3wKbXFqze82nsorXHqpzOdYFRIeNffKM3L3EK0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Al1BA+D5CZQKNXoDdePb/6GHkAwAkISy6/ZUMn/WqoJRRiwm09qWLhtvinhUIq2ASXzp7e3tnRwbkd/N2XzBkw6E3mP97N5OcfaTWICb8PnUwnOCAPUtSDIJu3wipL+nMZdCXkGDHM3axs0KG7Gbj7+TEex2owv44k4lu3dyrLwDovpIffaiVvTAoLyhkHr61Q7DzJ3KaecvxGK47xABwQfSMSCHsd7c7J1MzWeoFKXP95YvEmIWc2oFhJVqlud61GS/nz9aJ3xp9Br1AFyUU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000535, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When memory allocation profiling is disabled there is no need to update current->alloc_tag and these manipulations add unnecessary overhead. Fix the overhead by skipping these extra updates. Fixes: b951aaff5035 ("mm: enable page allocation tagging") Signed-off-by: Suren Baghdasaryan Cc: stable@vger.kernel.org --- include/linux/alloc_tag.h | 11 ++++++++--- lib/alloc_tag.c | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) base-commit: 431614f1580a03c1a653340c55ea76bd12a9403f diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 0bbbe537c5f9..a946e0203e6d 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -224,9 +224,14 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) {} #define alloc_hooks_tag(_tag, _do_alloc) \ ({ \ - struct alloc_tag * __maybe_unused _old = alloc_tag_save(_tag); \ - typeof(_do_alloc) _res = _do_alloc; \ - alloc_tag_restore(_tag, _old); \ + typeof(_do_alloc) _res; \ + if (mem_alloc_profiling_enabled()) { \ + struct alloc_tag * __maybe_unused _old; \ + _old = alloc_tag_save(_tag); \ + _res = _do_alloc; \ + alloc_tag_restore(_tag, _old); \ + } else \ + _res = _do_alloc; \ _res; \ }) diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 7dcebf118a3e..4c373f444eb1 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -29,6 +29,8 @@ EXPORT_SYMBOL(_shared_alloc_tag); DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT, mem_alloc_profiling_key); +EXPORT_SYMBOL(mem_alloc_profiling_key); + DEFINE_STATIC_KEY_FALSE(mem_profiling_compressed); struct alloc_tag_kernel_section kernel_tags = { NULL, 0 };