Received: by 10.192.165.156 with SMTP id m28csp462990imm; Mon, 16 Apr 2018 03:24:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/O4YpGj6wL16AOC9bmhburwu/6XY6zi+YPvs0LT8H6OScuK9MhyuLkfWN8uykIN631cCpy X-Received: by 10.98.220.86 with SMTP id t83mr21024904pfg.60.1523874251637; Mon, 16 Apr 2018 03:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523874251; cv=none; d=google.com; s=arc-20160816; b=RB1QWQg5bKNLNtOEnkyh4a0LAwsOeBzZZveOaT9EIe996nsrv+ZK8YGHkBtQN9EpHP YY5iybAxnb53tdaXNXdOzRr/Yi6UNxuJOUYVYlL5c6kUNO0+Gg4+FCeb3VSIXIbjLeiI uq587jcq1n12/17XFGYfu1VNfCvvyUGd/46lQ82fCt2dXGLCMHl8Ku+FLec+4JS2nNg0 MILfclsJ/zgmtn2jniCRE1yMRhyC3ffu/zSIkzt4/Dwdw1JVIYnSAZTh5EU117EqFo/V PjHYHo9OqbbeHO8MmTEXSAxaBZO/WiekIFeXoLZFT1UUbz5x4qAymJ3f9tWEnc5DNsuv APnw== 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=VxU4GTVXZb8d8aHnugHgJXHutyNgt+nWCe8N9rT9SO8=; b=c9IyDIANPdV3sCtUy4Iw8qQA8TXxSFjfIpCTJN0G+9LZ5FfdWuuVnnSvenZilFpUaI SasuBh4ONGwIQxjSAZrb7WIemXaRzy3BsBS3t2H3y5toU4K47aqR4vq4fNwWXQ9+hjGY dcry5fPiuoeO03otjIHdkxqH0y93SpWBSX4kYfF8Uub+OTtDnVQ0a59pBuPwMUBwDFq7 KKlYqx2o1sMSKkVddP+ia0wRFBjlYxQ65tMw7+Z1IMeQvkNmjBhTjS/a7atQC/enhNUR aG/7++mGDcqIVlboIdPkeRWYN/blUdzp+q5QXHl+g+kuWyl8dZBZczU4i52bslLUXeHP 5wZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=nS1+XyBB; 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.23.57; Mon, 16 Apr 2018 03:24:11 -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=nS1+XyBB; 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 S1753819AbeDPKWn (ORCPT + 99 others); Mon, 16 Apr 2018 06:22:43 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:40917 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753154AbeDPKWm (ORCPT ); Mon, 16 Apr 2018 06:22:42 -0400 Received: by mail-wr0-f196.google.com with SMTP id v60so20513456wrc.7 for ; Mon, 16 Apr 2018 03:22:41 -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=VxU4GTVXZb8d8aHnugHgJXHutyNgt+nWCe8N9rT9SO8=; b=nS1+XyBB+Be9olxhC+3jiu18cUb12ZsVLr7MB7x7C/cHRgiT3wXOVXzwfF83ZdLAQG 1zBRU+vG/DeDD0exPvUjOXXONSFJYcJ2clxWCwnCjzpL28iD75+PO8qY1oqBkW0RkFyf vZtx/z4ZR8IQg2rE01bgekJQy4dgABcqH9fTMbdZ+cQQTPxlXM8SlR2AEmgMIM07rwwD FdiHbX6ofm4vONgrwr3tSbaWfmIw4NITSDVoVqRcDZNuvvxhx9vzFnKHyfvBJCr0wZjv IIxA7an5Y4ZH51QtdRCRg98fRoKugsNTrmBPgX1ibZHYT+CPDhHraXrruokXq0rpJFgP jy4w== 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=VxU4GTVXZb8d8aHnugHgJXHutyNgt+nWCe8N9rT9SO8=; b=F3XaaDVAAzeQ/F3dHL053v+/VMSYPtpcBVDBIy0pC9gg45f7REj8xz0er4DYAthhBI TzGYOdfdPFlFDzZNGYBESJRowO7/6OFBQ+BEA4FmK2nwDcsKOipezEvgFjtyZWQEdpT4 3BMZ76ShYYv28dCcPxn+GMD+5N6SryoKS9D9WdeqBhVvGvcRKuUQSzMdPV/TIq7E7FIm sDAuQW0Z7MVdxRzottg+5lzQsvkTq7yfRxxI24VTmgWOLG1j9N365LpJZ5UFyFPBmhFO M/BQVrKOeog0STxmwBEZiQxvlrN6YdronTBE5gVIj7tBhS7ef+jN3T7KMftsJ42hcG4J /J0A== X-Gm-Message-State: ALQs6tBtASePRfv5e/Two/EOv8LWI3lraJcYxO2P5XT1kXUN7KkR60gj V7qf0ItvQ56+ZgB17y9KTjX2ig== X-Received: by 10.80.152.227 with SMTP id j90mr32022808edb.89.1523874160729; Mon, 16 Apr 2018 03:22:40 -0700 (PDT) Received: from uhalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id h64sm7470734edc.19.2018.04.16.03.22.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Apr 2018 03:22:40 -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: axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH] lightnvm: pblk: remove unnecessary bio_get/put Date: Mon, 16 Apr 2018 12:22:37 +0200 Message-Id: <1523874157-5216-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 In the read path, pblk gets a reference to the incoming bio and puts it after ending the bio. Though this behavior is correct, it is unnecessary since pblk is the one putting the bio, therefore, it cannot disappear underneath it. Removing this reference, allows to clean up rqd->bio and avoid pointer bouncing for the different read paths. Now, the incoming bio always resides in the read context and pblk's internal bios (if any) reside in rqd->bio. Signed-off-by: Javier González --- drivers/lightnvm/pblk-read.c | 57 +++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/drivers/lightnvm/pblk-read.c b/drivers/lightnvm/pblk-read.c index 2f8224354c62..5464e4177c87 100644 --- a/drivers/lightnvm/pblk-read.c +++ b/drivers/lightnvm/pblk-read.c @@ -39,10 +39,10 @@ static int pblk_read_from_cache(struct pblk *pblk, struct bio *bio, } static void pblk_read_ppalist_rq(struct pblk *pblk, struct nvm_rq *rqd, - sector_t blba, unsigned long *read_bitmap) + struct bio *bio, sector_t blba, + unsigned long *read_bitmap) { struct pblk_sec_meta *meta_list = rqd->meta_list; - struct bio *bio = rqd->bio; struct ppa_addr ppas[PBLK_MAX_REQ_ADDRS]; int nr_secs = rqd->nr_ppas; bool advanced_bio = false; @@ -189,7 +189,6 @@ static void pblk_end_user_read(struct bio *bio) WARN_ONCE(bio->bi_status, "pblk: corrupted read bio\n"); #endif bio_endio(bio); - bio_put(bio); } static void __pblk_end_io_read(struct pblk *pblk, struct nvm_rq *rqd, @@ -197,23 +196,18 @@ static void __pblk_end_io_read(struct pblk *pblk, struct nvm_rq *rqd, { struct nvm_tgt_dev *dev = pblk->dev; struct pblk_g_ctx *r_ctx = nvm_rq_to_pdu(rqd); - struct bio *bio = rqd->bio; + struct bio *int_bio = rqd->bio; unsigned long start_time = r_ctx->start_time; generic_end_io_acct(dev->q, READ, &pblk->disk->part0, start_time); if (rqd->error) pblk_log_read_err(pblk, rqd); -#ifdef CONFIG_NVM_DEBUG - else - WARN_ONCE(bio->bi_status, "pblk: corrupted read error\n"); -#endif pblk_read_check_seq(pblk, rqd, r_ctx->lba); - bio_put(bio); - if (r_ctx->private) - pblk_end_user_read((struct bio *)r_ctx->private); + if (int_bio) + bio_put(int_bio); if (put_line) pblk_read_put_rqd_kref(pblk, rqd); @@ -230,16 +224,19 @@ static void __pblk_end_io_read(struct pblk *pblk, struct nvm_rq *rqd, static void pblk_end_io_read(struct nvm_rq *rqd) { struct pblk *pblk = rqd->private; + struct pblk_g_ctx *r_ctx = nvm_rq_to_pdu(rqd); + struct bio *bio = (struct bio *)r_ctx->private; + pblk_end_user_read(bio); __pblk_end_io_read(pblk, rqd, true); } -static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd, - unsigned int bio_init_idx, - unsigned long *read_bitmap) +static int pblk_partial_read(struct pblk *pblk, struct nvm_rq *rqd, + struct bio *orig_bio, unsigned int bio_init_idx, + unsigned long *read_bitmap) { - struct bio *new_bio, *bio = rqd->bio; struct pblk_sec_meta *meta_list = rqd->meta_list; + struct bio *new_bio; struct bio_vec src_bv, dst_bv; void *ppa_ptr = NULL; void *src_p, *dst_p; @@ -319,7 +316,7 @@ static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd, meta_list[hole].lba = lba_list_media[i]; src_bv = new_bio->bi_io_vec[i++]; - dst_bv = bio->bi_io_vec[bio_init_idx + hole]; + dst_bv = orig_bio->bi_io_vec[bio_init_idx + hole]; src_p = kmap_atomic(src_bv.bv_page); dst_p = kmap_atomic(dst_bv.bv_page); @@ -338,28 +335,26 @@ static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd, bio_put(new_bio); - /* Complete the original bio and associated request */ - bio_endio(bio); - rqd->bio = bio; + /* restore original request */ + rqd->bio = NULL; rqd->nr_ppas = nr_secs; __pblk_end_io_read(pblk, rqd, false); - return NVM_IO_OK; + return NVM_IO_DONE; err: pr_err("pblk: failed to perform partial read\n"); /* Free allocated pages in new bio */ - pblk_bio_free_pages(pblk, bio, 0, new_bio->bi_vcnt); + pblk_bio_free_pages(pblk, orig_bio, 0, new_bio->bi_vcnt); __pblk_end_io_read(pblk, rqd, false); return NVM_IO_ERR; } -static void pblk_read_rq(struct pblk *pblk, struct nvm_rq *rqd, +static void pblk_read_rq(struct pblk *pblk, struct nvm_rq *rqd, struct bio *bio, sector_t lba, unsigned long *read_bitmap) { struct pblk_sec_meta *meta_list = rqd->meta_list; - struct bio *bio = rqd->bio; struct ppa_addr ppa; pblk_lookup_l2p_seq(pblk, &ppa, lba, 1); @@ -423,14 +418,15 @@ int pblk_submit_read(struct pblk *pblk, struct bio *bio) rqd = pblk_alloc_rqd(pblk, PBLK_READ); rqd->opcode = NVM_OP_PREAD; - rqd->bio = bio; rqd->nr_ppas = nr_secs; + rqd->bio = NULL; /* cloned bio if needed */ rqd->private = pblk; rqd->end_io = pblk_end_io_read; r_ctx = nvm_rq_to_pdu(rqd); r_ctx->start_time = jiffies; r_ctx->lba = blba; + r_ctx->private = bio; /* original bio */ /* Save the index for this bio's start. This is needed in case * we need to fill a partial read. @@ -448,17 +444,15 @@ int pblk_submit_read(struct pblk *pblk, struct bio *bio) rqd->ppa_list = rqd->meta_list + pblk_dma_meta_size; rqd->dma_ppa_list = rqd->dma_meta_list + pblk_dma_meta_size; - pblk_read_ppalist_rq(pblk, rqd, blba, &read_bitmap); + pblk_read_ppalist_rq(pblk, rqd, bio, blba, &read_bitmap); } else { - pblk_read_rq(pblk, rqd, blba, &read_bitmap); + pblk_read_rq(pblk, rqd, bio, blba, &read_bitmap); } - bio_get(bio); if (bitmap_full(&read_bitmap, nr_secs)) { - bio_endio(bio); atomic_inc(&pblk->inflight_io); __pblk_end_io_read(pblk, rqd, false); - return NVM_IO_OK; + return NVM_IO_DONE; } /* All sectors are to be read from the device */ @@ -473,13 +467,10 @@ int pblk_submit_read(struct pblk *pblk, struct bio *bio) } rqd->bio = int_bio; - r_ctx->private = bio; ret = pblk_submit_io(pblk, rqd); if (ret) { pr_err("pblk: read IO submission failed\n"); - if (int_bio) - bio_put(int_bio); goto fail_end_io; } @@ -489,7 +480,7 @@ int pblk_submit_read(struct pblk *pblk, struct bio *bio) /* The read bio request could be partially filled by the write buffer, * but there are some holes that need to be read from the drive. */ - return pblk_partial_read_bio(pblk, rqd, bio_init_idx, &read_bitmap); + return pblk_partial_read(pblk, rqd, bio, bio_init_idx, &read_bitmap); fail_rqd_free: pblk_free_rqd(pblk, rqd, PBLK_READ); -- 2.7.4