From 0060da5e836aabb5c627f7c89d6996fde5cd176b Mon Sep 17 00:00:00 2001 From: Mike Christie Date: Mon, 30 Jun 2008 18:10:20 -0500 Subject: [PATCH 11/12] libfc: mv scsi pkt cache to module A per host cache is overkill. For other storage drivers we do a cache per module. This moves the scsi pkt cache to the module instead of per host. Signed-off-by: Mike Christie --- drivers/scsi/libfc/fc_scsi.c | 78 +++++++++++++---------------------------- 1 files changed, 25 insertions(+), 53 deletions(-) diff --git a/drivers/scsi/libfc/fc_scsi.c b/drivers/scsi/libfc/fc_scsi.c index 66ca996..d67540d 100644 --- a/drivers/scsi/libfc/fc_scsi.c +++ b/drivers/scsi/libfc/fc_scsi.c @@ -38,6 +38,7 @@ #include int openfc_debug; +static struct kmem_cache *scsi_pkt_cachep; #define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr) #define CMD_ENTRY_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in) @@ -115,7 +116,6 @@ struct fc_cmdq { }; struct fc_scsi_internal { - struct kmem_cache *scsi_pkt_cachep; struct fc_cmdq outstandingcmd[FC_MAX_OUTSTANDING_COMMANDS]; int current_cmd_indx; ____cacheline_aligned spinlock_t outstandingcmd_lock; @@ -192,9 +192,8 @@ static void fc_scsi_srr_error(struct fc_scsi_pkt *, struct fc_frame *); static struct fc_scsi_pkt *fc_scsi_pkt_alloc(struct fc_lport *lp) { struct fc_scsi_pkt *sp; - struct fc_scsi_internal *si = fc_get_scsi_internal(lp); - sp = kmem_cache_zalloc(si->scsi_pkt_cachep, 0); + sp = kmem_cache_zalloc(scsi_pkt_cachep, 0); if (sp) { sp->lp = (void *)lp; atomic_set(&sp->ref_cnt, 1); @@ -214,15 +213,11 @@ static struct fc_scsi_pkt *fc_scsi_pkt_alloc(struct fc_lport *lp) */ static int fc_scsi_pkt_free(struct fc_scsi_pkt *sp) { - struct fc_lport *lp = sp->lp; - struct fc_scsi_internal *si = fc_get_scsi_internal(lp); - if (atomic_dec_and_test(&sp->ref_cnt)) { - if (sp->state == FC_SRB_FREE) { - kmem_cache_free(si->scsi_pkt_cachep, sp); - } else { + if (sp->state == FC_SRB_FREE) + kmem_cache_free(scsi_pkt_cachep, sp); + else FC_DBG("freeing scsi_pkt not marked free\n"); - } } return 0; } @@ -237,40 +232,6 @@ static void fc_scsi_pkt_release(struct fc_scsi_pkt *sp) fc_scsi_pkt_free(sp); } - -static int fc_destroy_scsi_slab(struct fc_lport *lp) -{ - int rc = -1; - struct fc_scsi_internal *si = fc_get_scsi_internal(lp); - - if (si->scsi_pkt_cachep != NULL) { - kmem_cache_destroy(si->scsi_pkt_cachep); - si->scsi_pkt_cachep = NULL; - rc = 0; - } - return rc; -} - -static int fc_create_scsi_slab(struct fc_lport *lp) -{ - struct fc_scsi_internal *si = fc_get_scsi_internal(lp); - char scsi_pkt_cachep_name[FC_SRB_CACHEP_NAME]; - - sprintf(scsi_pkt_cachep_name, "openfc%d", lp->host->host_no); - - si->scsi_pkt_cachep = - kmem_cache_create(scsi_pkt_cachep_name, - sizeof(struct fc_scsi_pkt) + - 0, 0, SLAB_HWCACHE_ALIGN, - NULL); - - if (si->scsi_pkt_cachep == NULL) { - FC_DBG("Unable to allocate SRB cache...module load failed!"); - return -ENOMEM; - } - return 0; -} - /* * Lock fc_scsi_pkt. * The outstandingcmd queue lock is used to serialize access to the fc_scsi_pkt. @@ -2152,7 +2113,6 @@ EXPORT_SYMBOL(fc_change_queue_type); */ void fc_put_dev(struct fc_lport *lp) { - fc_destroy_scsi_slab(lp); kfree(fc_get_scsi_internal(lp)); lp->scsi_priv = NULL; } @@ -2176,14 +2136,6 @@ int fc_scsi_init(struct fc_lport *lp, lp->scsi_priv = si; /* - * create slab for pkt buffer - */ - if (fc_create_scsi_slab(lp) < 0) { - FC_DBG("scsi pkt slab create failed"); - return -1; - } - - /* * we will use openfc's scsi i/f only when lower level driver * does not have a fast path. */ @@ -2200,3 +2152,23 @@ int fc_scsi_init(struct fc_lport *lp, return 0; } EXPORT_SYMBOL(fc_scsi_init); + +static int __init libfc_init(void) +{ + scsi_pkt_cachep = kmem_cache_create("libfc_scsi_pkt", + sizeof(struct fc_scsi_pkt), + 0, SLAB_HWCACHE_ALIGN, NULL); + if (scsi_pkt_cachep == NULL) { + FC_DBG("Unable to allocate SRB cache...module load failed!"); + return -ENOMEM; + } + return 0; +} + +static void __exit libfc_exit(void) +{ + kmem_cache_destroy(scsi_pkt_cachep); +} + +module_init(libfc_init); +module_exit(libfc_exit); -- 1.5.4.1