Received: by 10.192.165.156 with SMTP id m28csp461862imm; Mon, 16 Apr 2018 03:22:38 -0700 (PDT) X-Google-Smtp-Source: AIpwx49lJUS+6bjnQ2l82KTdxew7FSrKY31Cg9V28oz/pI/H0CUpJ6t6YpoU13q8qeB0YNzDewgC X-Received: by 2002:a17:902:362:: with SMTP id 89-v6mr15090592pld.270.1523874158749; Mon, 16 Apr 2018 03:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523874158; cv=none; d=google.com; s=arc-20160816; b=ycdBhmrUj76l/q1U6jZJ/dda/ltgpyfLaKPh1fCclwXM5ijHFSSNoxeua2Ms9k57rs bRBHkSpLt4pAeNHK+vwIRQm6XK4qRVF9mOkD/fIRgCOE76NJpZKBj3orQgI/pU6PCNwa Gq0rKZFUboi5iXB8FO0IT4/L/E5ua1vkzZMttTGHICp3QcGA6hxxbqvLDiaDL+pzYEzK 1JVaSPXL6y3Id+evKj+MNhU+GC3hAWbm0K0S11sp1IMbKQYu0czXi7XLFtyNfdoquvO9 184C/FwOZTXC2TCU+tc50DMMvqPFMqZ32W5pQSXz9LtJ466UxLOgnjOJURg2aIg0YX5m 49uA== 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 :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Uyu9uAYisEvFOMRQ255KreMvD0Xr4OoFramTYQBRsA4=; b=lrJV4HVa5KL5j7Fm5xSYzydWpfd+yKy/UMw04xUlZ9piopHvCi5ObkmUvGKASkgpvP 8oOL/4PprmYSzQirYDbSgxGrdsK49Ed+W/wl2qDTdpFwmP+HiiwNtfh+5IRFHc08k7PC PKkxng6yqxr4rydrlTDby4kwHur7+o50FN0prNqFAVx8blVLvlqTP9OR06fmp/fcYVVE nn9Uwpi1uI/7Eo3m4yewCKV6m3IrR8lBQ3pQEfVX4PZlX+KEWW2O+ct7Ki+reD1yMxjo a9O08ei7WMJsBqbuYNmEzVDMbyKqIhhYHveKMIucEaXGD9ERgO034eC2vr2utkJZ3mqG VqMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=CrktTjWC; 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 e16si3892552pgq.550.2018.04.16.03.22.23; Mon, 16 Apr 2018 03:22:38 -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=CrktTjWC; 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 S1753690AbeDPKVO (ORCPT + 99 others); Mon, 16 Apr 2018 06:21:14 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:37659 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752979AbeDPKVM (ORCPT ); Mon, 16 Apr 2018 06:21:12 -0400 Received: by mail-wr0-f194.google.com with SMTP id l49so24398485wrl.4 for ; Mon, 16 Apr 2018 03:21:11 -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:mime-version :content-transfer-encoding; bh=Uyu9uAYisEvFOMRQ255KreMvD0Xr4OoFramTYQBRsA4=; b=CrktTjWCeU6kq69sQSESypt+Z7uNT4UxKDNGyM3NCP555gp2+tc8/AFVfHa9qxCde9 by8G8RTAC0ie4cwFDNfwezhzMi954KClqW1ZpuCpnK/qMHxx7kG433eK70WiD2dU0VXv H/v0lW25Z9PwEIt/PI/gvs1QHIlXtflWOmIyrY0bpdwTAODJ8XdqeDcFpc+y7znbB2H5 sU8ors30UdT3ero85/VOtLX4vj5m957ecpNFK3nr4l3sZfXiGOh8rW9uCYY3H+Uv81X/ /+yi5PHpYHdePBd7f8qGtnl0zx1OaGWZwgtMN8K9Obu3ZqlryIpkXaqwFt+cMGzOUOSQ 4z9A== 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:mime-version :content-transfer-encoding; bh=Uyu9uAYisEvFOMRQ255KreMvD0Xr4OoFramTYQBRsA4=; b=j5cuzNuzWgad0zHDo5e9aJ0sQlEafOSgWZi2adOL+VnBXX5kDRqTUQsv/wDhdSAUfh fT+wy9Q4SYnzxIebVApC6638ooQ+kL5E6H3Eiku4mNVDbRQNQc+QxdCXsZKxyBr39D1R UFcnvyfukawjguZbbuBsQY7eWCgN0IAldjA3nbWnsLfdX0IuFIEQTyQ3cuy+nADhYBUK NndEt1r/UUB8kY+8Ewy94MTVWsZrVHiSVptCR56VxKRdQkmNUgFPEADfjczwhypr++/r YmFDBxnMspKGCZ39AymKlzx50TyNoXDr4aTLW2Tto9kWX0xd0emtv8meDNDiwLSxI8bW V+RA== X-Gm-Message-State: ALQs6tA13vuBfdqxgbUB7QxSM4C93c1ZVDLZI3DPUcgFa29eV8xDE639 V0VqZyi6+gW3ThSmkNnfzzrSyw== X-Received: by 10.80.201.193 with SMTP id c1mr32101505edi.2.1523874070926; Mon, 16 Apr 2018 03:21:10 -0700 (PDT) Received: from uhalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id j15sm7048049edj.42.2018.04.16.03.21.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Apr 2018 03:21:09 -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: Mon, 16 Apr 2018 12:21:06 +0200 Message-Id: <1523874066-4459-1-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 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 Allocate line bitmaps outside of the line lock on line preparation. Signed-off-by: Javier González --- drivers/lightnvm/pblk-core.c | 96 +++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c index 5f960a6609c8..7762e89984ee 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,15 @@ 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); + if (pblk_line_alloc_bitmaps(pblk, line)) + return -EINTR; 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 +1260,24 @@ void pblk_line_recov_close(struct pblk *pblk, struct pblk_line *line) line->emeta = NULL; } +static void pblk_line_clear(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_clear(line); +} + struct pblk_line *pblk_line_get(struct pblk *pblk) { struct pblk_line_mgmt *l_mg = &pblk->l_mg; @@ -1326,11 +1344,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_clear(line); + l_mg->data_line = retry_line; spin_unlock(&l_mg->free_lock); @@ -1383,6 +1404,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 +1551,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 +1593,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