All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@fb.com>
Cc: Mike Snitzer <snitzer@redhat.com>,
	Junichi Nomura <j-nomura@ce.jp.nec.com>,
	linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-raid@vger.kernel.org, dm-devel@redhat.com
Subject: [PATCH 12/18] scsi: respect unchecked_isa_dma for blk-mq
Date: Wed, 25 Jan 2017 18:25:20 +0100	[thread overview]
Message-ID: <1485365126-23210-13-git-send-email-hch@lst.de> (raw)
In-Reply-To: <1485365126-23210-1-git-send-email-hch@lst.de>

Currently blk-mq always allocates the sense buffer using normal GFP_KERNEL
allocation.  Refactor the cmd pool code to split the cmd and sense allocation
and share the code to allocate the sense buffers as well as the sense buffer
slab caches between the legacy and blk-mq path.

Note that this switches to lazy allocation of the sense slab caches - the
slab caches (not the actual allocations) won't be destroy until the scsi
module is unloaded instead of keeping track of hosts using them.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/hosts.c     |  4 ++++
 drivers/scsi/scsi.c      | 24 ++++---------------
 drivers/scsi/scsi_lib.c  | 62 +++++++++++++++++++++++++++++++++++++++++++++---
 drivers/scsi/scsi_priv.h |  5 ++++
 4 files changed, 73 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 258a3f9..6d29c4a 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -213,6 +213,10 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
 		goto fail;
 	}
 
+	error = scsi_init_sense_cache(shost);
+	if (error)
+		goto fail;
+
 	if (shost_use_blk_mq(shost)) {
 		error = scsi_mq_setup_tags(shost);
 		if (error)
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 0f93892..469aa0f 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -100,22 +100,18 @@ EXPORT_SYMBOL(scsi_sd_pm_domain);
 
 struct scsi_host_cmd_pool {
 	struct kmem_cache	*cmd_slab;
-	struct kmem_cache	*sense_slab;
 	unsigned int		users;
 	char			*cmd_name;
-	char			*sense_name;
 	unsigned int		slab_flags;
 };
 
 static struct scsi_host_cmd_pool scsi_cmd_pool = {
 	.cmd_name	= "scsi_cmd_cache",
-	.sense_name	= "scsi_sense_cache",
 	.slab_flags	= SLAB_HWCACHE_ALIGN,
 };
 
 static struct scsi_host_cmd_pool scsi_cmd_dma_pool = {
 	.cmd_name	= "scsi_cmd_cache(DMA)",
-	.sense_name	= "scsi_sense_cache(DMA)",
 	.slab_flags	= SLAB_HWCACHE_ALIGN|SLAB_CACHE_DMA,
 };
 
@@ -136,7 +132,7 @@ scsi_host_free_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
 
 	if (cmd->prot_sdb)
 		kmem_cache_free(scsi_sdb_cache, cmd->prot_sdb);
-	kmem_cache_free(pool->sense_slab, cmd->sense_buffer);
+	scsi_free_sense_buffer(shost, cmd->sense_buffer);
 	kmem_cache_free(pool->cmd_slab, cmd);
 }
 
@@ -158,7 +154,8 @@ scsi_host_alloc_command(struct Scsi_Host *shost, gfp_t gfp_mask)
 	if (!cmd)
 		goto fail;
 
-	cmd->sense_buffer = kmem_cache_alloc(pool->sense_slab, gfp_mask);
+	cmd->sense_buffer = scsi_alloc_sense_buffer(shost, gfp_mask,
+			NUMA_NO_NODE);
 	if (!cmd->sense_buffer)
 		goto fail_free_cmd;
 
@@ -171,7 +168,7 @@ scsi_host_alloc_command(struct Scsi_Host *shost, gfp_t gfp_mask)
 	return cmd;
 
 fail_free_sense:
-	kmem_cache_free(pool->sense_slab, cmd->sense_buffer);
+	scsi_free_sense_buffer(shost, cmd->sense_buffer);
 fail_free_cmd:
 	kmem_cache_free(pool->cmd_slab, cmd);
 fail:
@@ -301,7 +298,6 @@ scsi_find_host_cmd_pool(struct Scsi_Host *shost)
 static void
 scsi_free_host_cmd_pool(struct scsi_host_cmd_pool *pool)
 {
-	kfree(pool->sense_name);
 	kfree(pool->cmd_name);
 	kfree(pool);
 }
@@ -317,8 +313,7 @@ scsi_alloc_host_cmd_pool(struct Scsi_Host *shost)
 		return NULL;
 
 	pool->cmd_name = kasprintf(GFP_KERNEL, "%s_cmd", hostt->proc_name);
-	pool->sense_name = kasprintf(GFP_KERNEL, "%s_sense", hostt->proc_name);
-	if (!pool->cmd_name || !pool->sense_name) {
+	if (!pool->cmd_name) {
 		scsi_free_host_cmd_pool(pool);
 		return NULL;
 	}
@@ -357,12 +352,6 @@ scsi_get_host_cmd_pool(struct Scsi_Host *shost)
 						   pool->slab_flags, NULL);
 		if (!pool->cmd_slab)
 			goto out_free_pool;
-
-		pool->sense_slab = kmem_cache_create(pool->sense_name,
-						     SCSI_SENSE_BUFFERSIZE, 0,
-						     pool->slab_flags, NULL);
-		if (!pool->sense_slab)
-			goto out_free_slab;
 	}
 
 	pool->users++;
@@ -371,8 +360,6 @@ scsi_get_host_cmd_pool(struct Scsi_Host *shost)
 	mutex_unlock(&host_cmd_pool_mutex);
 	return retval;
 
-out_free_slab:
-	kmem_cache_destroy(pool->cmd_slab);
 out_free_pool:
 	if (hostt->cmd_size) {
 		scsi_free_host_cmd_pool(pool);
@@ -398,7 +385,6 @@ static void scsi_put_host_cmd_pool(struct Scsi_Host *shost)
 
 	if (!--pool->users) {
 		kmem_cache_destroy(pool->cmd_slab);
-		kmem_cache_destroy(pool->sense_slab);
 		if (hostt->cmd_size) {
 			scsi_free_host_cmd_pool(pool);
 			hostt->cmd_pool = NULL;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index e9e1e14..3d6b364 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -39,6 +39,58 @@
 
 
 struct kmem_cache *scsi_sdb_cache;
+static struct kmem_cache *scsi_sense_cache;
+static struct kmem_cache *scsi_sense_isadma_cache;
+static DEFINE_MUTEX(scsi_sense_cache_mutex);
+
+static inline struct kmem_cache *
+scsi_select_sense_cache(struct Scsi_Host *shost)
+{
+	return shost->unchecked_isa_dma ?
+		scsi_sense_isadma_cache : scsi_sense_cache;
+}
+
+void scsi_free_sense_buffer(struct Scsi_Host *shost,
+		unsigned char *sense_buffer)
+{
+	kmem_cache_free(scsi_select_sense_cache(shost), sense_buffer);
+}
+
+unsigned char *scsi_alloc_sense_buffer(struct Scsi_Host *shost, gfp_t gfp_mask,
+		int numa_node)
+{
+	return kmem_cache_alloc_node(scsi_select_sense_cache(shost), gfp_mask,
+			numa_node);
+}
+
+int scsi_init_sense_cache(struct Scsi_Host *shost)
+{
+	struct kmem_cache *cache;
+	int ret = 0;
+
+	cache = scsi_select_sense_cache(shost);
+	if (cache)
+		return 0;
+
+	mutex_lock(&scsi_sense_cache_mutex);
+	if (shost->unchecked_isa_dma) {
+		scsi_sense_isadma_cache =
+			kmem_cache_create("scsi_sense_cache(DMA)",
+			SCSI_SENSE_BUFFERSIZE, 0,
+			SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA, NULL);
+		if (!scsi_sense_isadma_cache)
+			ret = -ENOMEM;
+	} else {
+		scsi_sense_cache =
+			kmem_cache_create("scsi_sense_cache",
+			SCSI_SENSE_BUFFERSIZE, 0, SLAB_HWCACHE_ALIGN, NULL);
+		if (!scsi_sense_cache)
+			ret = -ENOMEM;
+	}
+
+	mutex_unlock(&scsi_sense_cache_mutex);
+	return ret;
+}
 
 /*
  * When to reinvoke queueing after a resource shortage. It's 3 msecs to
@@ -1981,10 +2033,11 @@ static int scsi_init_request(void *data, struct request *rq,
 		unsigned int hctx_idx, unsigned int request_idx,
 		unsigned int numa_node)
 {
+	struct Scsi_Host *shost = data;
 	struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
 
-	cmd->sense_buffer = kzalloc_node(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL,
-			numa_node);
+	cmd->sense_buffer =
+		scsi_alloc_sense_buffer(shost, GFP_KERNEL, numa_node);
 	if (!cmd->sense_buffer)
 		return -ENOMEM;
 	return 0;
@@ -1993,9 +2046,10 @@ static int scsi_init_request(void *data, struct request *rq,
 static void scsi_exit_request(void *data, struct request *rq,
 		unsigned int hctx_idx, unsigned int request_idx)
 {
+	struct Scsi_Host *shost = data;
 	struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
 
-	kfree(cmd->sense_buffer);
+	scsi_free_sense_buffer(shost, cmd->sense_buffer);
 }
 
 static int scsi_map_queues(struct blk_mq_tag_set *set)
@@ -2208,6 +2262,8 @@ int __init scsi_init_queue(void)
 
 void scsi_exit_queue(void)
 {
+	kmem_cache_destroy(scsi_sense_cache);
+	kmem_cache_destroy(scsi_sense_isadma_cache);
 	kmem_cache_destroy(scsi_sdb_cache);
 }
 
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 193636a..1a712c6 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -30,6 +30,11 @@ extern void scsi_exit_hosts(void);
 
 /* scsi.c */
 extern bool scsi_use_blk_mq;
+void scsi_free_sense_buffer(struct Scsi_Host *shost,
+		unsigned char *sense_buffer);
+unsigned char *scsi_alloc_sense_buffer(struct Scsi_Host *shost, gfp_t gfp_mask,
+		int numa_node);
+int scsi_init_sense_cache(struct Scsi_Host *shost);
 extern int scsi_setup_command_freelist(struct Scsi_Host *shost);
 extern void scsi_destroy_command_freelist(struct Scsi_Host *shost);
 #ifdef CONFIG_SCSI_LOGGING
-- 
2.1.4


  parent reply	other threads:[~2017-01-25 17:25 UTC|newest]

Thread overview: 172+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-25 17:25 split scsi passthrough fields out of struct request V2 Christoph Hellwig
2017-01-25 17:25 ` [PATCH 01/18] block: add a op_is_flush helper Christoph Hellwig
2017-01-26  2:58   ` Martin K. Petersen
2017-01-26 22:38   ` Bart Van Assche
2017-01-25 17:25 ` [PATCH 02/18] md: cleanup bio op / flags handling in raid1_write_request Christoph Hellwig
2017-01-26  2:59   ` Martin K. Petersen
2017-01-26 23:18   ` Bart Van Assche
2017-01-26 23:18     ` Bart Van Assche
2017-01-25 17:25 ` [PATCH 03/18] block: fix elevator init check Christoph Hellwig
2017-01-26  3:01   ` Martin K. Petersen
2017-01-26 23:21   ` Bart Van Assche
2017-01-26 23:21     ` Bart Van Assche
2017-01-25 17:25 ` [PATCH 04/18] block: simplify blk_init_allocated_queue Christoph Hellwig
2017-01-26  3:02   ` Martin K. Petersen
2017-01-26 23:27   ` Bart Van Assche
2017-01-26 23:27     ` Bart Van Assche
2017-01-25 17:25 ` [PATCH 05/18] block: allow specifying size for extra command data Christoph Hellwig
2017-01-26  3:15   ` Martin K. Petersen
2017-01-27 16:12     ` Christoph Hellwig
2017-01-27 16:12       ` Christoph Hellwig
2017-01-27 17:21       ` Bart Van Assche
2017-01-27 17:21         ` Bart Van Assche
2017-01-27 17:26         ` Jens Axboe
2017-01-27 17:26           ` Jens Axboe
2017-01-27 17:30           ` Bart Van Assche
2017-01-27 17:30             ` Bart Van Assche
2017-01-27 17:33             ` Jens Axboe
2017-01-25 17:25 ` [PATCH 06/18] dm: remove incomple BLOCK_PC support Christoph Hellwig
2017-01-27 17:32   ` Bart Van Assche
2017-01-27 17:32     ` Bart Van Assche
2017-01-25 17:25 ` [PATCH 07/18] dm: always defer request allocation to the owner of the request_queue Christoph Hellwig
2017-01-27 16:34   ` Mike Snitzer
2017-01-27 16:34     ` Mike Snitzer
2017-01-27 16:36     ` Christoph Hellwig
2017-01-27 16:36       ` Christoph Hellwig
2017-01-27 16:44       ` Mike Snitzer
2017-01-27 16:44         ` Mike Snitzer
2017-01-25 17:25 ` [PATCH 08/18] scsi_dh_rdac: switch to scsi_execute_req_flags() Christoph Hellwig
2017-01-26  3:18   ` Martin K. Petersen
2017-01-25 17:25 ` [PATCH 09/18] scsi_dh_emc: " Christoph Hellwig
2017-01-26  3:19   ` Martin K. Petersen
2017-01-25 17:25 ` [PATCH 10/18] scsi_dh_hp_sw: " Christoph Hellwig
2017-01-26  3:20   ` Martin K. Petersen
2017-01-26  3:20     ` Martin K. Petersen
2017-01-25 17:25 ` [PATCH 11/18] scsi: remove gfp_flags member in scsi_host_cmd_pool Christoph Hellwig
2017-01-26  3:21   ` Martin K. Petersen
2017-01-27 17:38   ` Bart Van Assche
2017-01-27 17:38     ` Bart Van Assche
2017-01-25 17:25 ` Christoph Hellwig [this message]
2017-01-26  3:23   ` [PATCH 12/18] scsi: respect unchecked_isa_dma for blk-mq Martin K. Petersen
2017-01-27 17:45   ` Bart Van Assche
2017-01-27 17:45     ` Bart Van Assche
2017-01-25 17:25 ` [PATCH 13/18] scsi: remove scsi_cmd_dma_pool Christoph Hellwig
2017-01-26  3:24   ` Martin K. Petersen
2017-01-27 17:51   ` Bart Van Assche
2017-01-27 17:51     ` Bart Van Assche
2017-01-25 17:25 ` [PATCH 14/18] scsi: remove __scsi_alloc_queue Christoph Hellwig
2017-01-26  3:25   ` Martin K. Petersen
2017-01-27 17:58   ` Bart Van Assche
2017-01-27 17:58     ` Bart Van Assche
2017-01-28  8:23     ` hch
2017-01-25 17:25 ` [PATCH 15/18] scsi: allocate scsi_cmnd structures as part of struct request Christoph Hellwig
2017-01-26  3:30   ` Martin K. Petersen
2017-01-27 18:39   ` Bart Van Assche
2017-01-27 18:39     ` Bart Van Assche
2017-01-28  8:25     ` hch
2017-01-28  8:25       ` hch
2017-01-25 17:25 ` [PATCH 16/18] block/bsg: move queue creation into bsg_setup_queue Christoph Hellwig
2017-01-27 18:48   ` Bart Van Assche
2017-01-27 18:48     ` Bart Van Assche
2017-01-25 17:25 ` [PATCH 17/18] block: split scsi_request out of struct request Christoph Hellwig
2017-01-25 17:25 ` [PATCH 18/18] block: don't assign cmd_flags in __blk_rq_prep_clone Christoph Hellwig
2017-01-26  3:31   ` Martin K. Petersen
2017-01-26 18:29 ` split scsi passthrough fields out of struct request V2 Bart Van Assche
2017-01-26 18:29   ` Bart Van Assche
2017-01-26 18:44   ` Jens Axboe
2017-01-26 18:52     ` Bart Van Assche
2017-01-26 18:52       ` Bart Van Assche
2017-01-26 18:57       ` Jens Axboe
2017-01-26 18:59         ` hch
2017-01-26 19:01           ` Jens Axboe
2017-01-26 19:01             ` Jens Axboe
2017-01-26 20:47             ` [dm-devel] " Bart Van Assche
2017-01-26 20:54               ` Jens Axboe
2017-01-26 20:54                 ` [dm-devel] " Jens Axboe
2017-01-26 21:01                 ` Bart Van Assche
2017-01-26 21:01                   ` Bart Van Assche
2017-01-26 21:12                   ` Jens Axboe
2017-01-26 21:12                     ` [dm-devel] " Jens Axboe
2017-01-26 21:47                     ` Bart Van Assche
2017-01-26 21:47                       ` [dm-devel] " Bart Van Assche
2017-01-26 21:51                       ` Jens Axboe
2017-01-26 21:51                         ` [dm-devel] " Jens Axboe
2017-01-26 23:14                         ` Bart Van Assche
2017-01-26 23:14                           ` Bart Van Assche
2017-01-26 23:26                           ` Jens Axboe
2017-01-26 23:26                             ` Jens Axboe
2017-01-26 23:26                             ` [dm-devel] " Jens Axboe
2017-01-26 23:47                             ` Bart Van Assche
2017-01-26 23:47                               ` [dm-devel] " Bart Van Assche
2017-01-26 23:50                               ` Jens Axboe
2017-01-27  0:33                                 ` Jens Axboe
2017-01-27  0:33                                   ` [dm-devel] " Jens Axboe
2017-01-27  0:38                                 ` Bart Van Assche
2017-01-27  0:38                                   ` Bart Van Assche
2017-01-27  0:41                                   ` Jens Axboe
2017-01-27  1:15                                     ` Bart Van Assche
2017-01-27  1:15                                       ` [dm-devel] " Bart Van Assche
2017-01-27  1:22                                       ` Jens Axboe
2017-01-27  1:22                                         ` [dm-devel] " Jens Axboe
2017-01-27  6:40                                         ` Jens Axboe
2017-01-27  8:04                                           ` Jens Axboe
2017-01-27  8:04                                             ` [dm-devel] " Jens Axboe
2017-01-27 16:52                                             ` Bart Van Assche
2017-01-27 16:52                                               ` [dm-devel] " Bart Van Assche
2017-01-27 16:56                                               ` Jens Axboe
2017-01-27 16:56                                                 ` [dm-devel] " Jens Axboe
2017-01-27 17:03                                                 ` Bart Van Assche
2017-01-27 17:03                                                   ` [dm-devel] " Bart Van Assche
2017-01-31  1:12                                                 ` Bart Van Assche
2017-01-31  1:12                                                   ` Bart Van Assche
2017-01-31  1:38                                                   ` Jens Axboe
2017-01-31  1:38                                                     ` Jens Axboe
2017-01-31  4:13                                                     ` Jens Axboe
2017-01-31  4:13                                                       ` [dm-devel] " Jens Axboe
2017-01-31 21:35                                                     ` Bart Van Assche
2017-01-31 21:35                                                       ` Bart Van Assche
2017-01-31 21:55                                                       ` Bart Van Assche
2017-01-31 21:55                                                         ` Bart Van Assche
2017-01-31 21:58                                                         ` Jens Axboe
2017-02-01  1:01                                                           ` Bart Van Assche
2017-02-01  6:38                                                             ` Jens Axboe
2017-02-01 16:46                                                               ` Bart Van Assche
2017-02-01 17:13                                                                 ` Jens Axboe
2017-02-01 17:28                                                                   ` Bart Van Assche
2017-02-01 19:21                                                                   ` Bart Van Assche
2017-02-01 22:01                                                                   ` Bart Van Assche
2017-02-02 17:27                                                                     ` Bart Van Assche
2017-02-02 18:33                                                                       ` Mike Snitzer
2017-02-02 18:43                                                                         ` Bart Van Assche
2017-02-02 19:13                                                                           ` Mike Snitzer
2017-02-02 19:46                                                                             ` Bart Van Assche
2017-02-02 21:04                                                                               ` Mike Snitzer
2017-02-02 21:10                                                                                 ` Mike Snitzer
2017-02-03  0:20                                                                                   ` Bart Van Assche
2017-02-03  0:42                                                                                     ` Mike Snitzer
2017-02-02 22:38                                                                                 ` Bart Van Assche
2017-01-27 17:02                                         ` [dm-devel] " Bart Van Assche
2017-01-27 17:02                                           ` Bart Van Assche
2017-01-27 16:11 ` Jens Axboe
2017-01-27 16:11   ` Jens Axboe
2017-01-27 16:17   ` Christoph Hellwig
2017-01-27 16:17     ` Christoph Hellwig
2017-01-27 16:21     ` Jens Axboe
2017-01-27 16:21       ` Jens Axboe
2017-01-27 16:23       ` Christoph Hellwig
2017-01-27 16:23         ` Christoph Hellwig
2017-01-27 16:27         ` Jens Axboe
2017-01-27 16:27           ` Jens Axboe
2017-01-27 16:34           ` Christoph Hellwig
2017-01-27 16:34             ` Christoph Hellwig
2017-01-27 16:38             ` Jens Axboe
2017-01-27 16:38               ` Jens Axboe
2017-01-27 16:42               ` Christoph Hellwig
2017-01-27 16:42                 ` Christoph Hellwig
2017-01-27 16:58                 ` Jens Axboe
2017-01-27 16:58                   ` Jens Axboe
2017-01-27 21:27 ` Bart Van Assche
2017-01-27 21:27   ` Bart Van Assche
2017-01-28  8:29   ` hch
2017-01-30  6:58   ` Hannes Reinecke
2017-01-30  6:58     ` Hannes Reinecke

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=1485365126-23210-13-git-send-email-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@fb.com \
    --cc=dm-devel@redhat.com \
    --cc=j-nomura@ce.jp.nec.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=snitzer@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.