Re: [PATCH] skx_edac: Move a few hundred bytes to text from data using const

From: Joe Perches
Date: Mon Aug 22 2016 - 12:57:32 EST


On Mon, 2016-08-22 at 09:46 -0700, Luck, Tony wrote:
> On Sun, Aug 21, 2016 at 05:02:41PM -0700, Joe Perches wrote:
> > Marking arrays as const makes for smaller data.
> Joe,

Hi Tony

> "a few hundred" seems to be exaggeration.
>
> Before:
> $ size drivers/edac/skx_edac.ko
>    text    data     bss     dec     hex filename
>    8435    1024      24    9483    250b drivers/edac/skx_edac.ko
>
> After:
> $ size drivers/edac/skx_edac.ko
>    text    data     bss     dec     hex filename
>    8531     944      24    9499    251b drivers/edac/skx_edac.ko
>
> so "data" was reduced by 80 bytes, but "text" went up by 96.


Yeah, it was a few hundred in an allyesconfig
and I neglected to test the defconfig.

$ size drivers/edac/skx_edac.o* (x86-64)
   text    data     bss     dec     hex filename
   6677      64      24    6765    1a6d drivers/edac/skx_edac.o.defconfig.new
   6546     176      24    6746    1a5a drivers/edac/skx_edac.o.defconfig.old
  20609    5744     320   26673    6831 drivers/edac/skx_edac.o.new
  20273    6064     320   26657    6821 drivers/edac/skx_edac.o.old

> Net increase of 16 (perhaps because some padding for alignment???)
>
> Making read-only data const is a good idea in general, but
> do we want to do it if it *increases* kernel footprint?

Marking all data const that can be const is a good thing.
It reduces exposure and eliminates unintentional overwriting.