Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k

On 64 bit, struct error_info has 6 bytes of padding, which amounts to
over 4k of wasted space in the additional[] array. We could easily get
rid of that by instead using separate arrays for the codes and the
pointers. However, we can do even better than that and save an
additional 6 bytes per entry: In the table, just store the sizeof()
the corresponding string literal. The cumulative sum of these is then
the appropriate offset into additional_text, which is built from the
concatenation (with '\0's inbetween) of the strings.

$ scripts/bloat-o-meter /tmp/vmlinux vmlinux
add/remove: 0/0 grow/shrink: 1/1 up/down: 24/-8488 (-8464)
function old new delta
scsi_extd_sense_format 136 160 +24
additional 11312 2824 -8488

The Kconfig help text used to say that CONFIG_SCSI_CONSTANTS=y costs
around 75 KB, but that was a little exaggerated. The actual number was
closer to 44K, and 36K with this patch.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Tested-by: Douglas Gilbert <dgilbert@interlog.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Rasmus Villemoes and committed by
Martin K. Petersen
e1f0bce3 9d99a2e3

+23 -7
+2 -2
drivers/scsi/Kconfig
··· 202 202 certain enclosure conditions to be reported and is not required. 203 203 204 204 config SCSI_CONSTANTS 205 - bool "Verbose SCSI error reporting (kernel size +=75K)" 205 + bool "Verbose SCSI error reporting (kernel size += 36K)" 206 206 depends on SCSI 207 207 help 208 208 The error messages regarding your SCSI hardware will be easier to 209 209 understand if you say Y here; it will enlarge your kernel by about 210 - 75 KB. If in doubt, say Y. 210 + 36 KB. If in doubt, say Y. 211 211 212 212 config SCSI_LOGGING 213 213 bool "SCSI logging facility"
+21 -5
drivers/scsi/constants.c
··· 292 292 293 293 struct error_info { 294 294 unsigned short code12; /* 0x0302 looks better than 0x03,0x02 */ 295 - const char * text; 295 + unsigned short size; 296 296 }; 297 297 298 + /* 299 + * There are 700+ entries in this table. To save space, we don't store 300 + * (code, pointer) pairs, which would make sizeof(struct 301 + * error_info)==16 on 64 bits. Rather, the second element just stores 302 + * the size (including \0) of the corresponding string, and we use the 303 + * sum of these to get the appropriate offset into additional_text 304 + * defined below. This approach saves 12 bytes per entry. 305 + */ 298 306 static const struct error_info additional[] = 299 307 { 300 - #define SENSE_CODE(c, s) {c, s}, 308 + #define SENSE_CODE(c, s) {c, sizeof(s)}, 301 309 #include "sense_codes.h" 302 310 #undef SENSE_CODE 303 - {0, NULL} 304 311 }; 312 + 313 + static const char *additional_text = 314 + #define SENSE_CODE(c, s) s "\0" 315 + #include "sense_codes.h" 316 + #undef SENSE_CODE 317 + ; 305 318 306 319 struct error_info2 { 307 320 unsigned char code1, code2_min, code2_max; ··· 377 364 { 378 365 int i; 379 366 unsigned short code = ((asc << 8) | ascq); 367 + unsigned offset = 0; 380 368 381 369 *fmt = NULL; 382 - for (i = 0; additional[i].text; i++) 370 + for (i = 0; i < ARRAY_SIZE(additional); i++) { 383 371 if (additional[i].code12 == code) 384 - return additional[i].text; 372 + return additional_text + offset; 373 + offset += additional[i].size; 374 + } 385 375 for (i = 0; additional2[i].fmt; i++) { 386 376 if (additional2[i].code1 == asc && 387 377 ascq >= additional2[i].code2_min &&