Skip to contentSkip to conversation

scsi-mq: Pre-allocation of sg tables base on min(host->hostt->sg_tablesize,SCSI_MQ_MAX_SG_SEGMENTS).

PATCH Applied majianpeng 2 participants 2 messages Nov 29, 2013 – Dec 23, 2013 SCSI

lore
Share & tools
lore

majianpeng

author
#0 lore raw

PATCH 6/6 scsi-mq: Pre-allocation of sg tables base on min(host->hostt->sg_tablesize,SCSI_MQ_MAX_SG_SEGMENTS).

---
 drivers/scsi/scsi-mq.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/scsi/scsi-mq.c +10 -3
index 78b05c1..7b8137b 100644
@@ -154,6 +154,7 @@ int scsi_mq_alloc_queue(struct Scsi_Host *sh, struct scsi_device *sdev)
 	struct request *rq;
 	struct scsi_cmnd *sc;
 	int i, j;
+	int sgl_size;
 
 	sdev->sdev_mq_reg.ops = &scsi_mq_ops;
 	sdev->sdev_mq_reg.queue_depth = min((short)sh->hostt->can_queue,
@@ -186,13 +187,20 @@ int scsi_mq_alloc_queue(struct Scsi_Host *sh, struct scsi_device *sdev)
 	 * Set existing Scsi_Host based hardware limits from scsi_lib.c
 	 */
 	scsi_init_request_queue(q, sh);
+
+	if (sh->hostt->sg_tablesize > SCSI_MQ_MAX_SG_SEGMENTS) {
+		printk(KERN_ERR"Host%d sg_tablesize too larger than %d\n",
+			sh->host_no, SCSI_MQ_MAX_SG_SEGMENTS);
+		sh->hostt->sg_tablesize = SCSI_MQ_MAX_SG_SEGMENTS;
+	}
+	sgl_size = sh->hostt->sg_tablesize * sizeof(struct scatterlist);
+
 	/*
 	 * Do remaining setup of pre-allocated scsi_cmnd descriptor map for
 	 * each scsi-mq hctx
 	 */
 //FIXME: Do cmd->prot_sdb setup for DIF from scsi_host_alloc_command
 	queue_for_each_hw_ctx(q, hctx, i) {
-
 		printk("Performing sc map setup on q: %p hctx: %p i: %d\n", q, hctx, i);
 
 		for (j = 0; j < hctx->queue_depth; j++) {
@@ -201,8 +209,7 @@ int scsi_mq_alloc_queue(struct Scsi_Host *sh, struct scsi_device *sdev)
 			sc->device = sdev;
 			sc->ll_list.next = NULL;
 
-//FIXME: Pre-allocation of sg tables based upon max_sectors
-			sc->mq_sgl = kzalloc_node(SCSI_MQ_SGL_SIZE,
+			sc->mq_sgl = kzalloc_node(sgl_size,
 					GFP_KERNEL, sdev->sdev_mq_reg.numa_node);
 			if (!sc->mq_sgl) {
 				pr_err("Unable to pre-allocate sc->sdb\n");
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines · majianpeng
---
 drivers/scsi/scsi-mq.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Applied, + squashed into current target-pending/scsi-mq code.

Thanks Jianpeng!

--nab

Quoted 44 lines
drivers/scsi/scsi-mq.c +10 -3
index 78b05c1..7b8137b 100644
@@ -154,6 +154,7 @@ int scsi_mq_alloc_queue(struct Scsi_Host *sh, struct scsi_device *sdev)
 	struct request *rq;
 	struct scsi_cmnd *sc;
 	int i, j;
+	int sgl_size;
 
 	sdev->sdev_mq_reg.ops = &scsi_mq_ops;
 	sdev->sdev_mq_reg.queue_depth = min((short)sh->hostt->can_queue,
@@ -186,13 +187,20 @@ int scsi_mq_alloc_queue(struct Scsi_Host *sh, struct scsi_device *sdev)
 	 * Set existing Scsi_Host based hardware limits from scsi_lib.c
 	 */
 	scsi_init_request_queue(q, sh);
+
+	if (sh->hostt->sg_tablesize > SCSI_MQ_MAX_SG_SEGMENTS) {
+		printk(KERN_ERR"Host%d sg_tablesize too larger than %d\n",
+			sh->host_no, SCSI_MQ_MAX_SG_SEGMENTS);
+		sh->hostt->sg_tablesize = SCSI_MQ_MAX_SG_SEGMENTS;
+	}
+	sgl_size = sh->hostt->sg_tablesize * sizeof(struct scatterlist);
+
 	/*
 	 * Do remaining setup of pre-allocated scsi_cmnd descriptor map for
 	 * each scsi-mq hctx
 	 */
 //FIXME: Do cmd->prot_sdb setup for DIF from scsi_host_alloc_command
 	queue_for_each_hw_ctx(q, hctx, i) {
-
 		printk("Performing sc map setup on q: %p hctx: %p i: %d\n", q, hctx, i);
 
 		for (j = 0; j < hctx->queue_depth; j++) {
@@ -201,8 +209,7 @@ int scsi_mq_alloc_queue(struct Scsi_Host *sh, struct scsi_device *sdev)
 			sc->device = sdev;
 			sc->ll_list.next = NULL;
 
-//FIXME: Pre-allocation of sg tables based upon max_sectors
-			sc->mq_sgl = kzalloc_node(SCSI_MQ_SGL_SIZE,
+			sc->mq_sgl = kzalloc_node(sgl_size,
 					GFP_KERNEL, sdev->sdev_mq_reg.numa_node);
 			if (!sc->mq_sgl) {
 				pr_err("Unable to pre-allocate sc->sdb\n");