From patchwork Wed Oct 23 17:07:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13847636 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 1D91ACFA453 for ; Wed, 23 Oct 2024 17:08:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 897A56B009B; Wed, 23 Oct 2024 13:08:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 823D06B009C; Wed, 23 Oct 2024 13:08:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64E1B6B009D; Wed, 23 Oct 2024 13:08:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 408DF6B009B for ; Wed, 23 Oct 2024 13:08:09 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1A732C0DCC for ; Wed, 23 Oct 2024 17:07:50 +0000 (UTC) X-FDA: 82705499352.10.E720F28 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf04.hostedemail.com (Postfix) with ESMTP id C9C9540009 for ; Wed, 23 Oct 2024 17:07:44 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mYGd4XV5; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3di0ZZwYKCHUlnkXgUZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3di0ZZwYKCHUlnkXgUZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729703174; a=rsa-sha256; cv=none; b=kRYo1kfuohtV7X3MUb5e5jL7EvELVn1VtlD3EqjQ+3R8ONzA32TSZXGufUpzQojISiQ+RF HO0Jn74V3rANnEC0+4M/Q/VDiyizIUQfIjrl91iw2Hq3EGG6mLIUAEnOcX6L/H6+SZgFFE VzPTO/h+uivxNMiZdewNieRdhTzQjos= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mYGd4XV5; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3di0ZZwYKCHUlnkXgUZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3di0ZZwYKCHUlnkXgUZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729703174; 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=qzUZQuDC5qa2V/vpTubJjhmN2aD40kQ8oHuQLi+u1Z4=; b=vmBUdg7Ya3NnGxuXiG2o9zIVVN3qdZkQZzGE3y9Be5O6MOGIoZu3QtDjvCrJgY53Rdz5Ra WpqqK5nC3YmK2m0tA8HY0L2MRDJU05YC29OF3xUShxlKcEROBgtaUpGe08p0G57cJ6Xe4V M6t5g3hIByXbje7z8XHzsw+TlYrwj3A= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e2bd3e0a26cso69786276.0 for ; Wed, 23 Oct 2024 10:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729703286; x=1730308086; 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=qzUZQuDC5qa2V/vpTubJjhmN2aD40kQ8oHuQLi+u1Z4=; b=mYGd4XV5l0KF49Hvlr1rg2RcNAenRc/BV5M5PQBz4Ii6Cfw05q8IVgF/Eot97APrg0 oZZ3lpqPshYHoTHHRJEjbEypwST9JXdU0IcVDOUT05Z46ncYhJiYiRv5tZTkXEZnfvuB yli0WkRE0DjaBmbAiHRj6xB6lWskzGb2VYaGh8OKX+BvFn195jPc6p4MLkWS5XJKzd27 Uq1nzJCJa3nMV9pe+V5+Ut2FlTw08APP8tr3Q340CRJVm9Hfb46G3/pvDWWFwcbGgzQF UdBir6FJYemPoPfI36gHIVLQ8Qp9sS326dnadAgrwTRqLsqeaZ0SAPAXx3JxdbtglO6A Sy7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729703286; x=1730308086; 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=qzUZQuDC5qa2V/vpTubJjhmN2aD40kQ8oHuQLi+u1Z4=; b=MBiHogs2LutWLDTTQF0724x/WE+VcRNAnhejQNmRXM2zFMPnMRzP4X46vaIxlCSiDg 4tmV+c1pqq+HGhXTnK8KQVmpD4qpmvdaD8p4Df5ZnzdT9Q5tcsOS9vUdHXe6Rmz2YYyW d3b7Oyaaw5YsKvQVH8VSxspE02Jk1Urf7oBM1BUe3FeNm67fJBWG59DKFPa88Z7Bvo5S wKdejAbAuWXVnSC+lcegwSWJOgnGfyzVGG6wqAAaLD2cXjSQOkEG8YOu/RSJJWlhASD0 tTlgR6ukH4DwSxqHg++BYYjgW3BcNNxaFwdn0WaznksttPiHKryPqjUjdY5qqEBcXjWO hxAg== X-Forwarded-Encrypted: i=1; AJvYcCWWqvKsFY7Fm+iBzC6JRNpxYzSZ62Uj63O/N8Y/+tHeKpRR3GJFpUksLMjjiF0QDncNtSYha0Nb1g==@kvack.org X-Gm-Message-State: AOJu0YyWwxw8svjkTJrod7wOqhQelVpQMyITyGh3QMmSnxogoGe65xJW wGrOGMLWBhDAs2DG7pRxJhED4vaWRE6qqItFpkBMBWDR//Glyfgxr2Dn+YsqXRCU+4wrQxy1qTA gWQ== X-Google-Smtp-Source: AGHT+IEf9XVjhAQxbJksRoGGus3EwGVaSTpLfWlLEYi7zdwXtn6qn+dayeJKMPCmDwrDuVs0NH6hwtuuxI8= X-Received: from surenb-desktop.mtv.corp.google.com ([2a00:79e0:2e3f:8:a087:59b9:198a:c44c]) (user=surenb job=sendgmr) by 2002:a25:8289:0:b0:e2e:3401:ea0f with SMTP id 3f1490d57ef6-e2e3a6bbdffmr7278276.7.1729703286023; Wed, 23 Oct 2024 10:08:06 -0700 (PDT) Date: Wed, 23 Oct 2024 10:07:55 -0700 In-Reply-To: <20241023170759.999909-1-surenb@google.com> Mime-Version: 1.0 References: <20241023170759.999909-1-surenb@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Message-ID: <20241023170759.999909-3-surenb@google.com> Subject: [PATCH v4 2/6] alloc_tag: introduce shutdown_mem_profiling helper function From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, corbet@lwn.net, arnd@arndb.de, mcgrof@kernel.org, rppt@kernel.org, paulmck@kernel.org, thuth@redhat.com, tglx@linutronix.de, bp@alien8.de, xiongwei.song@windriver.com, ardb@kernel.org, david@redhat.com, vbabka@suse.cz, mhocko@suse.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, pasha.tatashin@soleen.com, souravpanda@google.com, keescook@chromium.org, dennis@kernel.org, jhubbard@nvidia.com, urezki@gmail.com, hch@infradead.org, petr.pavlu@suse.com, samitolvanen@google.com, da.gomez@samsung.com, yuzhao@google.com, vvvvvv@google.com, rostedt@goodmis.org, iamjoonsoo.kim@lge.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, maple-tree@lists.infradead.org, linux-modules@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspamd-Queue-Id: C9C9540009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fom4ay8sbgzh1gxqjww3hr7wiqqjfwkf X-HE-Tag: 1729703264-981072 X-HE-Meta: U2FsdGVkX197QxsqLbsVgAeLLUzS2cbI49bYGUI/0hf2ywidsbOaq7NaFxbtYP58ViJHcaYaqR5fFFuN2bmATsIWC5DW92MhvmqU7rr55/DiCRHj5ASWh8ymWqD44l5bqFMzyhQXkYYnubVrXr9Bf1KxBbeSSQzJ+IWPEN52Kf3ANVjKxtcMYujKYT9XiCa4JVVFeUycvrZcynvVWo1aSidWtt7KZ7Rm2iX3akcyjKz/Ummny+bmk6QbL+8QAWZp7z0HD8F9xGJQHfENoPGlSpoIr08JEzS9LFDvk2jV8UO3zAGkR36pm0x19jsPGaMxCzOx5wyTv0DmcnA0IUDamDBgKpQw3Vq42uS7VyvX+P8VRas/8OVztjZXu+pnwYuerQIOr0hti1VltB+m6h+LrdUvobA6Vg2TlR6gkqnhIG2O5udNvBy5tMyAjMC/80sDZ42pMk15z2elMHNMzya/2j+RZDxevH20PSh2AcctgMFBk/Wd9AtKyB/Tpg1ilOu5UT5Ndff84+UfuJUpdynBLFVn9qQYXBB8hBIFgGCknRWoXOthbkgEt/9DHbyR80sVzVrd3SvMHGFxeSlTjEGVs+AAPXXS97+EXJOixzxTC17+zF2+01/nX9au8RXoBNPq+1uLHz64vkJKwGqs96BcIGqksst7vnPjE7HGcUwlbbkcrrBHvo2hbAC87Ogv35lgi8gRw0RWQ+jEi3XXsDiGT59CbmFO+2wX4mxKBpnEDzLLliZ5xHb3Qo+Mi5QrdWHh5UcU9Q5npzf6YlntT7nP5BYD9OHxrXt8SHxGUgM6VyTzNS4GYtE0d8dUyPalGjnWq2ziMfVoJj3rRtoXBZFLQ8GaIhDss4ciVmfJS7LVO+h9PmPCIszjEj/5QyaVivcjwiDGzhfeyB/0i3F9b2peCFgTbyHOVEf++3QzHH+P51yOwy3+NXeqN1yZHivHvjckIWicI6vcIC873Gm4Fkn Np4ZPAuZ tSLQSbKsmSNtIEkrHgX+lau951cMxAbHYR6Ng0y+pHZ3AJA6Mzad0HhvBUx/HarDWZC79QRNqOwYts/EwoTDA7G4k6rIlQOyNFPn87lFpzz2MxriybRuP2cr20pFPwEt9g2LTP/wP3iWAr058bcvYHsHn+XmGXTttsclKP/87S9FrG8mQCU4Z0PNqk/vZj74y3I35ID0rxk95hq6f7UL6lo4zLOC+PLoWoIcZ+wp5BsbMJ/7smv5lQtH/H0SP2T7mkluiyFWGO0D1a51zQVJPYEOIDTj77qhwnxfOgtobCo/cUsfgH1heaAxe4k1SkraTLmX/vjCEBsQNO1AnpJRu3Ytr9fC8/N2mUE6e80ki+3+D2nUbTeOAGx1AUsqEdksmCW3dgccXtIvO0XUBcLkkVSp0ZEF7VpPL66GQyOmashynw5utZazNghP5vmOdqVj2vB5Fda/1YGNFEscUSsD2rRJaFV78IncPIBgs4vNRfwi+YvLd5PtHIkPvQ/7T2Ialoc8KxpyWv71jPo7R6Lw48eZVxXccL/37SdhINHTZnXmXHJJBDNRq1A5NYOwpa69OIyd2LCXV5RQX5Wv3F3TOzmxn7A== 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: Implement a helper function to disable memory allocation profiling and use it when creation of /proc/allocinfo fails. Ensure /proc/allocinfo does not get created when memory allocation profiling is disabled. Signed-off-by: Suren Baghdasaryan Reviewed-by: Pasha Tatashin --- lib/alloc_tag.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 81e5f9a70f22..435aa837e550 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -8,6 +8,14 @@ #include #include +#define ALLOCINFO_FILE_NAME "allocinfo" + +#ifdef CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT +static bool mem_profiling_support __meminitdata = true; +#else +static bool mem_profiling_support __meminitdata; +#endif + static struct codetag_type *alloc_tag_cttype; DEFINE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag); @@ -144,9 +152,26 @@ size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, bool can_sl return nr; } +static void __init shutdown_mem_profiling(void) +{ + if (mem_alloc_profiling_enabled()) + static_branch_disable(&mem_alloc_profiling_key); + + if (!mem_profiling_support) + return; + + mem_profiling_support = false; +} + static void __init procfs_init(void) { - proc_create_seq("allocinfo", 0400, NULL, &allocinfo_seq_op); + if (!mem_profiling_support) + return; + + if (!proc_create_seq(ALLOCINFO_FILE_NAME, 0400, NULL, &allocinfo_seq_op)) { + pr_err("Failed to create %s file\n", ALLOCINFO_FILE_NAME); + shutdown_mem_profiling(); + } } static bool alloc_tag_module_unload(struct codetag_type *cttype, @@ -174,12 +199,6 @@ 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;