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 30FA3C433F5 for ; Fri, 13 May 2022 11:06:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72A906B0073; Fri, 13 May 2022 07:06:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B39B6B0075; Fri, 13 May 2022 07:06:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52C686B0078; Fri, 13 May 2022 07:06:29 -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 4014A6B0073 for ; Fri, 13 May 2022 07:06:29 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 15B7D80B73 for ; Fri, 13 May 2022 11:06:29 +0000 (UTC) X-FDA: 79460441298.07.6C40610 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf07.hostedemail.com (Postfix) with ESMTP id 76B38400A7 for ; Fri, 13 May 2022 11:06:21 +0000 (UTC) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-197-ASZCsPWJPluT1yty21qOXQ-1; Fri, 13 May 2022 12:06:24 +0100 X-MC-Unique: ASZCsPWJPluT1yty21qOXQ-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 13 May 2022 12:06:23 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.033; Fri, 13 May 2022 12:06:23 +0100 From: David Laight To: 'Andrew Morton' , liqiong CC: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] mm: change "char *bdi_unknown_name" to "char bdi_unknown_name[]" Thread-Topic: [PATCH] mm: change "char *bdi_unknown_name" to "char bdi_unknown_name[]" Thread-Index: AQHYZjsAqW5HazYh8E6shSZ+mswpua0cpDpg Date: Fri, 13 May 2022 11:06:23 +0000 Message-ID: <4b21dec7e98243b89daea96286c33434@AcuMS.aculab.com> References: <20220512082637.24649-1-liqiong@nfschina.com> <20220512130051.94a0c53e5d1498292473975d@linux-foundation.org> In-Reply-To: <20220512130051.94a0c53e5d1498292473975d@linux-foundation.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 76B38400A7 X-Stat-Signature: x4jo3ej1c8imhakypz6gmrewyzh61g5y X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf07.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com X-Rspamd-Server: rspam09 X-HE-Tag: 1652439981-310139 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: From: Andrew Morton > Sent: 12 May 2022 21:01 >=20 > On Thu, 12 May 2022 16:26:37 +0800 liqiong wrote: >=20 > > "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 =3D "(unknown)"; > > +static const char bdi_unknown_name[] =3D "(unknown)"; > > >=20 > heh, fun patch. We actually do this quite a lot. >=20 > =09grep -r "^[a-z].*char \*[a-z].*=3D \"" . >=20 > is a pathetic pattern which catches a lot of them. >=20 >=20 > However. I expected your patch to shrink the kernel a bit, but it has > the opposite effect: >=20 > hp2:/usr/src/25> size mm/backing-dev.o > text=09 data=09 bss=09 dec=09 hex=09filename > 21288=09 9396=09 3808=09 34492=09 86bc=09mm/backing-dev.o-before > 21300=09 9428=09 3808=09 34536=09 86e8=09mm/backing-dev.o-after >=20 > Even .data became larger. I didn't investigate why. The linker can merge replicated strings (ie data in .rodata.str1.n sections) but I don't think the compiler puts variables into that section. So if you have: static const char *const foo_xxx =3D "foo"; in multiple source/object files you get lots of pointers but only one string. OTOH with: static const char foo_xxx[] =3D "foo"; you get lots of copies of the string. Which is smaller depends on the number of variables and the length of the string. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)