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 A19B4C433FE for ; Mon, 25 Apr 2022 02:44:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E29386B00A0; Sun, 24 Apr 2022 22:44:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD7C16B00A1; Sun, 24 Apr 2022 22:44:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9F466B00A2; Sun, 24 Apr 2022 22:44:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id B8FEB6B00A0 for ; Sun, 24 Apr 2022 22:44:43 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 85E7C21F0B for ; Mon, 25 Apr 2022 02:44:43 +0000 (UTC) X-FDA: 79393858446.08.A5CE602 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 3DB9C2002B for ; Mon, 25 Apr 2022 02:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=5cqZcBN/6VFoY2Kiw77E9V9l0udJorJnVRNxt6POB6Y=; b=pIe19kOM7lwduX9PIpON6Gl3Sb tYT/bmec/CDms8FQucEQp6BGZAPj/h3jUBLBkh0h3XXCKXO9c1KHZeplYXXTzPkIudQ39ORiAUt1N BDgYk5dNJzeztVjkG2pEEedWZvlTrtkUFgbOqjalWHN4EJ36ksozrS4EeaTP70ABLfhLRM3erkfXj uxEUuxKkBhom61Yus7fC7pKXE5CTkq32ISL4+6DCXYl0Aj7z6B89Xs0wZMj+zH3y+YZ8xVGwe9of6 B5fdfzAbcW4/J1UmME6cC0nkd6PsnNAkik1MjWGztykCGHMi/GWeEEqJn9diQEIk29exTmYH1X9+H nABXy5rA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nioiI-008N4t-Ir; Mon, 25 Apr 2022 02:44:34 +0000 Date: Mon, 25 Apr 2022 03:44:34 +0100 From: Matthew Wilcox To: Joe Perches Cc: Kent Overstreet , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, hch@lst.de, hannes@cmpxchg.org, akpm@linux-foundation.org, linux-clk@vger.kernel.org, linux-tegra@vger.kernel.org, linux-input@vger.kernel.org, roman.gushchin@linux.dev Subject: Re: [PATCH v2 1/8] lib/printbuf: New data structure for heap-allocated strings Message-ID: References: <20220421234837.3629927-1-kent.overstreet@gmail.com> <20220421234837.3629927-7-kent.overstreet@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=pIe19kOM; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3DB9C2002B X-Stat-Signature: tphkdq4t1qbsf8mt966za55k9e5mnncg X-HE-Tag: 1650854680-22998 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 Sun, Apr 24, 2022 at 04:46:03PM -0700, Joe Perches wrote: > > + * pr_human_readable_u64, pr_human_readable_s64: Print an integer with human > > + * readable units. > > Why not extend vsprintf for this using something like %pH[8|16|32|64] > or %pH[c|s|l|ll|uc|us|ul|ull] ? The %pX extension we have is _cute_, but ultimately a bad idea. It centralises all kinds of unrelated things in vsprintf.c, eg bdev_name() and clock() and ip_addr_string(). Really, it's working around that we don't have something like Java's StringBuffer (which I see both seq_buf and printbuf as attempting to be). So we have this primitive format string hack instead of exposing methods like: void dentry_string(struct strbuf *, struct dentry *); as an example, if (unlikely(ino == dir->i_ino)) { EXT4_ERROR_INODE(dir, "'%pd' linked to parent dir", dentry); return ERR_PTR(-EFSCORRUPTED); } would become something like: if (unlikely(ino == dir->i_ino)) { struct strbuf strbuf; strbuf_char(strbuf, '\''); dentry_string(strbuf, dentry); strbuf_string(strbuf, "' linked to parent dir"); EXT4_ERROR_INODE(dir, strbuf); return ERR_PTR(-EFSCORRUPTED); } which isn't terribly nice, but C has sucky syntax for string construction. Other languages have done this better, including Rust.