From: Douglas Gilbert <dgilbert@interlog.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-scsi@vger.kernel.org, martin.petersen@oracle.com,
jejb@linux.vnet.ibm.com, hare@suse.de, bvanassche@acm.org
Subject: Re: [PATCH v2 0/6] scsi: fix scsi_cmd::cmd_len
Date: Mon, 11 Apr 2022 23:05:34 -0400 [thread overview]
Message-ID: <67af49ba-0d39-d0f6-b6fb-cd49dd32bbb3@interlog.com> (raw)
In-Reply-To: <20220411155258.GA25715@lst.de>
On 2022-04-11 11:52, Christoph Hellwig wrote:
> On Mon, Apr 11, 2022 at 11:06:17AM -0400, Douglas Gilbert wrote:
>> On 2022-04-11 01:03, Christoph Hellwig wrote:
>>> This still misses any good explanation of why we want all this.
>>
>> Advantages:
>> - undoes regression in ce70fd9a551af, that is:
>> - cdb_len > 32 no longer allowed (visible to the user space), undone
>
> What exact regression causes this for real users and no just people
> playing around with scsi_debug?
Sorry, you are regressing something that has been in place for over
20 years and required by SPC (1 through 5) standards. The onus
should not be on me to prove that regression is not safe. It should
be the other way around (i.e. for you to prove that it is safe).
I admit that working with scsi_debug can be fun, but it seems to me a
few other people have found it a useful tool. Some football advice
might apply here: play the ball, not the man.
>> - but we still have this one:
>> - prior to lk5.18 sizeof(scsi_cmnd::cmnd) is that of a
>> pointer but >= lk5.18 sizeof(scsi_cmnd::cmnd) is 32 (or 16)
>
> Please check the total size of struct scsi_cmnd, which is what really
> matters.
From my laptop (64 bit) where scsi_cmnd1 is the original struct scsi_cmnd:
xtwo70 kernel: sizeof(struct scsi_cmnd)=376, sizeof(struct scsi_cmnd1)=392
So is slightly > 4% (higher on 32 bit machines) insignificant?
Since I have that measurement code in place, try a few other things ....
Changing scsi_cmnd::flags to be a u8 and putting sense_buffer and host_scribble
next to one another (they are pointers) gives:
xtwo70 kernel: sizeof(struct scsi_cmnd)=360, sizeof(struct scsi_cmnd1)=392
Now we are at a 8% reduction.
>
>> - makes all scsi_cmnd objects 16 bytes smaller
>
> Do we have data why this matters?
In commit ce70fd9a551af7424a7dace2a1ba05a7de8eae27 you wrote:
"Now that each scsi_request is backed by a scsi_cmnd, there is no need to
indirect the CDB storage. Change all submitters of SCSI passthrough
requests to store the CDB information directly in the scsi_cmnd, and while
doing so allocate the full 32 bytes that cover all Linux supported SCSI
hosts instead of requiring dynamic allocation for > 16 byte CDBs. On
64-bit systems this does not change the size of the scsi_cmnd at all, while
on 32-bit systems it slightly increases it for now, but that increase will
be made up by the removal of the remaining scsi_request fields."
$ cd drivers/scsi
$ find . -name '*.c' -exec grep "SCSI_MAX_VARLEN_CDB_SIZE" {} \; -print
shost->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE;
./iscsi_tcp.c
shost->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE;
./cxgbi/libcxgbi.c
include/scsi/scsi_proto.h:#define SCSI_MAX_VARLEN_CDB_SIZE 260
Two examples that make your "the full 32 bytes that cover all ..." assertion
false.
Also those quoted comments seem to give weight to the argument that
writer believes that the size of scsi_cmnd matters. If so, I agree,
smaller is better.
>> - hides the poorly named dtor for scsi_cmnd objects (blk_mq_free_request)
>> within a more intuitively named inline: scsi_free_cmnd
>
> I don't think this is in any way poorly named.
Seriously?
As well, having a scsi_cmnd destructor opens up the possibility of deferring
kmem_cache_free(scsi_sense_cache, cmd->sense_buffer) from scsi_mq_exit_request()
to that destructor. Then if scsi_cmnd objects are re-used,
scsi_mq_init_request() need only get a cmd->sense_buffer if one has not yet
been allocated. Again, I present no data, but pretty obviously a performance
win.
Another advantage of that patchset:
- in scsi_initialize_rq() the patch initializes CBD to Test Unit Ready
(6 zeros), previously it did a memset(scmd->cmnd, 0, 32), so that is
another small win.
That initialization could be further optimized with:
scmd->l_cdb.dummy_tur = 0; /* clears first 8 zeros */
scmd->cmd_len = SCSI_TEST_UNIT_READY_CDB_LEN;
to bypass memset() completely.
>> Disadvantages:
>> - burdens each access to a CDB with (scsi_cmnd::flags & SCMD_LONG_CDB)
>> check
>> - LLDs that want to fetch 32 byte CDBs (or longer) need to use the
>> scsi_cmnd_get_cdb() access function. For CDB lengths <= 16 bytes
>> they can continue to access scsi_cmnd::cmnd directly
>
> It adds back the dynamic allocation for 32-byte CDBs that we got rid of.
> It also breaks all LLDS actually using 32-byte CDBS currently as far as
> I can tell.
As Bart pointed out, the dynamic allocation for 32-byte CDBs is relatively
rare, more than made up for by the 4% reduction in struct scsi_cmnd's size.
As for the second sentence, if this patchset is accepted, I will find
and fix those. The ones I did check limited cdb_s to 16 bytes.
Doug Gilbert
next prev parent reply other threads:[~2022-04-12 3:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-10 17:36 [PATCH v2 0/6] scsi: fix scsi_cmd::cmd_len Douglas Gilbert
2022-04-10 17:36 ` [PATCH v2 1/6] scsi_cmnd: reinstate support for cmd_len > 32 Douglas Gilbert
2022-04-10 17:36 ` [PATCH v2 2/6] sd, sd_zbc: use scsi_cmnd cdb access functions Douglas Gilbert
2022-04-10 17:36 ` [PATCH v2 3/6] sg: reinstate cmd_len > 32 Douglas Gilbert
2022-04-10 17:36 ` [PATCH v2 4/6] bsg: allow " Douglas Gilbert
2022-04-10 17:36 ` [PATCH v2 5/6] scsi_debug: reinstate " Douglas Gilbert
2022-04-10 17:36 ` [PATCH v2 6/6] st,sr,stex: use scsi_cmnd cdb access functions Douglas Gilbert
2022-04-11 5:03 ` [PATCH v2 0/6] scsi: fix scsi_cmd::cmd_len Christoph Hellwig
2022-04-11 15:06 ` Douglas Gilbert
2022-04-11 15:52 ` Christoph Hellwig
2022-04-12 3:05 ` Douglas Gilbert [this message]
2022-04-19 3:26 ` 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=67af49ba-0d39-d0f6-b6fb-cd49dd32bbb3@interlog.com \
--to=dgilbert@interlog.com \
--cc=bvanassche@acm.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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