From patchwork Thu Mar 21 16:36:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13599172 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 AD99AC54E58 for ; Thu, 21 Mar 2024 16:37:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2673D6B00A7; Thu, 21 Mar 2024 12:37:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1ED3B6B00A9; Thu, 21 Mar 2024 12:37:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F35456B00AA; Thu, 21 Mar 2024 12:37:45 -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 D59C36B00A7 for ; Thu, 21 Mar 2024 12:37:45 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B1A2D1C0466 for ; Thu, 21 Mar 2024 16:37:45 +0000 (UTC) X-FDA: 81921602490.13.663AC14 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf22.hostedemail.com (Postfix) with ESMTP id DBEF7C0006 for ; Thu, 21 Mar 2024 16:37:43 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=r1hRGjvb; spf=pass (imf22.hostedemail.com: domain of 3VmL8ZQYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3VmL8ZQYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711039063; 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=BfPuXrQNw6sP43MOvy7juBQZEF5XCZI3rVOwMSUBcyU=; b=JfAFl3PQ+kSR9rAERiTRl3Xp/luy6JkmxcVdpmP7NIYlwjg/LcOVGbPEzuncyLvIu/cpCq 0flyqowmOPwxGMPRFlhW5OLsEbpHdu6gGpL4xUa9Gm0DdNzTTBGUw67ZSi6aPLkrcZMrFf tpPDljV6TQAkQlDe042xOdxaHxtxCk4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=r1hRGjvb; spf=pass (imf22.hostedemail.com: domain of 3VmL8ZQYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3VmL8ZQYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711039063; a=rsa-sha256; cv=none; b=yN35pch657ldKZioV4Ywz1gJ1ARPfCQ+9VuzS+vM1FFf3WpAK5MD15DrGPzhQU+3NKGk63 Y6jduU3gd3ZzS7qNyiwlwCDe7iDLSlE7+02YTxYqTKBVpILWzmfvXxA/o9kxS5Z1p2EfJ7 bNvCwQjlmFGMuK4mL/pivoTtu7qw458= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a0a5bf550so21840857b3.3 for ; Thu, 21 Mar 2024 09:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711039063; x=1711643863; 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=BfPuXrQNw6sP43MOvy7juBQZEF5XCZI3rVOwMSUBcyU=; b=r1hRGjvb71DQPdhxjE51t8lb483KqLPiH17qSU5di5QtoFwXiIw0OrpbqTqkFnujG4 9IY07H4zZlhj6M5kFpRxAH7pR9QG21+Th1NtvdKZf+fXHXg0tBZpTcL2VauuOUlam7di 7htj+dkAGpKLyD2eZ/CUcTcsEEX2h5mKD/H6VJmrtG3wvkNsxEPkvHgpnyoBRTgTBtZh Sf+ltVtCKLwwBHF8YwXy8dGgPup4Lpc4jLNxW35m28S5nTnIR+qagzaqL/hMCDelc3rs hWQXX+/KcvH95If7k7qoWxt3M1LUECp2CWXbRFVXwEAUY9MrFkCJp47dKNPBtMHQZEZL MPbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711039063; x=1711643863; 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=BfPuXrQNw6sP43MOvy7juBQZEF5XCZI3rVOwMSUBcyU=; b=XOoett28MCPw8ZZmtPJOFrY3DWIvJSkPSgooU+GQwXPHNoaL70GmVK6PvjbvmkMN+W 7Y01DDjyoY69Fh9fRjbrWuJ3s7SoH4S6oIBvOkpFyqHFP8JruJ8ONzyyV3vNp9TV/JBv 4s0FxQyKBdZ/qteyxOw5vHVPmGCuH+Y4nSjX446rc+Yyev/nkPcYtSwiPeGCilNRaiyY NneMvrfYvrtw2Qm1TEAItw4wDs+ogiJp2RWP4WJryIlkE/UedJ6TUwGbByglEHtyc+XR Wb5eIMvTOMXL81XgGndO2r3fP4cH+dj1JntXwfHeUl2ZA/DllTXq7KIg27QWaB+54KF1 4l8A== X-Forwarded-Encrypted: i=1; AJvYcCX3Fqw/PAZCrXtBE/oyp3SygJgX4EBNB8TQXXI+nBaqc+qA8HsYI/TtrRyHQw4OqQf5OPWsnk5CO2UgjnwIuRohYTY= X-Gm-Message-State: AOJu0YxOeHgaPLXZpYzTNikDNMRxcu7r1B6vkYmVi48AtOh9tAYYE/d4 3tM85NCg7dtnK4u86SDyIpQOWQFAZfNZgJpKoTFiUZeZNDitZwj6OXtL1H3hBITeS/WrFTTsOlW vHw== X-Google-Smtp-Source: AGHT+IF0jEtLINTH4On1VBGvIr2Jc0SGzS38YLdjNwaqc8VhKxt4NeXt5PC/R2alQ3iBswciTecJTdFY/QM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:a489:6433:be5d:e639]) (user=surenb job=sendgmr) by 2002:a05:690c:39b:b0:60c:d162:7abc with SMTP id bh27-20020a05690c039b00b0060cd1627abcmr2322702ywb.1.1711039062719; Thu, 21 Mar 2024 09:37:42 -0700 (PDT) Date: Thu, 21 Mar 2024 09:36:37 -0700 In-Reply-To: <20240321163705.3067592-1-surenb@google.com> Mime-Version: 1.0 References: <20240321163705.3067592-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240321163705.3067592-16-surenb@google.com> Subject: [PATCH v6 15/37] lib: introduce early boot parameter to avoid page_ext memory overhead From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, jhubbard@nvidia.com, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, songmuchun@bytedance.com, jbaron@akamai.com, aliceryhl@google.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org X-Rspamd-Queue-Id: DBEF7C0006 X-Rspam-User: X-Stat-Signature: j6dyw9d1deseds5j8aaw6yje7ac7t1be X-Rspamd-Server: rspam01 X-HE-Tag: 1711039063-380211 X-HE-Meta: U2FsdGVkX1/MV13HP0qOYMnhpAmev+diMWkikGqW00ojlqu+q7x7Uz5IIlBqXR9AMcK8WY1RYEY7pnPlN1U+rLaXTL/5stWyfIRMadOnpmJzD+1UcwVXKASDF9XT+WwrOwZNhvDEpc5+FQzMltMm5ECxpy8+9JTqBgtxAAQrF+eGNmecYc1ZdfyFG88iGCPsSQpM/1yvM/a0sOgzCjuQ7ba/KCKVkPHWHyDI0V1vSyrq5cD7FALAbiWWHZPWynTdHm83tKqbuaEXSzfABQEsqvW7Rpi8rVR8Be623QU7qLYhNlq1v/DFALOpjkPsVc5PGk6ol/w6XKrVfxPrDVmvahpZazA25e3vFNVTd1e8GE+v5MYbeSzRp7d6pVGBEsOq/OjYx8a1t2Jbm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ijEN7LNeqpZmNkuNoZJFCbe2jtVuldbEJZgqi6/m/LYteTTlwTXSMUVKhlfhlqCH2/orkzTAx+mhFyWsAEQw+QPQtWWhII7WXfHi7ODbgcJncgM/i2sDT6DeMr9BvoIqXSbqIs6Pfydc/4TWzxc6yYAnKhNMOYvZjXkRmJI5p8IakNhpdrWY8hHYGa1aLW16vE9+4Pyc2v1/QF9MzkT4i2tSWjwx9yP72jNyI5E8vOZyh6BZegTyH2AcN 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: The highest memory overhead from memory allocation profiling comes from page_ext objects. This overhead exists even if the feature is disabled but compiled-in. To avoid it, introduce an early boot parameter that prevents page_ext object creation. The new boot parameter is a tri-state with possible values of 0|1|never. When it is set to "never" the memory allocation profiling support is disabled, and overhead is minimized (currently no page_ext objects are allocated, in the future more overhead might be eliminated). As a result we also lose ability to enable memory allocation profiling at runtime (because there is no space to store alloctag references). Runtime sysctrl becomes read-only if the early boot parameter was set to "never". Note that the default value of this boot parameter depends on the CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT configuration. When CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=n the boot parameter is set to "never", therefore eliminating any overhead. CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=y results in boot parameter being set to 1 (enabled). This allows distributions to avoid any overhead by setting CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=n config and with no changes to the kernel command line. We reuse sysctl.vm.mem_profiling boot parameter name in order to avoid introducing yet another control. This change turns it into a tri-state early boot parameter. Signed-off-by: Suren Baghdasaryan Reviewed-by: Vlastimil Babka --- lib/alloc_tag.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index cb5adec4b2e2..617c2fbb6673 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -116,9 +116,46 @@ static bool alloc_tag_module_unload(struct codetag_type *cttype, return module_unused; } +#ifdef CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT +static bool mem_profiling_support __meminitdata = true; +#else +static bool mem_profiling_support __meminitdata; +#endif + +static int __init setup_early_mem_profiling(char *str) +{ + bool enable; + + if (!str || !str[0]) + return -EINVAL; + + if (!strncmp(str, "never", 5)) { + enable = false; + mem_profiling_support = false; + } else { + int res; + + res = kstrtobool(str, &enable); + if (res) + return res; + + mem_profiling_support = true; + } + + if (enable != static_key_enabled(&mem_alloc_profiling_key)) { + if (enable) + static_branch_enable(&mem_alloc_profiling_key); + else + static_branch_disable(&mem_alloc_profiling_key); + } + + return 0; +} +early_param("sysctl.vm.mem_profiling", setup_early_mem_profiling); + static __init bool need_page_alloc_tagging(void) { - return true; + return mem_profiling_support; } static __init void init_page_alloc_tagging(void) @@ -158,6 +195,8 @@ static int __init alloc_tag_init(void) if (IS_ERR_OR_NULL(alloc_tag_cttype)) return PTR_ERR(alloc_tag_cttype); + if (!mem_profiling_support) + memory_allocation_profiling_sysctls[0].mode = 0444; register_sysctl_init("vm", memory_allocation_profiling_sysctls); procfs_init();