Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp454133imu; Mon, 5 Nov 2018 03:44:53 -0800 (PST) X-Google-Smtp-Source: AJdET5fsXjPRjdnqLvBwGU3LdSlHk7OXQ9pijutB5GoRxlt3JFL5j53ULF2ZvK3i3tS5qAtEKUHV X-Received: by 2002:a63:b5b:: with SMTP id a27-v6mr18604746pgl.97.1541418293488; Mon, 05 Nov 2018 03:44:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541418293; cv=none; d=google.com; s=arc-20160816; b=P+3UOMRwpW6RLrXR21cNp9xymYZ2D7RH/B0Fz6HNGDkjsoz4zkVZoEM414jq/twk6y Rzl6ADLuFfuQaoy5/GG4PiRNhvVvuHhRykBRSmIwHD+688Q9o3elcGgsnYIZMIhBRCWM WrpeNQvSlzOVFzqtQyQPm+y3aoDckZLNuLtE30ECeskHcTnM2qqC8MbuzJRSsl/DqwYU 8lY3sXKA0dP+E8e4GCkuDXjiaNqvxz0A02cZUUBjzKr/3iAm4nvPU4p5G1+cSwo4NjYL PaGZ2zW4WghwC16AjMWlxeB/Z7yX/AS/q84Amx5pXRzGu2BIhtDOgqTTSNZtOhym76ae 380A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=sx1ajo5hZmYpBUQGxeD/kBzJSjvXlL/mCrEYSCy7h00=; b=JxLSf1vcucw+LWQg4GEulDeeHY2E4PWT22/eLd+g4gJGJvYmYQEw7r2KhfpEi2/d49 gOVyRWr3+L68AlBo6ZT+6fV4n9FiU6NzHtFukZPPHqjLtJX2NDCLoynqVYzblTfT9RAU afgqNCPGVQWm2ffh2NlEDIjsSo6Aapf9hGKRzejxthRUEEZPu6Zbpetr/zm9Ef9e9R5P RHwKgFagsfXTmolxSrT7sbNHY1FZ280TIytfYJU8h9+BWo/xoWPvuYBFfBSY3DHLpgzM Sr/ETJJNKaWC49vlwCdsUJ/tq+ab10fMAmfF6w3Y0Dx8q50t63XvH8MpmS8Bl2rqYaOc p4kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=FXgOKPD4; 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 b13-v6si19856115pgd.509.2018.11.05.03.44.38; Mon, 05 Nov 2018 03:44:53 -0800 (PST) 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=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=FXgOKPD4; 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 S1729356AbeKEVB3 (ORCPT + 99 others); Mon, 5 Nov 2018 16:01:29 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:39689 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729220AbeKEVB0 (ORCPT ); Mon, 5 Nov 2018 16:01:26 -0500 Received: by mail-it1-f194.google.com with SMTP id m15so12069621itl.4 for ; Mon, 05 Nov 2018 03:42:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=owltronix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sx1ajo5hZmYpBUQGxeD/kBzJSjvXlL/mCrEYSCy7h00=; b=FXgOKPD4pUJdjhD7cG6p71jP7/SwDYuTo19m8KPys2RpuYVduMHeKp2PZ9LyXYwTB0 LAHxBkgybesZOxHIP0R6Z5IHCMubohbxPy/pVsNuUSvJa0NNvttwBRXocnJ3K+AY6Ezu Do3VY9iVTdmofFnw3P7BxIm134sRs32rxfQL+atTvaOitn7SaCDAUB3+ACrA7gZK8kkb PlKeFDZAbJ4j37KmDSQMKU96EvLBxWWGvdy2ioWX2W1T7TTQ5Qj7PHpKjO5SKAASO5Qo lwlD4BTwlwS9g0sEE3HCRBXzSwS4XCoOCm85c/9lf1+ZgrmevhWdvi3mzAzi6HH9B7hv N4lg== 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; bh=sx1ajo5hZmYpBUQGxeD/kBzJSjvXlL/mCrEYSCy7h00=; b=sbuF0JS7U0J71VUl+o4YfThgZ+uVdaNdsclzjfiipSBZa7/JNCEV61aYR6pXSU4Cgs traSW28zA8pgRAPAjV0mIBLj6wfnGDVw+8izoduwGZ5Le9++vTyPi/AC9hYHscByMhG6 lcHSHzuqlkmSbTMqiVmM5uJTR+LdVuX+ZLZtwTHVZeJpHDFKLu1PjUjdMR9HZw27LmOp 7qs9j3SxUsSoTwyJ1bH923nZAMm7SwkFlPOjjK9mXFwjTFgaLfqNgu0Ep77CzJMlqbPH SwSzt/TnoNDMEVYf/VHN3+cnCIrmlosSvasWENnjqRjl/HfCjzyzFi4DDhdqLu9BBD9c yP2Q== X-Gm-Message-State: AGRZ1gJ9hSD0qsfKz2E6KfWsJcO9HYJALgcOUjrz2TgJvJGV7xV7CEs9 eZcaZRX9nu3W1GuSTKcPr0SN2A== X-Received: by 2002:a24:e4c8:: with SMTP id o191-v6mr6280803ith.24.1541418127219; Mon, 05 Nov 2018 03:42:07 -0800 (PST) Received: from ch-lap-hans.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id 186-v6sm14880824itf.11.2018.11.05.03.42.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 03:42:06 -0800 (PST) From: Hans Holmberg X-Google-Original-From: Hans Holmberg To: Matias Bjorling Cc: Javier Gonzales , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Holmberg , Hans Holmberg Subject: [PATCH 3/7] lightnvm: pblk: stop writes gracefully when running out of lines Date: Mon, 5 Nov 2018 12:41:09 +0100 Message-Id: <20181105114113.30932-4-hans.ml.holmberg@cnexlabs.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181105114113.30932-1-hans.ml.holmberg@cnexlabs.com> References: <20181105114113.30932-1-hans.ml.holmberg@cnexlabs.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Holmberg From: Hans Holmberg If mapping fails (i.e. when running out of lines), handle the error and stop writing. Signed-off-by: Hans Holmberg --- drivers/lightnvm/pblk-map.c | 47 +++++++++++++++++++++-------------- drivers/lightnvm/pblk-write.c | 30 ++++++++++++++-------- drivers/lightnvm/pblk.h | 4 +-- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/drivers/lightnvm/pblk-map.c b/drivers/lightnvm/pblk-map.c index 6dcbd44e3acb..5a3c28cce8ab 100644 --- a/drivers/lightnvm/pblk-map.c +++ b/drivers/lightnvm/pblk-map.c @@ -33,6 +33,9 @@ static int pblk_map_page_data(struct pblk *pblk, unsigned int sentry, int nr_secs = pblk->min_write_pgs; int i; + if (!line) + return -ENOSPC; + if (pblk_line_is_full(line)) { struct pblk_line *prev_line = line; @@ -42,8 +45,11 @@ static int pblk_map_page_data(struct pblk *pblk, unsigned int sentry, line = pblk_line_replace_data(pblk); pblk_line_close_meta(pblk, prev_line); - if (!line) - return -EINTR; + if (!line) { + pblk_pipeline_stop(pblk); + return -ENOSPC; + } + } emeta = line->emeta; @@ -84,7 +90,7 @@ static int pblk_map_page_data(struct pblk *pblk, unsigned int sentry, return 0; } -void pblk_map_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int sentry, +int pblk_map_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int sentry, unsigned long *lun_bitmap, unsigned int valid_secs, unsigned int off) { @@ -93,20 +99,22 @@ void pblk_map_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int sentry, unsigned int map_secs; int min = pblk->min_write_pgs; int i; + int ret; for (i = off; i < rqd->nr_ppas; i += min) { map_secs = (i + min > valid_secs) ? (valid_secs % min) : min; - if (pblk_map_page_data(pblk, sentry + i, &ppa_list[i], - lun_bitmap, &meta_list[i], map_secs)) { - bio_put(rqd->bio); - pblk_free_rqd(pblk, rqd, PBLK_WRITE); - pblk_pipeline_stop(pblk); - } + + ret = pblk_map_page_data(pblk, sentry + i, &ppa_list[i], + lun_bitmap, &meta_list[i], map_secs); + if (ret) + return ret; } + + return 0; } /* only if erase_ppa is set, acquire erase semaphore */ -void pblk_map_erase_rq(struct pblk *pblk, struct nvm_rq *rqd, +int pblk_map_erase_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int sentry, unsigned long *lun_bitmap, unsigned int valid_secs, struct ppa_addr *erase_ppa) { @@ -119,15 +127,16 @@ void pblk_map_erase_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int map_secs; int min = pblk->min_write_pgs; int i, erase_lun; + int ret; + for (i = 0; i < rqd->nr_ppas; i += min) { map_secs = (i + min > valid_secs) ? (valid_secs % min) : min; - if (pblk_map_page_data(pblk, sentry + i, &ppa_list[i], - lun_bitmap, &meta_list[i], map_secs)) { - bio_put(rqd->bio); - pblk_free_rqd(pblk, rqd, PBLK_WRITE); - pblk_pipeline_stop(pblk); - } + + ret = pblk_map_page_data(pblk, sentry + i, &ppa_list[i], + lun_bitmap, &meta_list[i], map_secs); + if (ret) + return ret; erase_lun = pblk_ppa_to_pos(geo, ppa_list[i]); @@ -163,7 +172,7 @@ void pblk_map_erase_rq(struct pblk *pblk, struct nvm_rq *rqd, */ e_line = pblk_line_get_erase(pblk); if (!e_line) - return; + return -ENOSPC; /* Erase blocks that are bad in this line but might not be in next */ if (unlikely(pblk_ppa_empty(*erase_ppa)) && @@ -174,7 +183,7 @@ void pblk_map_erase_rq(struct pblk *pblk, struct nvm_rq *rqd, bit = find_next_bit(d_line->blk_bitmap, lm->blk_per_line, bit + 1); if (bit >= lm->blk_per_line) - return; + return 0; spin_lock(&e_line->lock); if (test_bit(bit, e_line->erase_bitmap)) { @@ -188,4 +197,6 @@ void pblk_map_erase_rq(struct pblk *pblk, struct nvm_rq *rqd, *erase_ppa = pblk->luns[bit].bppa; /* set ch and lun */ erase_ppa->a.blk = e_line->id; } + + return 0; } diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-write.c index 750f04b8a227..2bf78f81862d 100644 --- a/drivers/lightnvm/pblk-write.c +++ b/drivers/lightnvm/pblk-write.c @@ -334,12 +334,13 @@ static int pblk_setup_w_rq(struct pblk *pblk, struct nvm_rq *rqd, } if (likely(!e_line || !atomic_read(&e_line->left_eblks))) - pblk_map_rq(pblk, rqd, c_ctx->sentry, lun_bitmap, valid, 0); + ret = pblk_map_rq(pblk, rqd, c_ctx->sentry, lun_bitmap, + valid, 0); else - pblk_map_erase_rq(pblk, rqd, c_ctx->sentry, lun_bitmap, + ret = pblk_map_erase_rq(pblk, rqd, c_ctx->sentry, lun_bitmap, valid, erase_ppa); - return 0; + return ret; } static int pblk_calc_secs_to_sync(struct pblk *pblk, unsigned int secs_avail, @@ -563,7 +564,7 @@ static void pblk_free_write_rqd(struct pblk *pblk, struct nvm_rq *rqd) c_ctx->nr_padded); } -static int pblk_submit_write(struct pblk *pblk) +static int pblk_submit_write(struct pblk *pblk, int *secs_left) { struct bio *bio; struct nvm_rq *rqd; @@ -572,6 +573,8 @@ static int pblk_submit_write(struct pblk *pblk) unsigned long pos; unsigned int resubmit; + *secs_left = 0; + spin_lock(&pblk->resubmit_lock); resubmit = !list_empty(&pblk->resubmit_list); spin_unlock(&pblk->resubmit_lock); @@ -601,17 +604,17 @@ static int pblk_submit_write(struct pblk *pblk) */ secs_avail = pblk_rb_read_count(&pblk->rwb); if (!secs_avail) - return 1; + return 0; secs_to_flush = pblk_rb_flush_point_count(&pblk->rwb); if (!secs_to_flush && secs_avail < pblk->min_write_pgs) - return 1; + return 0; secs_to_sync = pblk_calc_secs_to_sync(pblk, secs_avail, secs_to_flush); if (secs_to_sync > pblk->max_write_pgs) { pblk_err(pblk, "bad buffer sync calculation\n"); - return 1; + return 0; } secs_to_com = (secs_to_sync > secs_avail) ? @@ -640,6 +643,7 @@ static int pblk_submit_write(struct pblk *pblk) atomic_long_add(secs_to_sync, &pblk->sub_writes); #endif + *secs_left = 1; return 0; fail_free_bio: @@ -648,16 +652,22 @@ static int pblk_submit_write(struct pblk *pblk) bio_put(bio); pblk_free_rqd(pblk, rqd, PBLK_WRITE); - return 1; + return -EINTR; } int pblk_write_ts(void *data) { struct pblk *pblk = data; + int secs_left; + int write_failure = 0; while (!kthread_should_stop()) { - if (!pblk_submit_write(pblk)) - continue; + if (!write_failure) { + write_failure = pblk_submit_write(pblk, &secs_left); + + if (secs_left) + continue; + } set_current_state(TASK_INTERRUPTIBLE); io_schedule(); } diff --git a/drivers/lightnvm/pblk.h b/drivers/lightnvm/pblk.h index 02bb2e98f8a9..f415aae600c8 100644 --- a/drivers/lightnvm/pblk.h +++ b/drivers/lightnvm/pblk.h @@ -871,10 +871,10 @@ int pblk_write_gc_to_cache(struct pblk *pblk, struct pblk_gc_rq *gc_rq); /* * pblk map */ -void pblk_map_erase_rq(struct pblk *pblk, struct nvm_rq *rqd, +int pblk_map_erase_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int sentry, unsigned long *lun_bitmap, unsigned int valid_secs, struct ppa_addr *erase_ppa); -void pblk_map_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int sentry, +int pblk_map_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int sentry, unsigned long *lun_bitmap, unsigned int valid_secs, unsigned int off); -- 2.17.1