tcmu: Recalculate the tcmu_cmd size to save cmd area memories
authorXiubo Li <lixiubo@cmss.chinamobile.com>
Tue, 2 May 2017 07:54:29 +0000 (15:54 +0800)
committerNicholas Bellinger <nab@linux-iscsi.org>
Wed, 3 May 2017 03:39:38 +0000 (20:39 -0700)
commitfe25cc347959b1efd18ee150165416aa6ed0ecdd
treea4fa2f4f8394a0c9bcc7b8909b7854a6d0c05ec5
parentb6df4b79a5514a9c6c53533436704129ef45bf76
tcmu: Recalculate the tcmu_cmd size to save cmd area memories

For the "struct tcmu_cmd_entry" in cmd area, the minimum size
will be sizeof(struct tcmu_cmd_entry) == 112 Bytes. And it could
fill about (sizeof(struct rsp) - sizeof(struct req)) /
sizeof(struct iovec) == 68 / 16 ~= 4 data regions(iov[4]) by
default.

For most tcmu_cmds, the data block indexes allocated from the
data area will be continuous. And for the continuous blocks they
will be merged into the same region using only one iovec. For
the current code, it will always allocates the same number of
iovecs with blocks for each tcmu_cmd, and it will wastes much
memories.

For example, when the block size is 4K and the DATA_OUT buffer
size is 64K, and the regions needed is less than 5(on my
environment is almost 99.7%). The current code will allocate
about 16 iovecs, and there will be (16 - 4) * sizeof(struct
iovec) = 192 Bytes cmd area memories wasted.

Here adds two helpers to calculate the base size and full size
of the tcmu_cmd. And will recalculate them again when it make sure
how many iovs is needed before insert it to cmd area.

Signed-off-by: Xiubo Li <lixiubo@cmss.chinamobile.com>
Acked-by: Mike Christie <mchristi@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_user.c