Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp571813rwb; Fri, 23 Sep 2022 00:38:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4eFKKEBdkrv07Du63K25pZVAJ762YgbwCumRHkYce15P1MZz/jcFntlBLyi8mvu7oCmdCv X-Received: by 2002:a05:6402:298d:b0:451:5fc5:d423 with SMTP id eq13-20020a056402298d00b004515fc5d423mr7081212edb.102.1663918736208; Fri, 23 Sep 2022 00:38:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663918736; cv=none; d=google.com; s=arc-20160816; b=jQ5E+MwkV8aRR6kqGFX7+akqDKKSW6iN7ysSD+AZofe0l+9M7BzGL8k8R/LxlCVHl/ 3B0Tk49LPadm0Z7v49ISgvR3qagcOT9jPhujcvzCybjgoUB+KAONdkFjy+R67h3DumD1 31FJ2rLMrmJ6s+klYi5IV39xvYzILnS3aHUZn3RqOR0MRTFBG+NfVGpUqi3mWkrD46pK +l/VSoF+DFp2dazkxxY+AYaCpk16QGwcbtMZQaUE9oHdl9ug1FzxjQ0CK40cLLUVPCrP tIdpcic+avwDq8NSB9ZVSOiAsvFGLQ3x95eRdHYbhr3Ik9HhpeO9yhrHYrRMHDzYQDWd YTLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ORsrL8e+8QbJVIe4BvhZ3VDvLBbB5qgP5KztMnQH7yw=; b=Yz5oZd6a9spTfGqCMSJmCwtZnmAba2Gedrct6m5n+f5wc3pfHcFWhggDaUrTPzuAT+ vuVjh43uuDTbzg6W7MxYOowejxKks9AP9OP1WdRJzAOUpxxjmB1laM1NJnZFcWQ8RmlF O94NSA2s0J7hScjFncDOm+JcAW70/0GEe/Rxr9M0fkuSowiS4TSmMDXqp7BH2t8zGcyW w0aE5Xh/y5yJ/skfi8PMIVnGwkmoi58vjKpzBTnTxL3cAsR3J51JsSCwvthbgR5W+zQK NUJHEarjH5Eak/Z/uS/3rFneSqDWZWna6qRv4THuLgKVqK4LGjvoqgG7K4AdTEWMPdYU xX7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=FYwaPeup; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020a1709063a5400b0075c4337b02dsi6275562ejf.827.2022.09.23.00.38.31; Fri, 23 Sep 2022 00:38:56 -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; dkim=pass header.i=@suse.com header.s=susede1 header.b=FYwaPeup; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230047AbiIWHK5 (ORCPT + 99 others); Fri, 23 Sep 2022 03:10:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229673AbiIWHKv (ORCPT ); Fri, 23 Sep 2022 03:10:51 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17F5012384E for ; Fri, 23 Sep 2022 00:10:50 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 86B8321A6C; Fri, 23 Sep 2022 07:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1663917048; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ORsrL8e+8QbJVIe4BvhZ3VDvLBbB5qgP5KztMnQH7yw=; b=FYwaPeup555d+w356djmlgJcpK1vj/zXKLlXoCHvcqRbdOuVarhoVY+ZZMbbdV6yx2ST7W QSsCNbJ8C3jS43992/wtJLmCSfKjuzI+CTdKEE+mzvs+asmnx5MOmyFyosmB0UzdEH2QpW xRG9OaQeRPcxAhZaNEzpFUHTEhoHLPM= Received: from suse.cz (unknown [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 8622F2C14F; Fri, 23 Sep 2022 07:10:47 +0000 (UTC) Date: Fri, 23 Sep 2022 09:10:44 +0200 From: Petr Mladek To: Kent Overstreet Cc: linux-kernel@vger.kernel.org, "Matthew Wilcox (Oracle)" , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , John Ogness , Linus Torvalds , Andrew Morton , Ingo Molnar , Dan Williams , Michal Hocko , Bjorn Helgaas , Christoph Hellwig , Dmitry Torokhov , Al Viro Subject: Re: [PATCH v5 00/32] Printbufs Message-ID: References: <20220808024128.3219082-1-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220808024128.3219082-1-willy@infradead.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 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 On Mon 2022-08-08 03:40:56, Matthew Wilcox (Oracle) wrote: > [all this code is from Kent, I'm helping him out because he's having > trouble with git send-email and OAUTH] > > This should (hopefully) be the final iteration of this patch series. > > Previous discussion: > https://lore.kernel.org/linux-mm/20220620004233.3805-1-kent.overstreet@gmail.com/ > > Changes since v4: > > - %pf(%p) format extension has been dropped for now, since it turned out to be > a bit controversial. I think we're going to want it, but I'm leaving it for a > future patch series. > - There was a small off by one error in the patch converting > trace_events_synth. The original code using seq_buf had to calculate the size > of the string to allocate; since printbufs have native support for heap > allocating strings, the version of the patch in this series just uses that > for a nice cleanup. > > What are printbufs, and why? > ============================ > > Printbufs are like the existing seq_buf, with some differences and new features: > > - Heap allocation (optional) > > Currently, we have no standard mechanism for printing to a heap-allocated > string: code that needs to do this must calculate the size of the buffer to > allocate, which is tedious and error prone. IOW, this is a major ergonomic > improvement. > > - Indent level > > Any time we're printing structured multi-line data, proper indenting makes > the output considerably more readable. Printbufs have state for the current > indent level, controlled by printbuf_indent_add() and printbuf_indent_sub() > and obeyed by prt_newline(). > > In the future this may work with just \n, pending work to do this without > performance regressions. > > - Tab stops > > Printing reports with nicely aligned columns is something we do a _lot_, and > printbufs make this a lot easier. After setting tabstops (byte offsets from > start of line), prt_tab() will output spaces up to the next tabstop, and > pr_tab_rjust() will right justify output since the previous output against > the next tabstap. > > In the future this may work with just \t, pending work to do this without > performance regressions. The more I think about this patchset the more doubts I have. My first reaction was rather positive because 1. __prt_char(out, c) looks more safe and sane than repeating the following code pattern in vsprintf code if (buf < end) *buf = '0'; ++buf; 2. printk("%pf", meaningful_function_name(ptr)) is more user friendly, extendable. With a type check, it might be even more safe than printk("%pxyz", ptr); 3. pretty print API would allow to avoid some tricky use of temporary buffers in vsprintf code, for example, see https://lore.kernel.org/r/20220808024128.3219082-15-willy@infradead.org What are the concerns? It seems that the motivation for the pretty print is to allow printing more pretty/fancy multi-line debug messages. The API should be usable inside vsprintf.c and also outside. 1. vsprintf() is very important core API. It is used (not only for) when kernel wants to provide a human readable feedback, for example, via printk(), trace_printk(), procfs, sysfs, debugfs. If a bug in vsprintf() blocks printk()/trace_printk() then crash_dump might be the only way to debug the kernel. 2. My experience with printk() is that external APIs are big source of problems. Some of them are even solved by hacks, for example: + Console drivers have to check oops_in_progress before taking port->lock to prevent a deadlock. + printk_deferred() or printk_once() have to be used by code that might be called by printk(). This patchset adds another external API. The %pf feature allows writing crazy callbacks called inside vsprintf()/printk() without any proper review and self-tests. People would want to extend the pretty print API for a profs/sysfs/debugfs use-case. They would take it easily. There is a lower risk in this case because only a particular file is affected, the API is called in a well defined context. But it looks like a call for problems if we allow to call the same complicated code also from vsprintf() or printk() in any context. 3. Features usually complicate the code immediately or later. For example, the record based ring buffer complicated the printk() code a lot. It introduced many regressions. Development of the lockless variant was a real challenge. And it did not solve everything. Peple still complain that pr_cont() is not reliable. Multi-line output might be mixed, ... The pretty print API is actually designed for multi-line output. But it will not help when used with printk() that uses 1k buffers internally. And adding support for "unlimited" printk() messages would be another challenge. It would bring new problems, for example, one printk() caller might block others for too long, ... Any opinion is really appreciated. Best Regards, Petr PS: I am sorry that I did not react on this patchset for months. I was overloaded, sick twice, and had vacation. A more detailed review of the patchset would help me to have stronger opinion about it. I am not clever and experienced enough to see all the consequences on the first look.