From patchwork Sun Oct 1 13:25:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rakesh Pandit X-Patchwork-Id: 9979717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C5B7760365 for ; Sun, 1 Oct 2017 13:26:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C655B28AFA for ; Sun, 1 Oct 2017 13:26:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB33728B78; Sun, 1 Oct 2017 13:26:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31B4928AFA for ; Sun, 1 Oct 2017 13:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751081AbdJAN0A (ORCPT ); Sun, 1 Oct 2017 09:26:00 -0400 Received: from mx1.mpynet.fi ([82.197.21.84]:50333 "EHLO mx1.mpynet.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751035AbdJANZ7 (ORCPT ); Sun, 1 Oct 2017 09:25:59 -0400 Date: Sun, 1 Oct 2017 16:25:56 +0300 From: Rakesh Pandit To: Matias =?iso-8859-1?Q?Bj=F8rling?= , , CC: Javier =?iso-8859-1?Q?Gonz=E1lez?= Subject: [PATCH 5/6] lightnvm: pblk: free up mempool allocation for erases correctly Message-ID: <20171001132555.GA5763@hercules.tuxera.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.0 (2017-02-23) X-ClientProxiedBy: tuxera-exch.ad.tuxera.com (10.20.48.11) To tuxera-exch.ad.tuxera.com (10.20.48.11) Received-SPF: none Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP While separating read and erase mempools in 22da65a1b pblk_g_rq_cache was used two times to set aside memory both for erase and read requests. Because same kmem cache is used repeatedly a single call to kmem_cache_destroy wouldn't deallocate everything. Repeatedly doing loading and unloading of pblk modules would eventually result in some leak. The fix is to really use separate kmem cache and track it appropriately. Fixes: 22da65a1b ("lightnvm: pblk: decouple read/erase mempools") Signed-off-by: Rakesh Pandit --- drivers/lightnvm/pblk-init.c | 16 ++++++++++++++-- drivers/lightnvm/pblk.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c index 9d9adcf..519e5cf 100644 --- a/drivers/lightnvm/pblk-init.c +++ b/drivers/lightnvm/pblk-init.c @@ -21,7 +21,7 @@ #include "pblk.h" static struct kmem_cache *pblk_ws_cache, *pblk_rec_cache, *pblk_g_rq_cache, - *pblk_w_rq_cache; + *pblk_w_rq_cache, *pblk_e_rq_cache; static DECLARE_RWSEM(pblk_lock); struct bio_set *pblk_bio_set; @@ -206,12 +206,23 @@ static int pblk_init_global_caches(struct pblk *pblk) return -ENOMEM; } + pblk_e_rq_cache = kmem_cache_create("pblk_e_rq", pblk_e_rq_size, + 0, 0, NULL); + if (!pblk_e_rq_cache) { + kmem_cache_destroy(pblk_ws_cache); + kmem_cache_destroy(pblk_rec_cache); + kmem_cache_destroy(pblk_g_rq_cache); + up_write(&pblk_lock); + return -ENOMEM; + } + pblk_w_rq_cache = kmem_cache_create("pblk_w_rq", pblk_w_rq_size, 0, 0, NULL); if (!pblk_w_rq_cache) { kmem_cache_destroy(pblk_ws_cache); kmem_cache_destroy(pblk_rec_cache); kmem_cache_destroy(pblk_g_rq_cache); + kmem_cache_destroy(pblk_e_rq_cache); up_write(&pblk_lock); return -ENOMEM; } @@ -252,7 +263,7 @@ static int pblk_core_init(struct pblk *pblk) goto free_rec_pool; pblk->e_rq_pool = mempool_create_slab_pool(geo->nr_luns, - pblk_g_rq_cache); + pblk_e_rq_cache); if (!pblk->e_rq_pool) goto free_r_rq_pool; @@ -327,6 +338,7 @@ static void pblk_core_free(struct pblk *pblk) kmem_cache_destroy(pblk_ws_cache); kmem_cache_destroy(pblk_rec_cache); kmem_cache_destroy(pblk_g_rq_cache); + kmem_cache_destroy(pblk_e_rq_cache); kmem_cache_destroy(pblk_w_rq_cache); } diff --git a/drivers/lightnvm/pblk.h b/drivers/lightnvm/pblk.h index fcac246..03834d1 100644 --- a/drivers/lightnvm/pblk.h +++ b/drivers/lightnvm/pblk.h @@ -651,6 +651,7 @@ struct pblk_line_ws { #define pblk_g_rq_size (sizeof(struct nvm_rq) + sizeof(struct pblk_g_ctx)) #define pblk_w_rq_size (sizeof(struct nvm_rq) + sizeof(struct pblk_c_ctx)) +#define pblk_e_rq_size pblk_g_rq_size /* * pblk ring buffer operations