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 B005CC433EF for ; Fri, 13 May 2022 06:35:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BF9B6B0073; Fri, 13 May 2022 02:35:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 274B18D0001; Fri, 13 May 2022 02:35:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15E346B0078; Fri, 13 May 2022 02:35:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 037F06B0073 for ; Fri, 13 May 2022 02:35:04 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A019232165 for ; Fri, 13 May 2022 06:35:03 +0000 (UTC) X-FDA: 79459757286.25.F305213 Received: from mail.nfschina.com (unknown [124.16.136.209]) by imf14.hostedemail.com (Postfix) with ESMTP id 2EAE81000B1 for ; Fri, 13 May 2022 06:35:00 +0000 (UTC) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id E68791E80C96; Fri, 13 May 2022 14:29:17 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Yc2e7FKnwc4q; Fri, 13 May 2022 14:29:15 +0800 (CST) Received: from [172.30.21.106] (unknown [180.167.10.98]) (Authenticated sender: liqiong@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 5D7C61E80C93; Fri, 13 May 2022 14:29:15 +0800 (CST) Subject: Re: [PATCH] mm: change "char *bdi_unknown_name" to "char bdi_unknown_name[]" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220512082637.24649-1-liqiong@nfschina.com> <20220512130051.94a0c53e5d1498292473975d@linux-foundation.org> From: liqiong Message-ID: <2d698914-befd-0283-71ed-599aa1bf9e3d@nfschina.com> Date: Fri, 13 May 2022 14:34:56 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20220512130051.94a0c53e5d1498292473975d@linux-foundation.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-Stat-Signature: as5w1oydro1mffy7u14gc5ijsfqkufut Authentication-Results: imf14.hostedemail.com; dkim=none; spf=none (imf14.hostedemail.com: domain of liqiong@nfschina.com has no SPF policy when checking 124.16.136.209) smtp.mailfrom=liqiong@nfschina.com; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2EAE81000B1 X-HE-Tag: 1652423700-845058 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: 在 2022年05月13日 04:00, Andrew Morton 写道: > On Thu, 12 May 2022 16:26:37 +0800 liqiong wrote: > >> "char bdi_unknown_nam[]" string form declares a single variable. >> It is better then "char *bdi_unknown_name" which creates two >> variables. >> >> ... >> >> --- a/mm/backing-dev.c >> +++ b/mm/backing-dev.c >> @@ -20,7 +20,7 @@ struct backing_dev_info noop_backing_dev_info; >> EXPORT_SYMBOL_GPL(noop_backing_dev_info); >> >> static struct class *bdi_class; >> -static const char *bdi_unknown_name = "(unknown)"; >> +static const char bdi_unknown_name[] = "(unknown)"; >> > heh, fun patch. We actually do this quite a lot. > > grep -r "^[a-z].*char \*[a-z].*= \"" . > > is a pathetic pattern which catches a lot of them. > > > However. I expected your patch to shrink the kernel a bit, but it has > the opposite effect: > > hp2:/usr/src/25> size mm/backing-dev.o > text data bss dec hex filename > 21288 9396 3808 34492 86bc mm/backing-dev.o-before > 21300 9428 3808 34536 86e8 mm/backing-dev.o-after > > Even .data became larger. I didn't investigate why. Hi, It seems the patch creates a new section: 0000000000000000 l ___ksymtab_gpl+bdi_dev_name 0000000000000000 __ksymtab_bdi_dev_name 0000000000000f60 l O .rodata 000000000000000a bdi_unknown_name And put "bdi_unknown_name" at .rodata.str1.1: This work was published in "KernelJanitors/Todo". It says: "foo []" is better because it declares a single variable, For variables marked __initdata, the "*foo" form causes only the pointer, not the string itself, to be dropped from the kernel image, which is a bug. Using the "foo[]" form with regular 'ole local variables also makes the assembly shorter. I thought it make sense, so i searched the mm tree by "grep -nHre char.*\*.*=.*\"", and checked all the "char *foo" string form, It seems only this one should be fixed.