Received: by 10.192.165.156 with SMTP id m28csp1150465imm; Wed, 18 Apr 2018 05:08:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx498ThylGRCQQJpNA9cNm1qCW5B1Pfr0HVAi2y5p6ijmEKnogldtLfrCEmwLXpXHxGanDs/T X-Received: by 10.99.160.106 with SMTP id u42mr1487452pgn.389.1524053284756; Wed, 18 Apr 2018 05:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524053284; cv=none; d=google.com; s=arc-20160816; b=bRes6CyHTnRCzGtvoPRNcKOizChAFLzukvwPtMKWiXFX9+AIdvbnIi/3rlvzCrD1/O OqNI63qqQRXevj9S5rGdH2WGn3i2GkBL6tYXNtSgI34NOKKJNktrgNinsgIMtRGlpx4T cId1vtcOvEHMiJMtrD5/sC6ocwrI7oVytyHp5ZLBmQJySCkpmLcCS1hiJkhfKvHSbfwH YLXe+5MNqAs3KswzWpwJkoQf4XCXLqOZS0cZu1y4FRUaKUPvrE10YPNiCweYc9bW0xMI feaD+ml6s+PqLXb90IDUCiVpegbx/IobQyIjbO1D6ZyPllcy5Zjd0Be8b+j3Rp2PsTQw honA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Yyr+kxe5p5A5UdLHA9BWpo8rVJfLc3k6aj5E+DYa4k4=; b=xnvFPm5mFXaibj6MV6V1Bi1Jz46fnOsoVUaw9F7z0XIXKgDtwILAf+9P/xUpWlpMzZ gs6dbHUM53p5Y37OODms3u2MjtWLHKoJjPM0K7K4ZaDcIOaofvrbnkqLTOOu0WJ/lL2X mky8Y33NtBa2HTeZL3s9SnFhcRUTbAZqmbMg0MNEieHPpRI7Zz2JahkQ3urcvGHu9nx5 EXHy0eaJ046vCSJKfm2yTIvX/eg0+y1GGsw7fvsz9aJ9DwkJWjlhloEYl4PyVsDbBu9i eH5OzSHW+gXd9SPavBeGdTLGX4f4zLbF/ekGMIVhNti0ctLtT9he9NbI2ytxCm3mLIPI O4GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=jskZApbJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m65si1073879pfc.9.2018.04.18.05.07.50; Wed, 18 Apr 2018 05:08:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=jskZApbJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753463AbeDRMGm (ORCPT + 99 others); Wed, 18 Apr 2018 08:06:42 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:45278 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752162AbeDRMG3 (ORCPT ); Wed, 18 Apr 2018 08:06:29 -0400 Received: by mail-wr0-f195.google.com with SMTP id u11-v6so4113826wri.12 for ; Wed, 18 Apr 2018 05:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yyr+kxe5p5A5UdLHA9BWpo8rVJfLc3k6aj5E+DYa4k4=; b=jskZApbJIMifB3yzObHRBWwbZ698kzfDVcy3OBq21Omm3JunK3Xo0TMARk6DZi+0FL ZTpA6TWm151U8z0tZpUMG40v2s8B+XaQJIxd6XkNHgXvxteLxmXdCA/BB4VrutDkbXMo oRsei14fg/hkmenMfgj2zi8uz+tvC0U2GUPjpXh0gFUsW5ELoW7wzogYcuWZUjAAQ0WH d0fk5L0PBgnGwqCrE+hmt1keHYUDl1lSe48b9tAqVp5rpGgs93ZuiknYFs6UsZBCFhKI ovIhkEEpexokjN/EpfuqdVydmLOBTD2dUShJg/BAn6iF62k28s2bZTzJaYhNnYaSHYC5 fhJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yyr+kxe5p5A5UdLHA9BWpo8rVJfLc3k6aj5E+DYa4k4=; b=FVFpsCFgLPGaIUUCbybC7p/U9+hrWEW11RniioIo7Q1XzrogChcZri3fzpCC9YfMA6 ZMulpiBevcs05MTFOWZp4WAGi/f32IX69nzycmRuhdLV+yY38s+o4DcE7ar+AFzYHokE LgIRj5W9m6Iq1jxrYuIm40K7dM6Lts5JZPQ9qbtrBHHJ+XvWi9LFdy5d2sFuvF8Pqtbk 4adTl8CqT+Kwcxe4mhRfl6BTvv8ajTBJ53OKAOQm2wtibUXk+Wa6vTBa9mHuJLhl+bbj 6yLLGPmxgUCAdbHW9hoAGr7GpkwCx9sPs6xQPnv3zo5spzyGPSMkKgw070SZcOa4ictN vwCQ== X-Gm-Message-State: ALQs6tDeifM0CP/ymaWgboSxim4FDztoNjmGZjdB/9l3u2qGYqGCevE9 e5Q0uSSmlkSFqQ14DuzFz/RWzMjf X-Received: by 10.80.190.68 with SMTP id b4mr2762371edi.164.1524053188393; Wed, 18 Apr 2018 05:06:28 -0700 (PDT) Received: from uhalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id e2sm948327edj.97.2018.04.18.05.06.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 05:06:27 -0700 (PDT) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH] lightnvm: pblk: take bitmap alloc. out of critical section Date: Wed, 18 Apr 2018 14:06:08 +0200 Message-Id: <1524053168-30476-2-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524053168-30476-1-git-send-email-javier@cnexlabs.com> References: <1524053168-30476-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org pblk allocates line bitmaps within the line lock unnecessarily. In order to take pressure out of the fast patch, allocate line bitmaps outside of this lock and refactor accordingly. Signed-off-by: Javier González --- drivers/lightnvm/pblk-core.c | 97 +++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c index 5f960a6609c8..09d89a568cd5 100644 --- a/drivers/lightnvm/pblk-core.c +++ b/drivers/lightnvm/pblk-core.c @@ -1058,6 +1058,25 @@ static int pblk_line_init_metadata(struct pblk *pblk, struct pblk_line *line, return 1; } +static int pblk_line_alloc_bitmaps(struct pblk *pblk, struct pblk_line *line) +{ + struct pblk_line_meta *lm = &pblk->lm; + + line->map_bitmap = kzalloc(lm->sec_bitmap_len, GFP_KERNEL); + if (!line->map_bitmap) + return -ENOMEM; + + /* will be initialized using bb info from map_bitmap */ + line->invalid_bitmap = kmalloc(lm->sec_bitmap_len, GFP_KERNEL); + if (!line->invalid_bitmap) { + kfree(line->map_bitmap); + line->map_bitmap = NULL; + return -ENOMEM; + } + + return 0; +} + /* For now lines are always assumed full lines. Thus, smeta former and current * lun bitmaps are omitted. */ @@ -1162,18 +1181,7 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) { struct pblk_line_meta *lm = &pblk->lm; int blk_in_line = atomic_read(&line->blk_in_line); - int blk_to_erase, ret; - - line->map_bitmap = kzalloc(lm->sec_bitmap_len, GFP_ATOMIC); - if (!line->map_bitmap) - return -ENOMEM; - - /* will be initialized using bb info from map_bitmap */ - line->invalid_bitmap = kmalloc(lm->sec_bitmap_len, GFP_ATOMIC); - if (!line->invalid_bitmap) { - ret = -ENOMEM; - goto fail_free_map_bitmap; - } + int blk_to_erase; /* Bad blocks do not need to be erased */ bitmap_copy(line->erase_bitmap, line->blk_bitmap, lm->blk_per_line); @@ -1191,15 +1199,15 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) } if (blk_in_line < lm->min_blk_line) { - ret = -EAGAIN; - goto fail_free_invalid_bitmap; + spin_unlock(&line->lock); + return -EAGAIN; } if (line->state != PBLK_LINESTATE_FREE) { WARN(1, "pblk: corrupted line %d, state %d\n", line->id, line->state); - ret = -EINTR; - goto fail_free_invalid_bitmap; + spin_unlock(&line->lock); + return -EINTR; } line->state = PBLK_LINESTATE_OPEN; @@ -1213,16 +1221,6 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) kref_init(&line->ref); return 0; - -fail_free_invalid_bitmap: - spin_unlock(&line->lock); - kfree(line->invalid_bitmap); - line->invalid_bitmap = NULL; -fail_free_map_bitmap: - kfree(line->map_bitmap); - line->map_bitmap = NULL; - - return ret; } int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line) @@ -1242,13 +1240,16 @@ int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line) } spin_unlock(&l_mg->free_lock); - pblk_rl_free_lines_dec(&pblk->rl, line, true); + ret = pblk_line_alloc_bitmaps(pblk, line); + if (ret) + return ret; if (!pblk_line_init_bb(pblk, line, 0)) { list_add(&line->list, &l_mg->free_list); return -EINTR; } + pblk_rl_free_lines_dec(&pblk->rl, line, true); return 0; } @@ -1260,6 +1261,24 @@ void pblk_line_recov_close(struct pblk *pblk, struct pblk_line *line) line->emeta = NULL; } +static void pblk_line_reinit(struct pblk_line *line) +{ + *line->vsc = cpu_to_le32(EMPTY_ENTRY); + + line->map_bitmap = NULL; + line->invalid_bitmap = NULL; + line->smeta = NULL; + line->emeta = NULL; +} + +void pblk_line_free(struct pblk_line *line) +{ + kfree(line->map_bitmap); + kfree(line->invalid_bitmap); + + pblk_line_reinit(line); +} + struct pblk_line *pblk_line_get(struct pblk *pblk) { struct pblk_line_mgmt *l_mg = &pblk->l_mg; @@ -1326,11 +1345,14 @@ static struct pblk_line *pblk_line_retry(struct pblk *pblk, return NULL; } + retry_line->map_bitmap = line->map_bitmap; + retry_line->invalid_bitmap = line->invalid_bitmap; retry_line->smeta = line->smeta; retry_line->emeta = line->emeta; retry_line->meta_line = line->meta_line; - pblk_line_free(line); + pblk_line_reinit(line); + l_mg->data_line = retry_line; spin_unlock(&l_mg->free_lock); @@ -1383,6 +1405,9 @@ struct pblk_line *pblk_line_get_first_data(struct pblk *pblk) } spin_unlock(&l_mg->free_lock); + if (pblk_line_alloc_bitmaps(pblk, line)) + return NULL; + if (pblk_line_erase(pblk, line)) { line = pblk_line_retry(pblk, line); if (!line) @@ -1527,6 +1552,9 @@ struct pblk_line *pblk_line_replace_data(struct pblk *pblk) goto retry_erase; } + if (pblk_line_alloc_bitmaps(pblk, new)) + return NULL; + retry_setup: if (!pblk_line_init_metadata(pblk, new, cur)) { new = pblk_line_retry(pblk, new); @@ -1566,19 +1594,6 @@ struct pblk_line *pblk_line_replace_data(struct pblk *pblk) return new; } -void pblk_line_free(struct pblk_line *line) -{ - kfree(line->map_bitmap); - kfree(line->invalid_bitmap); - - *line->vsc = cpu_to_le32(EMPTY_ENTRY); - - line->map_bitmap = NULL; - line->invalid_bitmap = NULL; - line->smeta = NULL; - line->emeta = NULL; -} - static void __pblk_line_put(struct pblk *pblk, struct pblk_line *line) { struct pblk_line_mgmt *l_mg = &pblk->l_mg; -- 2.7.4