From patchwork Tue Mar 22 19:32:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 8644691 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 3B587C0554 for ; Tue, 22 Mar 2016 19:33:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2AEF920148 for ; Tue, 22 Mar 2016 19:33:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 33EAB20212 for ; Tue, 22 Mar 2016 19:33:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752259AbcCVTcm (ORCPT ); Tue, 22 Mar 2016 15:32:42 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:33170 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751723AbcCVTc2 (ORCPT ); Tue, 22 Mar 2016 15:32:28 -0400 Received: by mail-wm0-f47.google.com with SMTP id l68so206587725wml.0 for ; Tue, 22 Mar 2016 12:32:27 -0700 (PDT) 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=9sIspoo+aGNZ+2tFYrqunlLATTQ42jSSB+6sg2CrLb8=; b=AWXbBnizcJfTyABgtfNszk1BxV0Ie4jrqeWmlEac1PLSEnq1XmdjGHnnuQjEsJYnEi 1mjD1SFOcwpqtFm4/ILwKHzKkqniCl+te+SBhK+8Y49k5khtxAZqcVVdlw5XpNMYo5bD zkm7JIrO8m4PzzSURfLdmErVEaOD9od+6HZzc= 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=9sIspoo+aGNZ+2tFYrqunlLATTQ42jSSB+6sg2CrLb8=; b=VsFzuzksg/S6FmO5y9x3KmjFdCMYzCo9Oi4P54Z6lEMeQMSVkOVGtm5wQ8JJLoW/1I sQCBqKdrR3fExM6MeKMf176IGbl4O87/i6q08P+b9W0Y/syiMNVxJdQQ4sz8rngLrS1m VnMdWtvs7/LafEvWUBPpvQKtDoq04+zOAleaMo1ThCrWrLgoi23g8KQpJemZ4zycxkLz Q+RNC1A0cP8dJgxDj5ixNUE3ME3L8Vf1JXQxpZbTxLGaEuOTU+ho+lwOLeeMNrHypXAT NaLVle3tIP9+uBh+PsRCJuIAyOLmQoEUO2IZ3S/1Ih1Ez5Kzs2r0QtNuQ3PU7PYH2klO ZAqw== X-Gm-Message-State: AD7BkJI8Muz+axldw29pRrkLfnIzDgsi1cALzyRW0dfcnKcmaCY+V/W6blMq6Z/KhkB+RQ== X-Received: by 10.28.88.15 with SMTP id m15mr21161962wmb.60.1458675146403; Tue, 22 Mar 2016 12:32:26 -0700 (PDT) Received: from localhost.localdomain (lvps87-230-87-209.dedicated.hosteurope.de. [87.230.87.209]) by smtp.gmail.com with ESMTPSA id hx10sm31647926wjb.25.2016.03.22.12.32.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Mar 2016 12:32:26 -0700 (PDT) From: Rasmus Villemoes To: Douglas Gilbert , Christoph Hellwig , Hannes Reinecke , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Bart Van Assche , Rasmus Villemoes , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k Date: Tue, 22 Mar 2016 20:32:05 +0100 Message-Id: <1458675126-19265-4-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458675126-19265-1-git-send-email-linux@rasmusvillemoes.dk> References: <20160322075405.GA20141@infradead.org> <1458675126-19265-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=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,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 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 Reviewed-by: Hannes Reinecke Tested-by: Douglas Gilbert --- drivers/scsi/Kconfig | 4 ++-- drivers/scsi/constants.c | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index e80768f8e579..47611bda633f 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig @@ -202,12 +202,12 @@ config SCSI_ENCLOSURE certain enclosure conditions to be reported and is not required. config SCSI_CONSTANTS - bool "Verbose SCSI error reporting (kernel size +=75K)" + bool "Verbose SCSI error reporting (kernel size += 36K)" depends on SCSI help The error messages regarding your SCSI hardware will be easier to understand if you say Y here; it will enlarge your kernel by about - 75 KB. If in doubt, say Y. + 36 KB. If in doubt, say Y. config SCSI_LOGGING bool "SCSI logging facility" 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 &&