Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp78538lqi; Wed, 6 Mar 2024 10:29:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+2FVVQ7tDVx4WdSSm/tBu+k5XD4Y2entR4VRFvYMM6Zk40I54Mq4vqB9BVnpEUWnTUnYsP+1T88VEhSmWwOtn2gjyPoA+2ilLzpRiSg== X-Google-Smtp-Source: AGHT+IFVCfkvujjAmbyrntqIucj09wuwWClGICb+IA7xgzEzE+qGjzkxFPSVhJwu8QW0vfa9NQcF X-Received: by 2002:a05:620a:5581:b0:788:3191:3f60 with SMTP id vq1-20020a05620a558100b0078831913f60mr6322993qkn.69.1709749799293; Wed, 06 Mar 2024 10:29:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709749799; cv=pass; d=google.com; s=arc-20160816; b=xGc8BB4Ykga0R3ZuRbLWfsYoz44i2QQtBmYD1TEX4VJKBzRZqSk+jQnrfoJu6jlrz5 Aa4h8v3dVzabefYOp6L0at9tmcF1uuN60O23i8ttcicejKMlqV9qFwUL6+b4Al2atgiX dvcPiPQkMasHBbemCYm2ZlGWPuVU/cddTgLCmDXX4NtRAz8llah6IFCOHi0ZqRFt44N7 /94C3X0eCVWAwEYfj/wc8dKcLTOSqxh292mPKzFA8YhTPxtS3lfNDFilmSSx/tPBFuPD 66SROs2PBd9D07lM/d+k4RWBpyfY/YXWSFVJpWTECd3B0XOHaAds1d+fxLH2jKwL7V6f YerA== 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=bHZwja06se4PI5NvmXw6g0w6FqOSRgAaf+Zh29a7Axs=; fh=lY308suyDH/QrCX6b2IzIuqXdKkKo/9ipEjGA6aAkVE=; b=RyX8/yK56AN7VU4KVohl6hPatzfu9+N36mYNFxf49OL9HXE/ur3RNnCII0xCXkeE// R+9pR0tanV1vygWCypWed4XWQwOSm0hrVAo3X5TwZZMT+Mu0qkr/iKT9czxGwbIbBLfU YdszErspEWL9Ys1TlDr1mkhYQbOksQUFXrwZ1Frho80ZzgkH2Jg9e4sKvJ91ZrOvPZui ERX4hBfhvLw0cjC6/OsfxMELtJtv17l50j+mElksoCakskfUsLfLw7UKN+BQP7LTGg4F HgHMWHQWSMnu8oAZSPs5itXDR7tA0jZjEehBrLgEFjGmfOLzXGeYFmBjgDMTNeSj5Wro 8TZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Zbliseqw; 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-94407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94407-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 m11-20020a05620a214b00b00788310cf868si5516958qkm.399.2024.03.06.10.29.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 10:29:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94407-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=Zbliseqw; 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-94407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94407-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 ED5681C21757 for ; Wed, 6 Mar 2024 18:29:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0227148FFF; Wed, 6 Mar 2024 18:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Zbliseqw" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 108AE1474A6 for ; Wed, 6 Mar 2024 18:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709749520; cv=none; b=MQsFhVf54xzDztB++LN4qQ8xPG87GinPSCr1rMkpXpPkSCUi/Rlt8EDs0rG8O/zaKif3+K+9WCyyR0wHfqRxb7GWf894qKzVuomQe2c2S+Tvr8GnQwwKfWN9d6jht3OMo+kGqZSu0zeXVys6wPLSCZw95dm6lNBcx/YSUMS4jC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709749520; c=relaxed/simple; bh=Dv0eI32ABhCg/c3ioBN2YUnGdkO8o8M10k34MMBgAyw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MExvuqk5jiIsSZKUNdDJXH5c+7EgWKDC4NMM9EvKW5gaCYqBcK5QwUpmXnMIlM10r9hb9gEJwQxUdOxxeEeIggheXGO8uPRKUj8gSIh7ieWNFYB8xAgueYOef4EIvWsGVqI0jdRN2VVt7Yn9a12jfYVUUGpjsI2D3UZBVq6x2Hw= 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=Zbliseqw; arc=none smtp.client-ip=209.85.128.202 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-f202.google.com with SMTP id 00721157ae682-60966f363c1so118547b3.3 for ; Wed, 06 Mar 2024 10:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709749517; x=1710354317; 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=bHZwja06se4PI5NvmXw6g0w6FqOSRgAaf+Zh29a7Axs=; b=ZbliseqwaEa+vFlbwJFZ4qt5t9Pd2WQg3OKci0yjhtfGWEz9MYfNtDl3cWYuBnOVGJ MvLDfFb393YjCeEYwxcLWQhScVKFjrSG0YvY8jxk4Kx7tdtNziFGdAptuDnQFh4lXH7p OIgm789hYKJANxzsAfpPalLO/BanSQ/Vw3tpJjMoA9oF5niM6oEkXyipv4k9TsP3sWga b7CoAxBU3vW1oXrx9n7EehWALeBythb4o4IQ4DubRo969NG0rY2QpvtvTyZxwG4XIRr0 Zx9yF0X89RAfuB6Wjz/gMr63PcUn/Y8w9w/nN771Cd/wfj5eS3Oa0wdFBcsMvBNcgKFC ytpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709749517; x=1710354317; 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=bHZwja06se4PI5NvmXw6g0w6FqOSRgAaf+Zh29a7Axs=; b=Ax8xDHJwBIdK2bwI8yxL++4z8hoEoqrNf5VrUhQC2ZJ0l7k0YAge9w3WOooDcMNMzM YVmHj4JJPshzj7bG0cMuZzzRvgUpf0SuXFOieHVVprbrXEb13rzvmXxpjaH8CmZyxrNI 03y8iPGmYR1ZofySLvJ0tSjdMKF9PrBs0pX6AHEE94z23TWNiBewFBt4M2aAdZKtX7eg ftNw6FTn5IgKfy/3f+wI1ZeGcjO3VYpRoWV5zT4l0LCmClL4S1F23T/xYKqxdszotysB PGQiD974+ttmJuC5w+SCYB6hXvCgc3nbFVNRA/EU/z2rZ/1V025puhOC2QfXc8s8VWpc 98rQ== X-Forwarded-Encrypted: i=1; AJvYcCX6LB9qLcPXjxkdg5Dfj45mJNqafuGjtcOMW8hTycy2Ttjfxr8UbZfZgT35m7Z37aTiZbQf0wiD0vC/P3QVtNT43LVGH40SluFk5QeS X-Gm-Message-State: AOJu0Yxy1da95SRzGVYXWQ5mCkMaeKBjaAcq5tDypgQKV1R8K+PgB/Qz bW90CD+qmX2E4ZHKf6w6/8LOglSEMCfIF/A3Rk1Lh4i2g6uIba13uMfw5ImH6CUhWYkeIGteOSd kVQ== X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:85f0:e3db:db05:85e2]) (user=surenb job=sendgmr) by 2002:a05:6902:18c9:b0:dcd:5e5d:458b with SMTP id ck9-20020a05690218c900b00dcd5e5d458bmr4001383ybb.3.1709749516858; Wed, 06 Mar 2024 10:25:16 -0800 (PST) Date: Wed, 6 Mar 2024 10:24:13 -0800 In-Reply-To: <20240306182440.2003814-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: <20240306182440.2003814-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240306182440.2003814-16-surenb@google.com> Subject: [PATCH v5 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, shakeelb@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 Content-Type: text/plain; charset="UTF-8" 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 --- 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(); -- 2.44.0.278.ge034bb2e1d-goog