lkml.org 
[lkml]   [1999]   [Dec]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectUnnecessary zero initializers bloating .data
Date
I think there are some unnecessary (and not benign) initializers here and
there in the kernel.

I will pick on ll_rw_blk.c first as it seems to be a good example. Consider
the arrays defined at the top of the file.

Why explicitly initialize those arrays with 0? It forces them into .data,
bloating .data unnecessarily. That may be no big deal for desktops, but for
embedded it is. Removing the initializers shifts them to .bss where they
take up no room in the on-disk kernel image.

I see no reason to use those zero initializers. The kernel appears to
initialize .bss to zero in head.S. for almost every architecture (i386, arm,
mips, ppc, sh, sparc - don't know what is up with alpha), so it seems safe
to assume that uninitialized data is 0.

Also, ISO C9X draft says:

----------
6.7.8.10 If an object that has automatic storage duration is not initialized
explicitly, its value is indeterminate. If an object that has static storage
duration is not initialized explicitly, then:
- if it has pointer type, it is initialized to a null pointer;
- if it has arithmetic type, it is initialized to (positive or unsigned)
zero;
- if it is an aggregate, every member is initialized (recursively) according
to these rules;
- if it is a union, the first named member is initialized (recursively)
according to these rules.
----------

This simple patch alone cuts the on-disk size of the kernel by over 8k, and
it looks like it is just the beginning of removing bloat from .data:

diff -u -r1.2 ll_rw_blk.c
--- drivers/block/ll_rw_blk.c 1999/12/10 19:48:00 1.2
+++ drivers/block/ll_rw_blk.c 1999/12/18 21:38:00
@@ -66,7 +66,7 @@

/* This specifies how many sectors to read ahead on the disk. */

-int read_ahead[MAX_BLKDEV] = {0, };
+int read_ahead[MAX_BLKDEV];

/* blk_dev_struct is:
* *request_fn
@@ -82,7 +82,7 @@
*
* if (!blk_size[MAJOR]) then no minor size checking is done.
*/
-int * blk_size[MAX_BLKDEV] = { NULL, NULL, };
+int * blk_size[MAX_BLKDEV];

/*
* blksize_size contains the size of all block-devices:
@@ -91,7 +91,7 @@
*
* if (!blksize_size[MAJOR]) then 1024 bytes is assumed.
*/
-int * blksize_size[MAX_BLKDEV] = { NULL, NULL, };
+int * blksize_size[MAX_BLKDEV];

/*
* hardsect_size contains the size of the hardware sector of a device.
@@ -105,22 +105,22 @@
* This is currently set by some scsi devices and read by the msdos fs
driver.
* Other uses may appear later.
*/
-int * hardsect_size[MAX_BLKDEV] = { NULL, NULL, };
+int * hardsect_size[MAX_BLKDEV];

/*
* The following tunes the read-ahead algorithm in mm/filemap.c
*/
-int * max_readahead[MAX_BLKDEV] = { NULL, NULL, };
+int * max_readahead[MAX_BLKDEV];

/*
* Max number of sectors per request
*/
-int * max_sectors[MAX_BLKDEV] = { NULL, NULL, };
+int * max_sectors[MAX_BLKDEV];

/*
* Max number of segments per request
*/
-int * max_segments[MAX_BLKDEV] = { NULL, NULL, };
+int * max_segments[MAX_BLKDEV];

static inline int get_max_sectors(kdev_t dev)
{


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:55    [W:0.623 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site