From patchwork Tue Feb 14 15:29:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9572121 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 5DD7860578 for ; Tue, 14 Feb 2017 15:30:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5101E28394 for ; Tue, 14 Feb 2017 15:30:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45C0628428; Tue, 14 Feb 2017 15:30:12 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 6338C28408 for ; Tue, 14 Feb 2017 15:30:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932096AbdBNP3b (ORCPT ); Tue, 14 Feb 2017 10:29:31 -0500 Received: from mail-ot0-f194.google.com ([74.125.82.194]:33061 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752542AbdBNP3Y (ORCPT ); Tue, 14 Feb 2017 10:29:24 -0500 Received: by mail-ot0-f194.google.com with SMTP id t47so2205525ota.0; Tue, 14 Feb 2017 07:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aUrfUzKmfH4Oby4HaZQrkqWzilbOqmFOTJA0Lgkxstw=; b=FB9kZhRv7SWwURS7pujqGuZMwqDvHxxok/XRJiO7KSr2/gdvwysG3tYQLsYaHwgodV Gm+9fJ6Xo3Z+vcBHnGS/EqrgXmdw/ZtwpYJS4PhL0O+wZANqul3dXHhKB9OqPQn+ac0q KxJiLCGdHMg0ITVp4AU7DiRgUh5vZ4kvfsS5zo29PP3gUBYKjH6ea6SQUtQAfv33WNag w78Or+yblnLl2DKWeY/fU/PGdk7Ff30pZDqZ0gSBMNFSObkdkCjhU6kaWPcMDTJiu4RU AyVnbAy/srcyeP1GscQJjvseDHPb6Ai/z4YB9XYVAOOBSZdWPbgisEiBIDZC7sPt2QHa 5e1g== 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=aUrfUzKmfH4Oby4HaZQrkqWzilbOqmFOTJA0Lgkxstw=; b=r/NGcelarEjsm+sMmvQzCPILREd8e2vo55zwOs1r/c6dzGir8Om3oiCswxVjzq2xdL oMo8rMaZkk1zVr0+F/zcnTR/ki2c4ljw/OFXMrw2IWj+YL4+9dgkN0HTZQHlhlQPbL0b TtSOVGpYTBL5bLReHKkNeoKZ+NeoKMGK4yEoJ5CXkPLo9baFghT9FU3FGZ+oupI4ew7o BzvGUrRDnQRaFenuOZxJo56tHhdZtwt0XZF+mCUQF6iBZmP4hMVuFZhvLV3SxzCHPZk2 oIWRSgNFGcqmKYYQ+hkA+ySTO6VQLuBhZ6ABmWzliUasFf0jvbJZUVqIFsgneJanV1zG gtnQ== X-Gm-Message-State: AMke39kVS2loFFDW6RX6NtRGDUq6GEvIK1gmpwfbPDww+5PyTrrSCGiBXN9Ou0M/DVAysw== X-Received: by 10.99.157.135 with SMTP id i129mr33115129pgd.132.1487086162885; Tue, 14 Feb 2017 07:29:22 -0800 (PST) Received: from localhost (li405-222.members.linode.com. [106.187.53.222]) by smtp.gmail.com with ESMTPSA id m12sm2038342pgc.46.2017.02.14.07.29.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Feb 2017 07:29:22 -0800 (PST) From: Ming Lei To: Shaohua Li , Jens Axboe , linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig , NeilBrown Cc: Ming Lei Subject: [PATCH v2 3/5] md/raid1: use bio_clone_bioset_partial() in case of write behind Date: Tue, 14 Feb 2017 23:29:01 +0800 Message-Id: <1487086143-10255-4-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487086143-10255-1-git-send-email-tom.leiming@gmail.com> References: <1487086143-10255-1-git-send-email-tom.leiming@gmail.com> 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 Write behind need to replace pages in bio's bvecs, and we have to clone a fresh bio with new bvec table, so use the introduced bio_clone_bioset_partial() for it. For other bio_clone_mddev() cases, we will use fast clone since they don't need to touch bvec table. Reviewed-by: Christoph Hellwig Signed-off-by: Ming Lei --- drivers/md/raid1.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 830ff2b20346..b7548e0a9eca 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1341,13 +1341,12 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, first_clone = 1; for (i = 0; i < disks; i++) { - struct bio *mbio; + struct bio *mbio = NULL; + sector_t offset; if (!r1_bio->bios[i]) continue; - mbio = bio_clone_mddev(bio, GFP_NOIO, mddev); - bio_trim(mbio, r1_bio->sector - bio->bi_iter.bi_sector, - max_sectors); + offset = r1_bio->sector - bio->bi_iter.bi_sector; if (first_clone) { /* do behind I/O ? @@ -1357,8 +1356,13 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, if (bitmap && (atomic_read(&bitmap->behind_writes) < mddev->bitmap_info.max_write_behind) && - !waitqueue_active(&bitmap->behind_wait)) + !waitqueue_active(&bitmap->behind_wait)) { + mbio = bio_clone_bioset_partial(bio, GFP_NOIO, + mddev->bio_set, + offset, + max_sectors); alloc_behind_pages(mbio, r1_bio); + } bitmap_startwrite(bitmap, r1_bio->sector, r1_bio->sectors, @@ -1366,6 +1370,12 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, &r1_bio->state)); first_clone = 0; } + + if (!mbio) { + mbio = bio_clone_mddev(bio, GFP_NOIO, mddev); + bio_trim(mbio, offset, max_sectors); + } + if (r1_bio->behind_bvecs) { struct bio_vec *bvec; int j;