From mboxrd@z Thu Jan 1 00:00:00 1970 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 05DD0C433EF for ; Sun, 26 Jun 2022 19:53:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56AAE8E0003; Sun, 26 Jun 2022 15:53:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51A308E0001; Sun, 26 Jun 2022 15:53:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E1A58E0003; Sun, 26 Jun 2022 15:53:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 30D878E0001 for ; Sun, 26 Jun 2022 15:53:37 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EFB74F19 for ; Sun, 26 Jun 2022 19:53:36 +0000 (UTC) X-FDA: 79621436832.27.C8C5004 Received: from relay5.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by imf16.hostedemail.com (Postfix) with ESMTP id 8CF6718002F for ; Sun, 26 Jun 2022 19:53:36 +0000 (UTC) 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: quoted-printable User-Agent: Evolution 3.44.1-0ubuntu1 MIME-Version: 1.0 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/C8USxNfy8/EPSKDDRnnUZLXfj+xRFuUo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656273216; a=rsa-sha256; cv=none; b=zIRotnwTSH1GMQvmGrMSBlof9QAN9gk7fEZOVi5NFsjYZAO7XMAWmC4Tgsa1DcnBk/C0h4 VjjczCiVKNh7R1ptRhAjRi5jywzHFlSAzIQJuf8tLP51ZnW7mYJGYLIiC1I84SPySS0wU3 /g6SkVhkXi3lVEpxVzSdqWlPDKNeSQY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=none (imf16.hostedemail.com: domain of joe@perches.com has no SPF policy when checking 216.40.44.11) smtp.mailfrom=joe@perches.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656273216; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7og/6kD4aWiLluqOBY00gZiWk4o3TN+rASX996f9lsY=; b=ZkKQERxYeudCAUxQuOscjrzzMRxy2ur/OMcQuVBdY51bODV/JzUwHB4b0R93BWGDjHTMiz MCDqE7tNS9OrFCZbVSVFZgybc0Q8RjADl6kzANrDu/TFj7LzEP57RraS5KtwFpFWZwn4Ws 9YqsikAobmxWjam0bgIUWvF2HqB0HH8= X-HE-Tag-Orig: 1656273207-146809 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 8CF6718002F Authentication-Results: imf16.hostedemail.com; dkim=none; spf=none (imf16.hostedemail.com: domain of joe@perches.com has no SPF policy when checking 216.40.44.11) smtp.mailfrom=joe@perches.com; dmarc=none X-Rspam-User: X-Stat-Signature: ahmdizgnr1371jfbqn7z4pz9i9a6i14q X-HE-Tag: 1656273216-149960 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: 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. >=20 > Especially since KSYM_NAME_LEN was increased to 512 by=20 > commit 394dffa6680c ("kallsyms: increase maximum kernel symbol length to = 512") >=20 > Perhaps this stack declaration should instead be an alloc/free > as it can be quite large. >=20 > I suppose one could quibble about the kzalloc vs kmalloc or the nominally > unnecessary initialization of sym. >=20 > I think this makes sense though and it reduces the #ifdef uses too. > --- > lib/vsprintf.c | 41 ++++++++++++++++++++++++----------------- > 1 file changed, 24 insertions(+), 17 deletions(-) >=20 > 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 =3D NULL; > =20 > if (fmt[1] =3D=3D 'R') > ptr =3D __builtin_extract_return_addr(ptr); > value =3D (unsigned long)ptr; > =20 > -#ifdef CONFIG_KALLSYMS > - if (*fmt =3D=3D 'B' && fmt[1] =3D=3D 'b') > - sprint_backtrace_build_id(sym, value); > - else if (*fmt =3D=3D 'B') > - sprint_backtrace(sym, value); > - else if (*fmt =3D=3D 'S' && (fmt[1] =3D=3D 'b' || (fmt[1] =3D=3D 'R' &&= fmt[2] =3D=3D 'b'))) > - sprint_symbol_build_id(sym, value); > - else if (*fmt !=3D 's') > - sprint_symbol(sym, value); > - else > - sprint_symbol_no_offset(sym, value); > + if (IS_ENABLED(CONFIG_KALLSYMS) && > + (sym =3D kzalloc(KSYM_SYMBOL_LEN, GFP_NOWAIT | __GFP_NOWARN))) { > + char *rtn; > + > + if (*fmt =3D=3D 'B' && fmt[1] =3D=3D 'b') > + sprint_backtrace_build_id(sym, value); > + else if (*fmt =3D=3D 'B') > + sprint_backtrace(sym, value); > + else if (*fmt =3D=3D 'S' && > + (fmt[1] =3D=3D 'b' || > + (fmt[1] =3D=3D 'R' && fmt[2] =3D=3D 'b'))) > + sprint_symbol_build_id(sym, value); > + else if (*fmt !=3D 's') > + sprint_symbol(sym, value); > + else > + sprint_symbol_no_offset(sym, value); > + > + rtn =3D string_nocheck(buf, end, sym, spec); > + > + kfree(sym); > + > + return rtn; > + } > =20 > - return string_nocheck(buf, end, sym, spec); > -#else > return special_hex_number(buf, end, value, sizeof(void *)); > -#endif > } > =20 > static const struct printf_spec default_str_spec =3D { >=20