From e641e8f3f6ac24839dab7ff7af480fb293c6ca08 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 21 Mar 2023 20:35:44 +0800 Subject: [PATCH] lib/ublk: use page aligned data buffer Kernel `ublk_drv` driver will do memcpy to this data buffer in unit of page size, for a simple 4KiB I/O, it may call memcpy twice if the data buffer isn't page aligned. Moreover, SPDK may also has double buffers with this case, so here, we use page aligned data buffer at initialization. Change-Id: Ica86a9702283327a2bb491e38990b8c00bc77f57 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17283 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris --- lib/ublk/ublk.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/ublk/ublk.c b/lib/ublk/ublk.c index 6b410d9f9..c09b6a085 100644 --- a/lib/ublk/ublk.c +++ b/lib/ublk/ublk.c @@ -65,6 +65,7 @@ __attribute__((unused)) = { struct ublk_io { void *payload; + void *mpool_entry; uint32_t payload_size; uint32_t cmd_op; int32_t result; @@ -1262,8 +1263,7 @@ ublk_ios_fini(struct spdk_ublk_dev *ublk) for (i = 0; i < q->q_depth; i++) { if (q->ios[i].payload) { - spdk_mempool_put(ublk->io_buf_pool, q->ios[i].payload); - q->ios[i].payload = NULL; + spdk_mempool_put(ublk->io_buf_pool, q->ios[i].mpool_entry); } } free(q->ios); @@ -1286,8 +1286,8 @@ ublk_ios_init(struct spdk_ublk_dev *ublk) /* Create a mempool to allocate buf for each io */ ublk->io_buf_pool = spdk_mempool_create(mempool_name, ublk->num_queues * ublk->queue_depth, - UBLK_IO_MAX_BYTES, - 0, + UBLK_IO_MAX_BYTES + 4096, + SPDK_MEMPOOL_DEFAULT_CACHE_SIZE, SPDK_ENV_SOCKET_ID_ANY); if (ublk->io_buf_pool == NULL) { rc = -ENOMEM; @@ -1311,7 +1311,9 @@ ublk_ios_init(struct spdk_ublk_dev *ublk) } for (j = 0; j < q->q_depth; j++) { q->ios[j].q = q; - q->ios[j].payload = spdk_mempool_get(ublk->io_buf_pool); + q->ios[j].mpool_entry = spdk_mempool_get(ublk->io_buf_pool); + q->ios[j].payload = (void *)(uintptr_t)SPDK_ALIGN_CEIL((uint64_t)(uintptr_t)q->ios[j].mpool_entry, + 4096ULL); } }