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 D3B3AC7112F for ; Wed, 28 Aug 2024 20:25:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54B3D6B0099; Wed, 28 Aug 2024 16:25:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FA046B009A; Wed, 28 Aug 2024 16:25:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E9376B009B; Wed, 28 Aug 2024 16:25:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1CD206B0099 for ; Wed, 28 Aug 2024 16:25:18 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C9161A3F59 for ; Wed, 28 Aug 2024 20:25:17 +0000 (UTC) X-FDA: 82502783874.20.A04A9AB Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf23.hostedemail.com (Postfix) with ESMTP id 5F232140004 for ; Wed, 28 Aug 2024 20:25:14 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=kESqIMtE; spf=pass (imf23.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724876672; 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:dkim-signature; bh=pd5dFFz9q1ub1Xu8riFyFljpBMudnMsV7RsRFDEPSI4=; b=MNhPnhBV4GWwyTQ6BpIRcjGixeSKbpOEOeOgr1Bqq4l6uXQPtGAHayeUnY9/IZYbRwwTxm 8JfwLBh+nAhd513NwUkm+4cbpVlssyK8GKnhnpJPqaE1DNhilSxGYD/o6CtvNZQorPwJTr wqDtbVcFHfF2pzEe8LqI1m8d2F8LBDc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=kESqIMtE; spf=pass (imf23.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724876672; a=rsa-sha256; cv=none; b=ukySeRaFEoUUoubU9F53S7hJ6imwYhryNdDW8R53gRgnCN7T3tvirAjb5LH/hVw1ffhNEg IhJK/d9rlW1qWNjbTiSMG6DMbOgmT13GwbGloILAXjJMY7ATe6zpujgi6EIsmUC5NKigjZ GYl39gvRi4+TZafPTR9iwKcNvpuW2oU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 79B7BCE1928; Wed, 28 Aug 2024 20:25:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31981C4CEC0; Wed, 28 Aug 2024 20:25:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1724876710; bh=uBzK29h3Wh6e0YeFL9zV/5o5Il6973lCrLvdGTFVRkw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kESqIMtEyaI6zQPj+eFkdX2qp6FfujEgsyeUTXA8nqaZVEDggX0J7y2PWqdjnzzdd DzbuD0A2ZUpJ1bnu0jyPugCnINMWbwSVcWndrHgYBhQ4mtp6i+P+khKFFJDtXv4Ovr Js/dyblXotDccUNnKDO5Ql519VNFNhYtsiVi8eTo= Date: Wed, 28 Aug 2024 13:25:09 -0700 From: Andrew Morton To: Hongbo Li Cc: , , , , , , , Subject: Re: [PATCH -next v3 1/3] lib/string_choices: Add str_true_false()/str_false_true() helper Message-Id: <20240828132509.4447ff09665fa0d7b8020294@linux-foundation.org> In-Reply-To: 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> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 5F232140004 X-Stat-Signature: h8aoopjzcoak4971iaqg8iy6x5uxnt8g X-HE-Tag: 1724876714-356197 X-HE-Meta: U2FsdGVkX18eqGEqLjHu42mga/rr3g3ycYVCl4ebvi6iI0JKwupRJzxNPepT2u/bw3+usGzK7T5csO7IrrAY+rRkacRcT5pFT54jjHwYGraofbS3sO6MYCELO5Yy8h+ORbhc6GvGNe8MG7TH4HYySX04T0EUtyMOdZvqvpp1GEBAZ8IDLJMDGYUF4EitXvvXwgm6beo+Oj/kYfNmuoXqr3YMkT2V74w4VYNPocZ68dMIo7XD8xVCmvePUarjaeKymv/oKscm4aDrdK3rLue4ByybrqjTUYkARG+xNjElbPVeoAtsTHEDYNF6gRndVFS+fYFd2j1oH6Jq1qS9JEM2Bp1NLkZxFdbUVR6F5hndWFowMfl7z1KP1nz49wI2qEC4zyLkmOtsMr2OzKnueDO4KbAavaRBKT4K502h3pWHY+wqBgNZ2fQzsePgMcAq1DVNUCe+O8mNWOoKO2J6cB/mPQWCo+rey1BFhLX1+9Qhx9KaObE7J0j+/SvwnFGF3jvcd6iccoDpi8qbUicJ6jJCT5YCDgGZgHAgCL0UX5NfwQ7tAb3aAUUq8wGN0PBsAGhloOI74+amy98zevOa0djryFsbYAYqtWOeZmXh2iY7T2kVxUeZ1rPJJJQeKwDqjd/FQwREbUAwWuoOvR5H5LcWxCBMnS8cC5T3opcZOw274khNIxRmu9qifxRds4GcW7I4lzvOCMiEXCOnafGv+LuBWaG7rmiiepgkHZYEw/Z1++O0DoTuWJ+gimv9v4AS777LMDGdYTNftU5wPfva/xonV9vvt/UcZlsZ1SaCK0TLSTaHXe1GzB7vYHc5WydK/pgRN5cUlcN0a9DjUIA/WyOhJdccrYVHjlto+nnT232b8c0R5jZIJw2Hjv7D/MNWbwsb6HE+84AWNFHcIpcjv5qTEfb9po4O72pSJB6bA4oHd2wru3rO3alZF6EtMssNVegaW/orHgIyS7oaKk/4pW0 AzXIJAhL zf+poZN2MYnZG4yVFaa5kjlRW3lQpEKCgjAXpsZ5U7BfKBnkbYN9cu5fOzMs/AItIgG8I+8nYfQKSREDO2txLb/q5BK3p2CKj9tJFg8IG5YWHaYWDEHgW3Q/0HikXUzjeTFahheWhDuL37Udp2WpNJC1TS6pUywRxz59Ueh3sKCc/mBAkK20uf8bUz8tfCQgOY+C+hUAPNmvUq3ovMxINnkL+IqY3u2mEnP75alwdYSK2txPqfts4xwo0dYXkv1u4/b3HiVWY0h6swXvsoQ+w6YODlaTd2uunC+FhAVYuNwCfiOg5/3xLqEuuurul/zlWp6QC 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 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. However a quick experiment tells me that the compiler and linker are indeed able to perform this cross-object-file optimization: --- 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!