From: David Laight <David.Laight@ACULAB.COM>
To: 'Andrew Morton' <akpm@linux-foundation.org>,
liqiong <liqiong@nfschina.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] mm: change "char *bdi_unknown_name" to "char bdi_unknown_name[]"
Date: Fri, 13 May 2022 11:06:23 +0000 [thread overview]
Message-ID: <4b21dec7e98243b89daea96286c33434@AcuMS.aculab.com> (raw)
In-Reply-To: <20220512130051.94a0c53e5d1498292473975d@linux-foundation.org>
From: Andrew Morton
> Sent: 12 May 2022 21:01
>
> On Thu, 12 May 2022 16:26:37 +0800 liqiong <liqiong@nfschina.com> 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.
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 = "foo";
in multiple source/object files you get lots of pointers
but only one string.
OTOH with:
static const char foo_xxx[] = "foo";
you get lots of copies of the string.
Which is smaller depends on the number of variables and the length
of the string.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2022-05-13 11:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-12 8:26 liqiong
2022-05-12 14:48 ` liqiong
2022-05-12 15:29 ` Muchun Song
2022-05-12 17:10 ` liqiong
2022-05-12 20:00 ` Andrew Morton
2022-05-13 6:34 ` liqiong
2022-05-13 11:06 ` David Laight [this message]
2022-05-13 14:27 ` Muchun Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4b21dec7e98243b89daea96286c33434@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liqiong@nfschina.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox