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 76A5DC71159 for ; Thu, 29 Aug 2024 01:12:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0530D6B00B7; Wed, 28 Aug 2024 21:12:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 001346B00BC; Wed, 28 Aug 2024 21:12:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCA896B00C0; Wed, 28 Aug 2024 21:12:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BB1CE6B00B7 for ; Wed, 28 Aug 2024 21:12:53 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5F56616082D for ; Thu, 29 Aug 2024 01:12:53 +0000 (UTC) X-FDA: 82503508626.25.F402030 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf15.hostedemail.com (Postfix) with ESMTP id 87FDFA0009 for ; Thu, 29 Aug 2024 01:12:50 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of lihongbo22@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=lihongbo22@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724893951; 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=C83E3NLWvWg7MEk/5kXjSWhLKu+hZctJ4y+ov0zHD44=; b=6t69ukCeC9DnQ6bqAZ6kzlpuRnG+JIupHR/GwdtbfNMgo89/h/wSoEwcz3JrXGBgNa7IPF SUrlwCboOEFxyuKbSotqruRcK9MT3f96yNQl0J7k3q7/+xTpNrOnUb4I5P5zVD24rUvyl2 QKvSCXdOzmzApcd201csxCZK9v99G40= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of lihongbo22@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=lihongbo22@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724893951; a=rsa-sha256; cv=none; b=fnG04+vRJSPg8kDYagH1fJU5uWZHKLESOoLt0XM9O8MmvJQriPX89Xb04gp8w0I/o/gusU pUW46zSs4+A7s1bzNt2ldaGxh5U9Ka/8sWieaJtF0LBtwSrqA0clALBjNCsK/GbU8fwfYe KhK30k5GGioEfSX1ILl03sd8dvqEkc4= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WvNSD0H7Rz20mvZ; Thu, 29 Aug 2024 09:07:56 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id 0FB5F140257; Thu, 29 Aug 2024 09:12:46 +0800 (CST) Received: from [10.67.111.104] (10.67.111.104) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 29 Aug 2024 09:12:45 +0800 Message-ID: <3f40ff3c-0f66-49cc-806f-1cab6c8a8c50@huawei.com> Date: Thu, 29 Aug 2024 09:12:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH -next v3 1/3] lib/string_choices: Add str_true_false()/str_false_true() helper To: Andrew Morton CC: , , , , , , , References: <20240827024517.914100-1-lihongbo22@huawei.com> <20240827024517.914100-2-lihongbo22@huawei.com> <20240827164218.c45407bf2f2ef828975c1eff@linux-foundation.org> <8d19aece-3a33-4667-8bcf-635a3a861d1d@huawei.com> <20240827202204.b76c0510bf44cdfb6d3a74bd@linux-foundation.org> <20240828132509.4447ff09665fa0d7b8020294@linux-foundation.org> Content-Language: en-US From: Hongbo Li In-Reply-To: <20240828132509.4447ff09665fa0d7b8020294@linux-foundation.org> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.111.104] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500022.china.huawei.com (7.185.36.66) X-Rspam-User: X-Stat-Signature: aoghiewrd68knsp5jtqsihmb3r9scxuc X-Rspamd-Queue-Id: 87FDFA0009 X-Rspamd-Server: rspam11 X-HE-Tag: 1724893970-516609 X-HE-Meta: U2FsdGVkX1/X3WAFicROFaxK+COF+UYO6CRFqdB2lVGZZfM1c+VlODVr0ZpOfkLmJCXj3DWywIAu7VY+gFr6SGlOdy6tzCi7OI3v37lK682g6xJEiw8aREYLKC7MvQqFI34JSYvD/VqjegR3lY/v1q++a+bnU58E7QAxj3RfjT7Vbr1T+VZQ/SHZonOswnBvI+6vXttjMH5MYMni1OGb8gYjG3sBEBCTKXZYGYICR4CYEb5Ed0O/D3H/OWZN10K4d4R7b4PR4crVhblDR02rQnXKoR7JzI/64y7t9/A1vNLsjSybZRdTRoXGYtY0/lU3Mtq6FoYnG0RkSuk2gFUs/vXvkvx6gHRHh/o218ZO3KAzOG9dY6EN0HOwIaVN+WUYOPafUel5/bxqSwjPQmUU+Lo6B9/b5fU4RENea4MePM0g1bodMRP4hU1wowNUw17UaBaJOGJyCqnurgXi+uBGCXsGOes2Anl7BOLtW0++5vmySg9MiUj9AIoU2GXGfVAR/7o74NHkXVPqJkf4zlAh4wuMvLrUEmxAsRoCQp1aLEgtN8vP2F+I9S3gCU2m8s82RKhttTQpNsEb8Y6GmJyiwtJorjw4jtfCcw/wfV/N77gSavlruDK7Xp35Q2DL1jpqp80C2TBe/Gccq/90wVSVs7trt/UdkqHdRXLdsunf+idTge8aCzpiZdAG6/QY1+kVw47+ksgy+k5SfFDJsz6PrNBY2Egcpgm9PhjAdSXH0TDj1dVV0mOGTlP5Q8iGg/iCygwpO+AtMirRpCIugAan94hDJH9DUQ5aQe0/gOOUUZbsQwVZ7TyFxbbgOKUrMiftCYKdSn8nkwTMd41oHwXnpWr4pJ2vpDLWT0A25x8WGr8R7srOkdMapAQl/8ol7x6f8dVWEyMGbaBlEonBGRz5OhuSOkAfy55K4cNLCjeo6bfSUEVAP71vDB5qB8Ox77WHQiyI/kwfngoERj9AIY2 e3naHBGz qjOuDWADNo+MvA4N6vW7G3GUATJAyZ7U2WAJTTzM9ZCN4ZGS8otmesjhZsz1TFlEC+LpaHfZQzrdpn+XRMBTsAkoh9DXyYIx4j2lU1doaXtfmzFcCOSpwpgcfu9DTIzKtNQb+WPyReAxK02sTDHYwO5q9R41qw5FXbKQcn0Q/C5USKh75I9i9oRZA9M/ZoTzoIXwnuQri6WIyfQ8056ZDxP6T3zXEBJhLY1fEtdI+1xNzZs+mFaK+cUMLhOigRCaNGeoC2WVKKGF8GNiqXaBmJlZ93A== 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: List-Subscribe: List-Unsubscribe: On 2024/8/29 4:25, Andrew Morton wrote: > On Wed, 28 Aug 2024 11:49:51 +0800 Hongbo Li wrote: > >>> Anything which is calling these functions is not performance-sensitive, >>> so optimizing for space is preferred. An out-of-line function which >>> returns a const char * will achieve this? >> I think this helper can achieve this. Because it is tiny enough, the >> compiler will handle this like #define macro (do the replacement) >> without allocating extra functional stack. On the contrary, if it is >> implemented as a non-inline function, it will cause extra functional >> stack when it was called every time. And it also should be implemented >> in a source file (.c file), not in header file(.h file). > > No, my concern is that if, for example, str_high_low() gets used in 100 > .c files then we get 100 copies of the strings "high" and "low" in > vmlinux. Making str_high_low() uninlined would fix this. At first, I didn't consider these aspects. > > However a quick experiment tells me that the compiler and linker are > indeed able to perform this cross-object-file optimization: > That's very good! Thanks, Hongbo > --- a/fs/open.c~a > +++ a/fs/open.c > @@ -34,6 +34,8 @@ > #include > #include > > +#include > + > #include "internal.h" > > int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry, > @@ -42,6 +44,8 @@ int do_truncate(struct mnt_idmap *idmap, > int ret; > struct iattr newattrs; > > + printk("%s\n", frozzle(dentry == NULL)); > + > /* Not pretty: "inode->i_size" shouldn't really be signed. But it is. */ > if (length < 0) > return -EINVAL; > --- a/fs/inode.c~a > +++ a/fs/inode.c > @@ -22,6 +22,9 @@ > #include > #include > #include > + > +#include > + > #include "internal.h" > > /* > @@ -110,6 +113,8 @@ static struct inodes_stat_t inodes_stat; > static int proc_nr_inodes(const struct ctl_table *table, int write, void *buffer, > size_t *lenp, loff_t *ppos) > { > + printk("%s\n", frozzle(table == NULL)); > + > inodes_stat.nr_inodes = get_nr_inodes(); > inodes_stat.nr_unused = get_nr_inodes_unused(); > return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); > --- a/include/linux/string_choices.h~a > +++ a/include/linux/string_choices.h > @@ -4,6 +4,11 @@ > > #include > > +static inline const char *frozzle(bool v) > +{ > + return v ? "frizzle" : "frazzle"; > +} > + > static inline const char *str_enable_disable(bool v) > { > return v ? "enable" : "disable"; > _ > > > x1:/usr/src/25> strings vmlinux|grep frazzle > frazzle > x1:/usr/src/25> > > See, only one copy! >