linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: reduce CONFIG_SCSI_CONSTANTS impact by 4k
@ 2015-09-30 17:30 Rasmus Villemoes
  2015-10-03 17:14 ` Christoph Hellwig
  0 siblings, 1 reply; 15+ messages in thread
From: Rasmus Villemoes @ 2015-09-30 17:30 UTC (permalink / raw)
  To: Christoph Hellwig, Hannes Reinecke, James E.J. Bottomley
  Cc: linux-kernel, linux-scsi

struct error_info has 6 bytes of padding on x86_64 (and I assume also
other 64 bit platforms). This currently amounts to about 4k of wasted
space (and presumably a third of that on 32 bit).

We can avoid that by keeping the codes and the strings in separate
arrays. Keeping those in sync should be easy enough if we use the
standard trick of including a table twice.

Patch 2/2 would be something like below; 1/2 is a 1600 line purely
mechanical thing which I won't spam the lists with unless someone else
thinks this is a good idea.

What do you think?

Subject: [PATCH 2/2] scsi: split additional[] array in two

struct error_info has 6 bytes of padding (on 64 bit platforms), which
amounts to over 4K of wasted space in the additional[]
array. Splitting it in two avoids that waste. A BUILD_BUG_ON and the
fact that the two arrays are generated from the same include file
should keep these two arrays in sync.

$ scripts/bloat-o-meter /tmp/vmlinux vmlinux
add/remove: 2/1 grow/shrink: 1/0 up/down: 7073/-11312 (-4239)

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/scsi/constants.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 14d5069ca3ff..03f28cdcbc31 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -290,19 +290,19 @@ bool scsi_opcode_sa_name(int opcode, int service_action,
 	return true;
 }
 
-struct error_info {
-	unsigned short code12;	/* 0x0302 looks better than 0x03,0x02 */
-	const char * text;
+static unsigned short additional_code12[] = {
+#define SENSE_CODE(c, s) c
+#include "sense_codes.h"
+#undef SENSE_CODE
 };
 
-
-static const struct error_info additional[] =
-{
-#define SENSE_CODE(c, s) {c, s}
+static const char *additional_text[] = {
+#define SENSE_CODE(c, s) s
 #include "sense_codes.h"
 #undef SENSE_CODE
 };
 
+
 struct error_info2 {
 	unsigned char code1, code2_min, code2_max;
 	const char * str;
@@ -364,11 +364,12 @@ scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
 {
 	int i;
 	unsigned short code = ((asc << 8) | ascq);
+	BUILD_BUG_ON(ARRAY_SIZE(additional_code12) != ARRAY_SIZE(additional_text));
 
 	*fmt = NULL;
-	for (i = 0; additional[i].text; i++)
-		if (additional[i].code12 == code)
-			return additional[i].text;
+	for (i = 0; additional_text[i]; i++)
+		if (additional_code12[i] == code)
+			return additional_text[i];
 	for (i = 0; additional2[i].fmt; i++) {
 		if (additional2[i].code1 == asc &&
 		    ascq >= additional2[i].code2_min &&

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

end of thread, other threads:[~2015-10-17 22:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-30 17:30 RFC: reduce CONFIG_SCSI_CONSTANTS impact by 4k Rasmus Villemoes
2015-10-03 17:14 ` Christoph Hellwig
2015-10-03 22:09   ` Rasmus Villemoes
2015-10-04  8:02     ` Christoph Hellwig
2015-10-05  9:26       ` [PATCH 0/2] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k Rasmus Villemoes
2015-10-05  9:26         ` [PATCH 1/2] scsi: move Additional Sense Codes to separate file Rasmus Villemoes
2015-10-05 14:05           ` Bart Van Assche
2015-10-06 15:27             ` Rasmus Villemoes
2015-10-17 22:12               ` Rasmus Villemoes
2015-10-05  9:26         ` [PATCH 2/2] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k Rasmus Villemoes
2015-10-05 14:11           ` Bart Van Assche
2015-10-06 15:31             ` Rasmus Villemoes
2015-10-06  1:32     ` RFC: reduce CONFIG_SCSI_CONSTANTS impact by 4k Julian Calaby
2015-10-06 15:39       ` Rasmus Villemoes
2015-10-06 23:01         ` Julian Calaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).