All of lore.kernel.org
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Christoph Hellwig <hch@infradead.org>,
	Hannes Reinecke <hare@suse.de>,
	Bart Van Assche <bart.vanassche@sandisk.com>,
	"James E.J. Bottomley" <JBottomley@odin.com>,
	Julian Calaby <julian.calaby@gmail.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k
Date: Tue, 22 Dec 2015 15:25:33 -0500	[thread overview]
Message-ID: <5679B1BD.7090406@interlog.com> (raw)
In-Reply-To: <1448358147-23663-4-git-send-email-linux@rasmusvillemoes.dk>

On 15-11-24 04:42 AM, Rasmus Villemoes wrote:
> 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
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>

Tested-by: Douglas Gilbert <dgilbert@interlog.com>

> ---
>   drivers/scsi/constants.c | 26 +++++++++++++++++++++-----
>   1 file changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
> index 6e813eec4f8d..83458f7a2824 100644
> --- a/drivers/scsi/constants.c
> +++ b/drivers/scsi/constants.c
> @@ -292,17 +292,30 @@ bool scsi_opcode_sa_name(int opcode, int service_action,
>
>   struct error_info {
>   	unsigned short code12;	/* 0x0302 looks better than 0x03,0x02 */
> -	const char * text;
> +	unsigned short size;
>   };
>
> +/*
> + * There are 700+ entries in this table. To save space, we don't store
> + * (code, pointer) pairs, which would make sizeof(struct
> + * error_info)==16 on 64 bits. Rather, the second element just stores
> + * the size (including \0) of the corresponding string, and we use the
> + * sum of these to get the appropriate offset into additional_text
> + * defined below. This approach saves 12 bytes per entry.
> + */
>   static const struct error_info additional[] =
>   {
> -#define SENSE_CODE(c, s) {c, s},
> +#define SENSE_CODE(c, s) {c, sizeof(s)},
>   #include "sense_codes.h"
>   #undef SENSE_CODE
> -	{0, NULL}
>   };
>
> +static const char *additional_text =
> +#define SENSE_CODE(c, s) s "\0"
> +#include "sense_codes.h"
> +#undef SENSE_CODE
> +	;
> +
>   struct error_info2 {
>   	unsigned char code1, code2_min, code2_max;
>   	const char * str;
> @@ -364,11 +377,14 @@ scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
>   {
>   	int i;
>   	unsigned short code = ((asc << 8) | ascq);
> +	unsigned offset = 0;
>
>   	*fmt = NULL;
> -	for (i = 0; additional[i].text; i++)
> +	for (i = 0; i < ARRAY_SIZE(additional); i++) {
>   		if (additional[i].code12 == code)
> -			return additional[i].text;
> +			return additional_text + offset;
> +		offset += additional[i].size;
> +	}
>   	for (i = 0; additional2[i].fmt; i++) {
>   		if (additional2[i].code1 == asc &&
>   		    ascq >= additional2[i].code2_min &&
>


  reply	other threads:[~2015-12-22 20:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24  9:42 [PATCH v2 0/3] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k Rasmus Villemoes
2015-11-24  9:42 ` [PATCH v2 1/3] scsi: make some Additional Sense strings more grep'able Rasmus Villemoes
2015-12-22 20:25   ` Douglas Gilbert
2015-11-24  9:42 ` [PATCH v2 2/3] scsi: move Additional Sense Codes to separate file Rasmus Villemoes
2015-12-22 20:25   ` Douglas Gilbert
2015-11-24  9:42 ` [PATCH v2 3/3] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k Rasmus Villemoes
2015-12-22 20:25   ` Douglas Gilbert [this message]
2015-11-24 15:09 ` [PATCH v2 0/3] " Hannes Reinecke
2015-12-22 20:25 ` Douglas Gilbert
2016-03-08 19:52 ` Rasmus Villemoes
2016-03-22  7:54   ` Christoph Hellwig
2016-03-22 19:32     ` [PATCH v3 " Rasmus Villemoes
2016-03-22 19:32       ` [PATCH v3 1/3] scsi: make some Additional Sense strings more grep'able Rasmus Villemoes
2016-03-22 19:32       ` [PATCH v3 2/3] scsi: move Additional Sense Codes to separate file Rasmus Villemoes
2016-03-22 19:32       ` [PATCH v3 3/3] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k Rasmus Villemoes
2016-03-23  7:39       ` [PATCH v3 0/3] " Christoph Hellwig
2016-03-23 20:50       ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5679B1BD.7090406@interlog.com \
    --to=dgilbert@interlog.com \
    --cc=JBottomley@odin.com \
    --cc=bart.vanassche@sandisk.com \
    --cc=hare@suse.de \
    --cc=hch@infradead.org \
    --cc=julian.calaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.