From patchwork Sat Oct 3 22:09:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 7322661 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 198639F302 for ; Sat, 3 Oct 2015 22:10:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 21AC420675 for ; Sat, 3 Oct 2015 22:10:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0045220574 for ; Sat, 3 Oct 2015 22:10:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750994AbbJCWKE (ORCPT ); Sat, 3 Oct 2015 18:10:04 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:34055 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750925AbbJCWKB (ORCPT ); Sat, 3 Oct 2015 18:10:01 -0400 Received: by wicfx3 with SMTP id fx3so74097335wic.1 for ; Sat, 03 Oct 2015 15:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:organization:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=74abcGs1rpGsevqxwOkc5f31LlpMzlMzk9D/haM+vMw=; b=AbNgbtWnF1aHe+5tBuUiMCN3Zi+UHrX90om4f8LolJvsE2G/TjvzVgS9RQ40Hjt82o Y6bf58739csjjf3G1e2/+CgfMn5pp5hFrRwHU1nxDMoaiVhoIf7dTRaOCnCFVOAGFHQb 4wpkl+/hGHWjkgUSPCJNNo7oHlHxxwBdTOUzI= 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:organization:references:date :in-reply-to:message-id:user-agent:mime-version:content-type; bh=74abcGs1rpGsevqxwOkc5f31LlpMzlMzk9D/haM+vMw=; b=S1tY0dXmArTeKAvuDfP9eCoI3dydeEZdipRFiMfNyKhN+/h8WX+pyVQBFUmeYKFGiS a4roRXGzSVr+IK5JW5ShSt1Eue6w0NLuusOtM1Glpv8dofKYGub54KHpmyrvKiqdHV9q oGvsmqAq4P+ZrqhWsqgPhdTa0064uuASG7n2pz3P7a/zqd59GIdlvj1BdkMePr6FYFGz FLB34MkLQXAh8KKZbn9d7imRC41Wm1RhMDNRG086iTIWWhcqxhq183oRUhbY5qVSJysv nNkuQxWWRG7YMHRWcGjuAM/9/kFjecIHd3OyohsCvsnS4ffLXfub53Bq+wyac0aR9jW2 GpNA== X-Gm-Message-State: ALoCoQlBld81Qediiopz6oAK8y97DRgDh62WA3YcKrVtbzM6MswyRspB71iFXr1rU84NjDSh24bh X-Received: by 10.180.91.15 with SMTP id ca15mr4342631wib.12.1443910200078; Sat, 03 Oct 2015 15:10:00 -0700 (PDT) Received: from morgan.rasmusvillemoes.dk (ip-45-63.bnaa.dk. [84.238.45.63]) by smtp.gmail.com with ESMTPSA id hk5sm18418994wjb.6.2015.10.03.15.09.59 (version=TLS1_2 cipher=AES128-SHA256 bits=128/128); Sat, 03 Oct 2015 15:09:59 -0700 (PDT) From: Rasmus Villemoes To: Christoph Hellwig Cc: Hannes Reinecke , "James E.J. Bottomley" , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: Re: RFC: reduce CONFIG_SCSI_CONSTANTS impact by 4k Organization: D03 References: <87h9mbg6h1.fsf@rasmusvillemoes.dk> <20151003171437.GA20847@infradead.org> X-Hashcash: 1:20:151003:hch@infradead.org::wbMzjzlItHFX5eyu:000000000000000000000000000000000000000000000Q4Q X-Hashcash: 1:20:151003:linux-scsi@vger.kernel.org::Cs7j2LgMMLaAJn89:000000000000000000000000000000000000p3R X-Hashcash: 1:20:151003:hare@suse.de::XHmcyJ1cQyXNOXrc:000001G9j X-Hashcash: 1:20:151003:jbottomley@odin.com::khw5UHWX8QTS+0g5:0000000000000000000000000000000000000000002+hh X-Hashcash: 1:20:151003:linux-kernel@vger.kernel.org::SQoATZNQlC4fVHGL:00000000000000000000000000000000044lZ Date: Sun, 04 Oct 2015 00:09:58 +0200 In-Reply-To: <20151003171437.GA20847@infradead.org> (Christoph Hellwig's message of "Sat, 3 Oct 2015 10:14:37 -0700") Message-ID: <87bncf1u4p.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 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 Sat, Oct 03 2015, Christoph Hellwig wrote: > Hi Rasmus, > > I like this idea. But maybe it's also time to just move the constants > to a plain text file and auto-generate C headers from them? That way > the format in which they can be edited is decoupled from the > representation in the kernel image. Well, I don't really have an opinion on that part. In the meantime, I got another idea for doubling the saving to 8k. It requires a few more code changes and is perhaps also more hacky. 2/2 would be something like below. Please let me know which version you'd prefer, and I'll send both patches properly. Thanks, Rasmus Subject: [PATCH 2/2] 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 Signed-off-by: Rasmus Villemoes --- drivers/scsi/constants.c | 25 +++++++++++++++++++++---- drivers/scsi/sense_codes.h | 2 -- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c index 47aaccd5e68e..ccd34b0481cd 100644 --- a/drivers/scsi/constants.c +++ b/drivers/scsi/constants.c @@ -292,17 +292,31 @@ 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 }; +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 +378,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 && diff --git a/drivers/scsi/sense_codes.h b/drivers/scsi/sense_codes.h index 54b3939d6309..da84d53b3379 100644 --- a/drivers/scsi/sense_codes.h +++ b/drivers/scsi/sense_codes.h @@ -833,5 +833,3 @@ SENSE_CODE(0x746E, "External data encryption control timeout") SENSE_CODE(0x746F, "External data encryption control error") SENSE_CODE(0x7471, "Logical unit access not authorized") SENSE_CODE(0x7479, "Security conflict in translated device") - -SENSE_CODE(0, NULL)