public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* List of all-zero .data variables in linux-2.4.3 available
@ 2001-04-12 12:36 Adam J. Richter
  2001-04-12 14:44 ` johan.adolfsson
  2001-04-12 19:52 ` Jeff Garzik
  0 siblings, 2 replies; 13+ messages in thread
From: Adam J. Richter @ 2001-04-12 12:36 UTC (permalink / raw)
  To: linux-kernel

	For anyone who is interested, I have produced a list of all
of the .data variables that contain all zeroes and could be moved to
.bss within the kernel and all of the modules (all of the modules
that we build at Yggdrasil for x86, which is almost all).  These
are global or static variables that have been declared

	int foo = 0;

instead of

	int foo;	/* = 0 */

	The result is that the .o files are bigger than they have
to be.  The kernel memory image is not bigger, and gzip shrinks the
runs of zeroes down to almost nothing, so it does not have a huge effect
on bootable disks.  Still, it would be nice to save the disk space of
the approximately 75 kilobytes of zeroes and perhaps squeeze in another
sector or two when building boot floppies.

	I have also included a copy of the program that I wrote to
find these all-zero .data variables.

	The program and the output are FTPable from
ftp://ftp.yggdrasil.com/private/adam/linux/zerovars/.  Files with no
all-zero .data variables are not included in the listing.  If you maintain
any code in the kernel, you might want to look at the output to see
how your code stacks up.

Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America
fax +1 408 261-6631      "Free Software For The Rest Of Us."

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: List of all-zero .data variables in linux-2.4.3 available
@ 2001-04-12 19:01 Adam J. Richter
  2001-04-12 19:14 ` Ulrich Drepper
  0 siblings, 1 reply; 13+ messages in thread
From: Adam J. Richter @ 2001-04-12 19:01 UTC (permalink / raw)
  To: johan.adolfsson; +Cc: linux-kernel

johan.adolfsson@axis.com writes:
>Shouldn't a compiler be able to deal with this instead?

	Yes.  I sent some email to bug-gcc about this a couple of
months ago and even posted some (probably horribly incorrect) code
showing roughly the change I had in mind in the gcc source code
for the simple case of scalar variables.  I was told that some code
to this was put in and then removed from gcc a long time ago, and
nobody seemed interested in putting it back in.  I would think that this
would be a basic optimization that I would expect the compiler to make,
just like deleting "if(0) {......}" code, but gcc does not currently
do that.  If somebody would like to fix gcc and do the necessary
lobbying to get such a change integrated, that would be great.  However,
until that actually happens, I hope the file that I posted to
ftp://ftp.yggdrasil.com/private/adam/linux/zerovars/ will be useful
to individual maintainers and in identifying the largest arrays of
zeroes that can fix fixed in a few lines.

Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America
fax +1 408 261-6631      "Free Software For The Rest Of Us."

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: List of all-zero .data variables in linux-2.4.3 available
@ 2001-04-12 19:29 Adam J. Richter
  2001-04-12 19:40 ` Ulrich Drepper
  0 siblings, 1 reply; 13+ messages in thread
From: Adam J. Richter @ 2001-04-12 19:29 UTC (permalink / raw)
  To: drepper; +Cc: linux-kernel

>> = Adam Richter
>  = Ulrich Drepper

>> >Shouldn't a compiler be able to deal with this instead?
>> 
>> 	Yes.

>No.  gcc must not do this.  There are situations where you must place
>a zero-initialized variable in .data.  It is a programmer problem.

	I am aware of a couple of cases where code relied on static
variables being allocated contiguously, but, in both cases, those
variables were either all zeros or all non-zeros, so my proposed
change would not break such code.  Also, variables being allocated
contiguously is not an assumption supported by any standard that
I am aware of, and the very rare cases where code relies on this
should instead use an array (they've been of the same type in the
examples that I have come across).  At the very least, it seems
to me that this should be a compiler optimization flag, preferably
defaulted to "on".

	If you have some other scenario in mind, I'd appreciate an
example or a clear reference to some explanation, and I think others
on linux-kernel would probably appreciate that too.  It is a topic
that comes up repeatedly on linux-kernel.

Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America
fax +1 408 261-6631      "Free Software For The Rest Of Us."

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: List of all-zero .data variables in linux-2.4.3 available
@ 2001-04-12 19:50 Adam J. Richter
  0 siblings, 0 replies; 13+ messages in thread
From: Adam J. Richter @ 2001-04-12 19:50 UTC (permalink / raw)
  To: drepper; +Cc: linux-kernel

>> 	I am aware of a couple of cases where code relied on static
>> variables being allocated contiguously, but, in both cases, those
>> variables were either all zeros or all non-zeros, so my proposed
>> change would not break such code.

>Continuous placement is not the only property defined by
>initialization.  There are many more.  You cannot change this since it
>will quite a few programs and libraries and subtle and hard to
>impossible to identify ways.  Simply educate programmers to not
>initialize.

	If it is so simple to "educate" programmers on this,
could you provide and example or some specifics, especially on why
this should not even be a compiler option?  Surely that will save
you some iterations in this discussion.

Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America
fax +1 408 261-6631      "Free Software For The Rest Of Us."

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: List of all-zero .data variables in linux-2.4.3 available
@ 2001-04-12 20:04 Adam J. Richter
  0 siblings, 0 replies; 13+ messages in thread
From: Adam J. Richter @ 2001-04-12 20:04 UTC (permalink / raw)
  To: jgarzik; +Cc: linux-kernel

>Thanks, but Andrey Panin did you one better -- he produced a patch which
>fixes up a good number of these.  You should follow lkml more closely :)

I missed that patch and have been unable to find it on google/dejanews.
However, my point is to provide an exhaustive list with sizes (and the tool
for generating it), to make it easier to spot and prioritize ones that
may have been missed.

Anyhow, thanks for the tip.  Perhaps I should run this program and
post results again on a subsequent kernel release (presumably
with Andrey's patch), although anyone else can run this program
just as easily.

Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America
fax +1 408 261-6631      "Free Software For The Rest Of Us."

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2001-04-16 21:21 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-04-12 12:36 List of all-zero .data variables in linux-2.4.3 available Adam J. Richter
2001-04-12 14:44 ` johan.adolfsson
2001-04-12 14:57   ` Russell King
2001-04-12 15:28   ` Richard B. Johnson
2001-04-12 19:52 ` Jeff Garzik
  -- strict thread matches above, loose matches on Subject: below --
2001-04-12 19:01 Adam J. Richter
2001-04-12 19:14 ` Ulrich Drepper
2001-04-12 21:27   ` H. Peter Anvin
2001-04-12 19:29 Adam J. Richter
2001-04-12 19:40 ` Ulrich Drepper
2001-04-16 14:33   ` Pavel Machek
2001-04-12 19:50 Adam J. Richter
2001-04-12 20:04 Adam J. Richter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox