From patchwork Mon Dec 7 12:16:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwei Tao X-Patchwork-Id: 7783291 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 180339F350 for ; Mon, 7 Dec 2015 12:23:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E2CD12049E for ; Mon, 7 Dec 2015 12:23:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B908203F3 for ; Mon, 7 Dec 2015 12:23:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755655AbbLGMXC (ORCPT ); Mon, 7 Dec 2015 07:23:02 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:33912 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932236AbbLGMXB (ORCPT ); Mon, 7 Dec 2015 07:23:01 -0500 Received: by pfbg73 with SMTP id g73so66089437pfb.1; Mon, 07 Dec 2015 04:23:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4eTWYKvKtNgRw51TzinE9LicETk9ZJW9P/lKBwHdBHE=; b=IW92BVnEqG9JnFbU7bQWXFlaJSEY4zIfwi5isKmyMlhib+bi7wob9V4xL3DHu3AHsm Jbb+A0vI6x56c0NewKOPJWP0Zh7KS/1UkEaKfw05yzm62CUTl3cMM64fogvYXsEZEG6o oOoOa5FIdk698fLC9Eq3gaXh8pxkHpegn5g6lFd7BDCN8QdDfxTb3+OtNdhOvVkeyEoZ 9cKY3TYoJOunb4uKxa5UV0GJg1TyCN4ST8Cry2qFA0Z/LtwJ70srzVcp0hRusApwYurg JH0Lq6WgB6xZe7WPd4G8uzkPglfm+lH3X1tP5C1HAncch5p5YzUsPC29+GMYCIDeg7Rh NppQ== X-Received: by 10.98.8.20 with SMTP id c20mr42551578pfd.65.1449490588597; Mon, 07 Dec 2015 04:16:28 -0800 (PST) Received: from localhost.localdomain.com ([111.204.49.2]) by smtp.gmail.com with ESMTPSA id hw7sm34529220pac.12.2015.12.07.04.16.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Dec 2015 04:16:28 -0800 (PST) From: Wenwei Tao To: mb@lightnvm.io Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH] lightnvm: change rrpc slab creation/destruction time Date: Mon, 7 Dec 2015 20:16:17 +0800 Message-Id: <1449490577-30574-1-git-send-email-ww.tao0320@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP create rrpc slabs during rrpc module init, thus eliminate the lock contention and slab status check in rrpc_core_init. And destroy them when rrpc exit. Signed-off-by: Wenwei Tao --- drivers/lightnvm/rrpc.c | 54 ++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c index 75e59c3..a36f39a 100644 --- a/drivers/lightnvm/rrpc.c +++ b/drivers/lightnvm/rrpc.c @@ -17,7 +17,6 @@ #include "rrpc.h" static struct kmem_cache *rrpc_gcb_cache, *rrpc_rq_cache; -static DECLARE_RWSEM(rrpc_lock); static int rrpc_submit_io(struct rrpc *rrpc, struct bio *bio, struct nvm_rq *rqd, unsigned long flags); @@ -1019,26 +1018,6 @@ static int rrpc_map_init(struct rrpc *rrpc) static int rrpc_core_init(struct rrpc *rrpc) { - down_write(&rrpc_lock); - if (!rrpc_gcb_cache) { - rrpc_gcb_cache = kmem_cache_create("rrpc_gcb", - sizeof(struct rrpc_block_gc), 0, 0, NULL); - if (!rrpc_gcb_cache) { - up_write(&rrpc_lock); - return -ENOMEM; - } - - rrpc_rq_cache = kmem_cache_create("rrpc_rq", - sizeof(struct nvm_rq) + sizeof(struct rrpc_rq), - 0, 0, NULL); - if (!rrpc_rq_cache) { - kmem_cache_destroy(rrpc_gcb_cache); - up_write(&rrpc_lock); - return -ENOMEM; - } - } - up_write(&rrpc_lock); - rrpc->page_pool = mempool_create_page_pool(PAGE_POOL_SIZE, 0); if (!rrpc->page_pool) return -ENOMEM; @@ -1338,14 +1317,47 @@ static struct nvm_tgt_type tt_rrpc = { .exit = rrpc_exit, }; +static int __init rrpc_slab_init(void) +{ + rrpc_gcb_cache = kmem_cache_create("rrpc_gcb", + sizeof(struct rrpc_block_gc), 0, 0, NULL); + if (!rrpc_gcb_cache) + goto out; + + rrpc_rq_cache = kmem_cache_create("rrpc_rq", + sizeof(struct nvm_rq) + sizeof(struct rrpc_rq), + 0, 0, NULL); + if (!rrpc_rq_cache) + goto out_free; + + return 0; + +out_free: + kmem_cache_destroy(rrpc_gcb_cache); +out: + return -ENOMEM; +} + +static inline void rrpc_slab_free(void) +{ + kmem_cache_destroy(rrpc_gcb_cache); + kmem_cache_destroy(rrpc_rq_cache); +} + static int __init rrpc_module_init(void) { + int ret; + + ret = rrpc_slab_init(); + if (ret) + return ret; return nvm_register_target(&tt_rrpc); } static void rrpc_module_exit(void) { nvm_unregister_target(&tt_rrpc); + rrpc_slab_free(); } module_init(rrpc_module_init);