From patchwork Wed Sep 6 15:01:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= X-Patchwork-Id: 9940959 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 E665B604D5 for ; Wed, 6 Sep 2017 15:01:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB00928501 for ; Wed, 6 Sep 2017 15:01:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D010828C13; Wed, 6 Sep 2017 15:01:48 +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,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable 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 E4E6828C10 for ; Wed, 6 Sep 2017 15:01:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932802AbdIFPB0 (ORCPT ); Wed, 6 Sep 2017 11:01:26 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:38677 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932747AbdIFPBS (ORCPT ); Wed, 6 Sep 2017 11:01:18 -0400 Received: by mail-wm0-f47.google.com with SMTP id 187so32068531wmn.1 for ; Wed, 06 Sep 2017 08:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aCLku6mgSuK2uY/A5CAnDlTQp+E25WP24soyJmxKmmw=; b=HEHl8isfjCGfy4HUHcLYw3lqEaq2C1f9mTMt+2awsevl6m8XSi51R4BGK6RFGQlXYl rRnNzqshWIbUYgdl2crS/qRa5XAe0/bnTJT0B966KfwdT5FzhJFx1GX6gNn72nl8ovSP Xynaxl6rpU8dnHyR/xTjXtk3s0xAHgLZMIYICoYyoitIn/OGJ2ZCla44jAa9t00ZiJQD /dR6WGZonu1iCoU12Bn1sUtU41o//6adsbw0BiQMQhqyAUbSz/gHkobgOrd+z3Mhwxku JNtEYlf9/3erta0dgjN7IOEwhor/g+fc+7aNPL/tVEbcJ7fTzL1jiOcGcMQz13gxulNA 7zvw== 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=aCLku6mgSuK2uY/A5CAnDlTQp+E25WP24soyJmxKmmw=; b=QGYTH2ysCJ50QwJRhPVg6VGBGqxXUX1grwKeoqqe5u54XmnXXRqPTTpAQQ+DOL7fs8 Ndy11Ik8CkDFhbRMMVnjVUP2fE9g38f0/L+KRAyqpSQhNFI5C56QtQHIn1BRJYSaPkWd uvumTjIHhM5QRcDqa0hPZR9HyqFmRWMqFGQ7TDXKW8afZj5cGNBKQ1W1UjXtLDvDTWfH CVfPmNNr2F0kLhSXqIhCU/NYlYVM3Fc6pYA8NSjQ8bIFUKJe23j2W/ptbAbrmtZcLR8Q ij7V8BIuPwdYoptpD0XSGNMO9GR8NnrijxeQA4EvKC7YZcJn6ITCr6qWJTw3HCQ/zbt2 L6/g== X-Gm-Message-State: AHPjjUjm2UOmqmji6Zz0EwqOkwxFclSCZqevmJfNPOGdZwDInYlLAczo CfpygDaxUDm/j3+L X-Google-Smtp-Source: ADKCNb6MGt9xnjQsd95vg/G6uX6c/F1fCeMlibHJVcVW4EQejchzqapDIzU5y4yGsQJeveJEXI/YrA== X-Received: by 10.80.164.163 with SMTP id w32mr22668edb.63.1504710077801; Wed, 06 Sep 2017 08:01:17 -0700 (PDT) Received: from uHalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id p16sm1408260eda.78.2017.09.06.08.01.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Sep 2017 08:01:17 -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, axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 4/6] lightnvm: pblk: free padded entries in write buffer Date: Wed, 6 Sep 2017 17:01:04 +0200 Message-Id: <1504710066-4699-5-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504710066-4699-1-git-send-email-javier@cnexlabs.com> References: <1504710066-4699-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 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 When a REQ_FLUSH reaches pblk, the bio cannot be directly completed. Instead, data on the write buffer is flushed and the bio is completed on the completion pah. This might require some sectors to be padded in order to guarantee a successful write. This patch fixes a memory leak on the padded pages. A consequence of this bad free was that internal bios not containing data (only a flush) were not being completed. Fixes: a4bd217b4326 ("lightnvm: physical block device (pblk) target") Signed-off-by: Javier González Signed-off-by: Matias Bjørling Reviewed-by: Johannes Thumshirn --- drivers/lightnvm/pblk-core.c | 1 - drivers/lightnvm/pblk-write.c | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c index acb07bbcb416..84bff271abd8 100644 --- a/drivers/lightnvm/pblk-core.c +++ b/drivers/lightnvm/pblk-core.c @@ -192,7 +192,6 @@ void pblk_bio_free_pages(struct pblk *pblk, struct bio *bio, int off, WARN_ON(off + nr_pages != bio->bi_vcnt); - bio_advance(bio, off * PBLK_EXPOSED_PAGE_SIZE); for (i = off; i < nr_pages + off; i++) { bv = bio->bi_io_vec[i]; mempool_free(bv.bv_page, pblk->page_pool); diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-write.c index 3ad9e56d2473..6acb4a92435f 100644 --- a/drivers/lightnvm/pblk-write.c +++ b/drivers/lightnvm/pblk-write.c @@ -25,13 +25,20 @@ static unsigned long pblk_end_w_bio(struct pblk *pblk, struct nvm_rq *rqd, unsigned long ret; int i; - for (i = 0; i < c_ctx->nr_valid; i++) { + i = 0; + do { struct pblk_w_ctx *w_ctx; w_ctx = pblk_rb_w_ctx(&pblk->rwb, c_ctx->sentry + i); while ((original_bio = bio_list_pop(&w_ctx->bios))) bio_endio(original_bio); - } + + i++; + } while (i < c_ctx->nr_valid); + + if (c_ctx->nr_padded) + pblk_bio_free_pages(pblk, rqd->bio, c_ctx->nr_valid, + c_ctx->nr_padded); #ifdef CONFIG_NVM_DEBUG atomic_long_add(c_ctx->nr_valid, &pblk->sync_writes); @@ -521,7 +528,8 @@ static void pblk_free_write_rqd(struct pblk *pblk, struct nvm_rq *rqd) struct bio *bio = rqd->bio; if (c_ctx->nr_padded) - pblk_bio_free_pages(pblk, bio, rqd->nr_ppas, c_ctx->nr_padded); + pblk_bio_free_pages(pblk, bio, c_ctx->nr_valid, + c_ctx->nr_padded); } static int pblk_submit_write(struct pblk *pblk)