From patchwork Tue Nov 24 09:42:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 7689011 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 44FFCBF90C for ; Tue, 24 Nov 2015 09:43:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6EC072080E for ; Tue, 24 Nov 2015 09:43:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F27C20804 for ; Tue, 24 Nov 2015 09:43:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753879AbbKXJn1 (ORCPT ); Tue, 24 Nov 2015 04:43:27 -0500 Received: from mail-lf0-f41.google.com ([209.85.215.41]:36714 "EHLO mail-lf0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753674AbbKXJmu (ORCPT ); Tue, 24 Nov 2015 04:42:50 -0500 Received: by lfs39 with SMTP id 39so13243155lfs.3 for ; Tue, 24 Nov 2015 01:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yCyYZQr6x8tS7olpvCIpZMCgeKwEk7gltLRAcP7k0WQ=; b=WszxlQzpWhFDRyrD/9Gwx7jEyRU2ND3Vw6pAmN5HqunNxxNo4BH90QcdjeY5pEcTIe RiaElj/0w8JUPHXHK5zLWaMfvIHjniuVZVH8x/KL3iF72E6HmE5LwPncOnc3oGFacjVn N6ST5/DKQnrw7tZvVS4lvab4IKo6R11qKZ+OQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yCyYZQr6x8tS7olpvCIpZMCgeKwEk7gltLRAcP7k0WQ=; b=IpmAIx+hzVS+j7xaOBzFJFdONqbYTm9BdCNxcY1vXgS2PK3eIJ0CiW+Tu0jnFBqeL0 RtTWXeNX/c+ToUqt7Q5baKG+e6QYyUN4TOy9hCeAkiDjXtUjGtgrDgay1vLua7GnpV4x cOWEWosRC01sMp1cfvxf1EIfRPwFFHWltbtJ8iw0yq5rqc7tmC9jAZrag1egj8A2Qvy5 lactihH06H8MWgVcWRrCCJ9fu38y8PK+j+xa1OWm9Y2CkQ2BPpepVf7K+mh7nBNyRU6q L8Kb9WBkwqTdjpimOPXYlEq1xweouKDDA7p6GcTcS6eDZgy7paFVQMG9jc43QOtvQCjd YeQg== X-Gm-Message-State: ALoCoQkYZaAJsL7z4vV6jnRGtlw/tajcN1jtw6Gddi6PU/Dhfsxjvmmao3Wod9aIneHNPtjlAjsT X-Received: by 10.112.150.168 with SMTP id uj8mr10566928lbb.22.1448358169134; Tue, 24 Nov 2015 01:42:49 -0800 (PST) Received: from garcia.imf.au.dk ([130.225.20.51]) by smtp.gmail.com with ESMTPSA id m75sm2465773lfg.15.2015.11.24.01.42.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Nov 2015 01:42:48 -0800 (PST) From: Rasmus Villemoes To: Christoph Hellwig , Hannes Reinecke , Bart Van Assche , "James E.J. Bottomley" , Julian Calaby Cc: Rasmus Villemoes , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k Date: Tue, 24 Nov 2015 10:42:27 +0100 Message-Id: <1448358147-23663-4-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.6.1 In-Reply-To: <1448358147-23663-1-git-send-email-linux@rasmusvillemoes.dk> References: <1448358147-23663-1-git-send-email-linux@rasmusvillemoes.dk> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Douglas Gilbert --- 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 &&