Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2348532iog; Sun, 26 Jun 2022 13:22:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1upkwUPt+LTLcCosC7iie6mCHQyok2Db6Nu/AsJQzCGcCATDB5b+ARlAS3Mue+suF8WmP/v X-Received: by 2002:a63:4d65:0:b0:408:9e5c:f7b7 with SMTP id n37-20020a634d65000000b004089e5cf7b7mr9406160pgl.553.1656274949033; Sun, 26 Jun 2022 13:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656274949; cv=none; d=google.com; s=arc-20160816; b=E2ZvJp24z7SOJ4b9vtMZ8mEWehrRtpJ65RxsIxqLAn5QP+HxmAJ4qN5sM9mii/f3Nm xOo9G0PqZP51QIOSfhbb3eNjB7Q2V8brnK7gjpGjzpTrr0JIse00mPPnOlIaPRDtqj7N lUSLbtISdOdh258obXe6I7tDRk/oGrOq+8wZvOaWcrmj2VD8cs4VD8fttEgnhUO+G4TD t4BkeAfvsmjBzCmn05DbQZgjD7eTuKJg0VMVfi9Q1+R1XOXAjQRIMl8272svilyLoTA1 8I5QjIdBsutnhywKRyPBOXFIbz8nF8EwZOBnLtyM5GkVc9qQXpfxPE0wRRS1PENsa8PW T1jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=SHd6P0CIR9PYYvFFROnpzf3BLWt0VWb+3eVl4O4NK04=; b=D1h+zUbYNBHMu7l6Qq89b04FyXOMH47r8EY+/HVk25xLGZUmJeyZtIDFcjStnQRQDJ L+vMFdjg0kT3mJL03uyK89QffFO+rnxRpFxG2Awf6hqJA7doS/MSa2QIEIhHh64olDG1 VzmH+k1A8Io+w8n6iocfirxTN9EwQU+Sj7NvnR++9PrwU0Siw1x8I6s5JiUAf7kDecaP WMk7Mhc/pH0XzQ1AIucNrpbLopYDFGjkG+nVuHW5oj1dbRIoPsBjhUZnn/gcl2FFf9Ym /Re4v1WsYYB/+IFEtQnHuXWiW8S5aVV1AdEtQGvS0oU1F643QTacwnyvwU3Dck3zt/Mc F+dA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a170902f68c00b0016a14bc0a25si13687753plg.232.2022.06.26.13.22.16; Sun, 26 Jun 2022 13:22:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231910AbiFZTxj convert rfc822-to-8bit (ORCPT + 99 others); Sun, 26 Jun 2022 15:53:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231529AbiFZTxh (ORCPT ); Sun, 26 Jun 2022 15:53:37 -0400 Received: from relay3.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0178A2728 for ; Sun, 26 Jun 2022 12:53:36 -0700 (PDT) Received: from omf08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4978A20F7F; Sun, 26 Jun 2022 19:53:35 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf08.hostedemail.com (Postfix) with ESMTPA id BF0E720025; Sun, 26 Jun 2022 19:53:27 +0000 (UTC) Message-ID: <355e912490dbaef8fe4e12df0201c3f5b439565d.camel@perches.com> Subject: [RFC[ Alloc in vsprintf From: Joe Perches To: Andrew Morton , Linus Torvalds Cc: David Laight , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Rasmus Villemoes , Matthew Wilcox , Miguel Ojeda , Kent Overstreet , Andy Shevchenko , LKML , linux-mm Date: Sun, 26 Jun 2022 12:53:26 -0700 In-Reply-To: References: <20220620004233.3805-1-kent.overstreet@gmail.com> <0a5901f8460f452a89c9b0cda32fb833@AcuMS.aculab.com> <20220620150514.3tjy5dv7pv5frcwd@moria.home.lan> <53d77ae6101a0f24cfb694174d4c7699424c57e8.camel@perches.com> <20220621005752.ohiq5besmy3r5rjo@moria.home.lan> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.1-0ubuntu1 MIME-Version: 1.0 X-Rspamd-Queue-Id: BF0E720025 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Stat-Signature: zohyamfpbqbpm5xnigdzra7x6gg67d57 X-Rspamd-Server: rspamout06 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/C8USxNfy8/EPSKDDRnnUZLXfj+xRFuUo= X-HE-Tag: 1656273207-146809 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In a reply to the printbufs thread, I wrote a proposal to use an alloc to reduce stack in vsprintf when CONFIG_KALLSYMS is enabled. No one has replied to this but I think it's somewhat sensible. Thoughts? On Mon, 2022-06-20 at 19:10 -0700, Joe Perches wrote: > In a brief looking around at stack uses in vsprintf, I believe > this is the largest stack declaration there. > > Especially since KSYM_NAME_LEN was increased to 512 by > commit 394dffa6680c ("kallsyms: increase maximum kernel symbol length to 512") > > Perhaps this stack declaration should instead be an alloc/free > as it can be quite large. > > I suppose one could quibble about the kzalloc vs kmalloc or the nominally > unnecessary initialization of sym. > > I think this makes sense though and it reduces the #ifdef uses too. > --- > lib/vsprintf.c | 41 ++++++++++++++++++++++++----------------- > 1 file changed, 24 insertions(+), 17 deletions(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index c414a8d9f1ea9..30113a30fd88a 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -980,30 +980,37 @@ char *symbol_string(char *buf, char *end, void *ptr, > struct printf_spec spec, const char *fmt) > { > unsigned long value; > -#ifdef CONFIG_KALLSYMS > - char sym[KSYM_SYMBOL_LEN]; > -#endif > + char *sym = NULL; > > if (fmt[1] == 'R') > ptr = __builtin_extract_return_addr(ptr); > value = (unsigned long)ptr; > > -#ifdef CONFIG_KALLSYMS > - if (*fmt == 'B' && fmt[1] == 'b') > - sprint_backtrace_build_id(sym, value); > - else if (*fmt == 'B') > - sprint_backtrace(sym, value); > - else if (*fmt == 'S' && (fmt[1] == 'b' || (fmt[1] == 'R' && fmt[2] == 'b'))) > - sprint_symbol_build_id(sym, value); > - else if (*fmt != 's') > - sprint_symbol(sym, value); > - else > - sprint_symbol_no_offset(sym, value); > + if (IS_ENABLED(CONFIG_KALLSYMS) && > + (sym = kzalloc(KSYM_SYMBOL_LEN, GFP_NOWAIT | __GFP_NOWARN))) { > + char *rtn; > + > + if (*fmt == 'B' && fmt[1] == 'b') > + sprint_backtrace_build_id(sym, value); > + else if (*fmt == 'B') > + sprint_backtrace(sym, value); > + else if (*fmt == 'S' && > + (fmt[1] == 'b' || > + (fmt[1] == 'R' && fmt[2] == 'b'))) > + sprint_symbol_build_id(sym, value); > + else if (*fmt != 's') > + sprint_symbol(sym, value); > + else > + sprint_symbol_no_offset(sym, value); > + > + rtn = string_nocheck(buf, end, sym, spec); > + > + kfree(sym); > + > + return rtn; > + } > > - return string_nocheck(buf, end, sym, spec); > -#else > return special_hex_number(buf, end, value, sizeof(void *)); > -#endif > } > > static const struct printf_spec default_str_spec = { >