linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benny Halevy <bhalevy@panasas.com>
To: Matthew Wilcox <matthew@wil.cx>
Cc: Boaz Harrosh <bharrosh@panasas.com>,
	James Bottomley <James.Bottomley@SteelEye.com>,
	Jens Axboe <jens.axboe@oracle.com>,
	FUJITA Tomonori <tomof@acm.org>,
	Matthew Dharm <mdharm-scsi@one-eyed-alien.net>,
	Russell King <rmk@arm.linux.org.uk>,
	Alan Stern <stern@rowland.harvard.edu>,
	"David S. Miller" <davem@davemloft.net>,
	Christoph Hellwig <hch@infradead.org>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	Pete Wyckoff <pw@osc.edu>
Subject: Re: [PATCH 27/32] scsi_data_buffer
Date: Thu, 18 Oct 2007 08:59:58 +0200	[thread overview]
Message-ID: <4717046E.9040101@panasas.com> (raw)
In-Reply-To: <20071018004722.GA14883@parisc-linux.org>

On Oct. 18, 2007, 2:47 +0200, Matthew Wilcox <matthew@wil.cx> wrote:
> On Wed, Oct 17, 2007 at 08:21:15PM +0200, Boaz Harrosh wrote:
>>   - Group all IO members of scsi_cmnd into a scsi_data_buffer
>>     structure.
> 
>> +struct scsi_data_buffer {
>> +	unsigned length;
>> +	int resid;
>> +	unsigned short sg_count;
>> +	unsigned short alloc_sg_count;
>> +	struct scatterlist* sglist;
>> +};
> 
> This has exactly the problems I thought it would have.  Due to alignment
> rules, it grows the scsi_cmnd from 368 to 376 bytes on x86-64.
> It remains at 272 bytes on i386 though, which is some consolation.
> By porting the patch I had for shrinking the scsi_cmnd, I can get it
> down to 352 bytes, but not as far as the 344 bytes I had it at before.
> 
> The problem is the padding at the *end* of scsi_data_buffer (er, after I
> rearrange it in the patch below).  There's nothing we can realistically
> put in it, given that we don't want to expand scsi_data_buffer's size on
> 32-bit machines.  I have a fix ... but I don't think you'll like it.
> I certainly don't.  But it does get us back down to 344 bytes.
> 
> Updated patch below.  I'm fully expecting the 'result' shenanigan to get
> it NACKed, but I'd like to see if it inspires anyone else to a more
> creative way of saving this space.


yeah. The sglist pointer shuffle makes sense and so are the field type
changes and coalescing, but the union holding the deprecated fields
of scsi_data_buff is going away.

#pragma pack(4) before struct scsi_cmnd
(followed by #pragma pack()) should do the trick 
by saving member padding bytes. As a general rule I don't like pragma's
but this one works, is easy to understand, and is pretty standard.

> 
> ---
> 
> Thanks to acme's pahole utility, I found some places where we can save
> a lot of bytes in scsi_cmnd, just by rearranging struct elements and
> reducing the size of some elements.  We go from 272 to 260 bytes on x86
> and from 368 to 344 bytes on x86-64.
> 
>  - eh_eflags had a 4-byte hole after it on 64-bit.  In fact, this has
>    value 0 or 1, so reduce it to an unsigned char, and put it with the
>    other chars in scsi_cmnd.  Saves 8 bytes on 64-bit.
>  - sc_data_direction has a value from 0-3, so make it an unsigned char
>    rather than an enum.  Saves at least 4 bytes.
>  - Putting 'tag' with the other char elements saves another 4 bytes
>  - Moving 'result' into the union with the deprecated members saves 8
>    bytes on 64-bit.
> 
> diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
> index 047ffe6..2b10779 100644
> --- a/include/scsi/scsi_cmnd.h
> +++ b/include/scsi/scsi_cmnd.h
> @@ -13,22 +13,21 @@ struct Scsi_Host;
>  struct scsi_device;
>  
>  struct scsi_data_buffer {
> +	struct scatterlist* sglist;
>  	unsigned length;
>  	int resid;
>  	unsigned short sg_count;
>  	unsigned short alloc_sg_count;
> -	struct scatterlist* sglist;
>  };
>  
>  /* embedded in scsi_cmnd */
>  struct scsi_pointer {
>  	char *ptr;		/* data pointer */
> -	int this_residual;	/* left in this buffer */
>  	struct scatterlist *buffer;	/* which buffer */
> +	dma_addr_t dma_handle;
> +	int this_residual;	/* left in this buffer */
>  	int buffers_residual;	/* how many buffers left */
>  
> -        dma_addr_t dma_handle;
> -
>  	volatile int Status;
>  	volatile int Message;
>  	volatile int have_data_in;
> @@ -40,7 +39,6 @@ struct scsi_cmnd {
>  	struct scsi_device *device;
>  	struct list_head list;  /* scsi_cmnd participates in queue lists */
>  	struct list_head eh_entry; /* entry for the host eh_cmd_q */
> -	int eh_eflags;		/* Used by error handlr */
>  
>  	/*
>  	 * A SCSI Command is assigned a nonzero serial_number before passed
> @@ -64,7 +62,9 @@ struct scsi_cmnd {
>  	int timeout_per_command;
>  
>  	unsigned char cmd_len;
> -	enum dma_data_direction sc_data_direction;
> +	unsigned char eh_eflags;		/* Used by error handler */
> +	unsigned char sc_data_direction;	/* enum dma_data_direction */
> +	unsigned char tag;	/* SCSI-II queued command tag */
>  
>  	/* These elements define the operation we are about to perform */
>  #define MAX_COMMAND_SIZE	16
> @@ -109,10 +109,6 @@ struct scsi_cmnd {
>  					 * obtained by scsi_malloc is guaranteed
>  					 * to be at an address < 16Mb). */
>  
> -	int result;		/* Status code from lower level driver */
> -
> -	unsigned char tag;	/* SCSI-II queued command tag */
> -
>  	union {
>  		struct scsi_data_buffer sdb;
>  		/*
> @@ -121,11 +117,12 @@ struct scsi_cmnd {
>  		 *        of struct scsi_data_buffer members.
>  		 */
>  		struct {
> +			void __deprecated *request_buffer;
>  			unsigned __deprecated request_bufflen;
>  			int __deprecated resid;
>  			unsigned short __deprecated use_sg;
>  			unsigned short __deprecated place_holder_sg_alloc;
> -			void __deprecated *request_buffer;
> +			int result; /* Status code from lower level driver */
>  		};
>  	};
>  };
> 


  reply	other threads:[~2007-10-18  7:00 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-17 17:14 [patchset 0/33] scsi_data_buffer for after the last driver is converted Boaz Harrosh
2007-10-17 17:19 ` [PATCH 1/32] arm: fas216 Use scsi_eh API for REQUEST_SENSE invocation Boaz Harrosh
2007-10-17 17:22 ` [PATCH 2/32] isd200.c: use one-element sg list in issuing commands Boaz Harrosh
2007-10-17 17:26 ` [PATCH 3/32] usb: transport - convert to accessors and !use_sg code path removal Boaz Harrosh
2007-10-17 17:29 ` [PATCH 4/32] usb: protocol.c " Boaz Harrosh
2007-10-17 17:32 ` [PATCH 5/32] usb: shuttle_usbat.c " Boaz Harrosh
2007-10-17 17:34 ` [PATCH 6/32] usb: freecom.c & sddr09.c - convert to accessors and !use_sg cleanup Boaz Harrosh
2007-10-17 17:37 ` [PATCH 7/32] NCR5380 familly convert to accessors & " Boaz Harrosh
2007-10-17 17:41 ` [PATCH 8/32] arm: scsi convert to accessors and " Boaz Harrosh
2007-10-17 17:43 ` [PATCH 9/32] nsp_cs.c convert to data " Boaz Harrosh
2007-10-17 17:45 ` [PATCH 10/32] eata_pio.c: convert to " Boaz Harrosh
2007-10-17 17:47 ` [PATCH 11/32] a2091.c: " Boaz Harrosh
2007-10-17 17:50 ` [PATCH 12/32] a3000.c: " Boaz Harrosh
2007-10-17 17:53 ` [PATCH 13/32] aha1542.c: " Boaz Harrosh
2007-11-10  2:30   ` Randy Dunlap
2007-11-10  2:32     ` Randy Dunlap
2007-10-17 17:55 ` [PATCH 14/32] atp870u.c: " Boaz Harrosh
2007-10-17 17:57 ` [PATCH 15/32] fd_mcs.c: " Boaz Harrosh
2007-10-17 17:59 ` [PATCH 16/32] imm.c: " Boaz Harrosh
2007-10-17 18:00 ` [PATCH 17/32] ppa.c: " Boaz Harrosh
2007-10-17 18:03 ` [PATCH 18/32] wd33c93.c: " Boaz Harrosh
2007-10-17 18:04 ` [PATCH 19/32] qlogicpti.c: " Boaz Harrosh
2007-10-17 18:05 ` [PATCH 20/32] in2000.c: " Boaz Harrosh
2007-10-17 18:07 ` [PATCH 21/32] qla1280: convert to use the data buffer accessors Boaz Harrosh
2007-10-17 18:10 ` [PATCH 22/32] qla1280: Indentation fix Boaz Harrosh
2007-10-17 22:15   ` Matthew Wilcox
2007-10-18 16:32   ` [PATCH 22/32 ver2] " Boaz Harrosh
2007-10-17 18:12 ` [PATCH 23/32] scsi_debug: convert to use the data buffer accessors Boaz Harrosh
2007-10-17 18:15 ` [PATCH 24/32] wd7000.c - proper fix for boards without sg support Boaz Harrosh
2007-10-17 18:17 ` [PATCH 25/32] Remove psi240i driver from kernel Boaz Harrosh
2007-10-17 18:18 ` [PATCH 26/32] Remove of seagate.c driver Boaz Harrosh
2007-10-17 18:21 ` [PATCH 27/32] scsi_data_buffer Boaz Harrosh
2007-10-17 23:40   ` FUJITA Tomonori
2007-10-18  7:51     ` Boaz Harrosh
2007-10-18  7:57       ` FUJITA Tomonori
2007-10-18  8:27         ` Boaz Harrosh
2007-10-18  8:45           ` FUJITA Tomonori
2007-10-18  9:17             ` FUJITA Tomonori
2007-10-18  0:47   ` Matthew Wilcox
2007-10-18  6:59     ` Benny Halevy [this message]
2007-10-18  8:06       ` Matthew Wilcox
2007-10-18  8:31         ` Benny Halevy
2007-10-18  8:16       ` Boaz Harrosh
2007-10-18  8:54         ` Matthew Wilcox
2007-10-18 10:21           ` Boaz Harrosh
2007-10-18 14:26           ` Alan Stern
2007-10-18 15:44             ` Matthew Wilcox
2007-10-17 18:23 ` [PATCH 28/32] scsi_data_buffer - scsi_error.c Boaz Harrosh
2007-10-17 18:25 ` [PATCH 29/32] scsi_data_buffer - sd.c and sr.c Boaz Harrosh
2007-10-17 18:28 ` [PATCH 30/32] tgt: convert to use scsi_data_buffer Boaz Harrosh
2007-10-17 18:30 ` [PATCH 31/32] tgt: convert ibmvstgt and libsrp " Boaz Harrosh
2007-10-17 18:32 ` [PATCH 32/32] isd200.c - use of scsi_data_buffer Boaz Harrosh
2007-10-17 23:32 ` [patchset 0/33] scsi_data_buffer for after the last driver is converted FUJITA Tomonori
2007-10-18  7:44 ` [PATCH 33/33] Remove Compatibility mode hack from scsi_cmnd Boaz Harrosh

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=4717046E.9040101@panasas.com \
    --to=bhalevy@panasas.com \
    --cc=James.Bottomley@SteelEye.com \
    --cc=bharrosh@panasas.com \
    --cc=davem@davemloft.net \
    --cc=hch@infradead.org \
    --cc=jens.axboe@oracle.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=mdharm-scsi@one-eyed-alien.net \
    --cc=pw@osc.edu \
    --cc=rmk@arm.linux.org.uk \
    --cc=stern@rowland.harvard.edu \
    --cc=tomof@acm.org \
    /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 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).