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 7677AC433EF for ; Tue, 21 Jun 2022 02:10:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A85298E0001; Mon, 20 Jun 2022 22:10:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0CB06B0073; Mon, 20 Jun 2022 22:10:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8ADEA8E0001; Mon, 20 Jun 2022 22:10:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 783BA6B0072 for ; Mon, 20 Jun 2022 22:10:42 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 4280480218 for ; Tue, 21 Jun 2022 02:10:42 +0000 (UTC) X-FDA: 79600614324.09.3FA6D97 Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by imf16.hostedemail.com (Postfix) with ESMTP id EAEC518001D for ; Tue, 21 Jun 2022 02:10:41 +0000 (UTC) Received: from omf14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C4A4C61081; Tue, 21 Jun 2022 02:10:40 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf14.hostedemail.com (Postfix) with ESMTPA id F267A32; Tue, 21 Jun 2022 02:10:38 +0000 (UTC) Message-ID: Subject: Re: [PATCH v4 00/34] Printbufs - new data structure for building strings From: Joe Perches To: Kent Overstreet , Andrew Morton Cc: David Laight , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "pmladek@suse.com" , "rostedt@goodmis.org" , "enozhatsky@chromium.org" , "linux@rasmusvillemoes.dk" , "willy@infradead.org" , Miguel Ojeda Date: Mon, 20 Jun 2022 19:10:38 -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: U2FsdGVkX18Xz7rjAxOO7jXBkzbfuwKRIweIFY8sohA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655777442; a=rsa-sha256; cv=none; b=H5NK9GpddIk6VYLssh1i9IMBQ9jECl1bONNiYIvVvWIo+MEAxTHuO1v/JFrnprxxmhvdQ6 iP7L2XwytRItzYKLSnzbknadxHnvxyi+nnkql2UtJPsw4IDi1fBcaujRFvbvFE7yD0VdA4 52jNuogVYsWP07os2J478LoiGPaFmrE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=none (imf16.hostedemail.com: domain of joe@perches.com has no SPF policy when checking 216.40.44.10) smtp.mailfrom=joe@perches.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655777442; 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=vCuUE6MR9ahQw8PZNYzWKQ/aC7sCCypG8m7+zXxNL14=; b=VyL2WOInjRRGdNLJbffDV5jmb2xlIfC4kdJ1jkWe4HFPsfAcdfrnVLkDj6dLdPEECc9UNQ iVyiYB2kgFFaJ9KoBMsHv0rM2UwRFR/xPbPkI0hpwB0X6X2wwtwqOot8yztAG7T9wW6Qqj +Ji1cz18s4murhUfi/Zyc8sE7xF92b0= X-Rspamd-Queue-Id: EAEC518001D X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=none (imf16.hostedemail.com: domain of joe@perches.com has no SPF policy when checking 216.40.44.10) smtp.mailfrom=joe@perches.com X-HE-Tag-Orig: 1655777438-450937 X-Rspamd-Server: rspam06 X-Stat-Signature: yti5ekqzjgahnwyuaaqqmjwm8kg6xddp X-HE-Tag: 1655777441-786442 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: On Mon, 2022-06-20 at 18:26 -0700, Joe Perches wrote: > On Mon, 2022-06-20 at 20:57 -0400, Kent Overstreet wrote: > > On Mon, Jun 20, 2022 at 05:38:51PM -0700, Joe Perches wrote: > > > On Mon, 2022-06-20 at 11:07 -0400, Kent Overstreet wrote: > > > > On Mon, Jun 20, 2022 at 04:19:31AM +0000, David Laight wrote: > > > > > I really think that is a bad idea. > > > > > printk() already uses a lot of stack, anything doing a recursive > > > > > call is just making that worse. > > > > > Especially since these calls can often be in error paths > > > > > which are not often tested and can already be on deep stacks. > > > >=20 > > > > We went over this before - this patch series drastically reduces st= ack usage of > > > > sprintf by eliminating a bunch of stack allocated buffers. Do try t= o keep up... > > >=20 > > > I generally agree with David. > > >=20 > > > I think Kent has not provided data that this actually _reduces_ > > > stack usage. > >=20 > > I think the people who are comfortable with reading C can discern that = when > > large stack allocated character arrays are deleted, frame size and stac= k usage > > go down. >=20 > I am very comfortable reading C. >=20 > You have not provided any data. 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=20 commit 394dffa6680c ("kallsyms: increase maximum kernel symbol length to 51= 2") 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 =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' && f= mt[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 {