From patchwork Fri Feb 10 10:56:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9566523 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 5A981601C3 for ; Fri, 10 Feb 2017 10:58:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 493652855E for ; Fri, 10 Feb 2017 10:58:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C98E28558; Fri, 10 Feb 2017 10:58:24 +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=ham 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 E672528558 for ; Fri, 10 Feb 2017 10:58:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752720AbdBJK6X (ORCPT ); Fri, 10 Feb 2017 05:58:23 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33996 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752604AbdBJK5C (ORCPT ); Fri, 10 Feb 2017 05:57:02 -0500 Received: by mail-pf0-f194.google.com with SMTP id o64so1420595pfb.1; Fri, 10 Feb 2017 02:56:39 -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=ksShTwDXvIxeZmfo01nywUSUGNciOmkbZQRV2T07X84=; b=ONfke85nUuYdWmlfsl6slOYKU2hD0a2STZFECpUPpW2oDQyuAx9YhK9KZAvpc2K0nW x4AFhgrw6jdWiCSEm44gDcIg9rBhMTBhgp4RQ2EAD1NrVA4GqglDohhShnuAiT8lDxKR F3OLH3IIDAYeMNnRMAxl87nk7qHPnoJCnj43vgKV30KMVckG/swntoJLrD9mdWWJvlcU 0zS/3E8qoFjUkut4O6kVz6hYREZqpjMcUcW/Pigv80j58U7AN67NcdQWpgLD7brryxYC 75x6IJqdSiT5SSYza/FDs2+zqSWu3p3j2HneDZXQ0GNWsHVuipbtYlnV+B6/fWqqMpzf lZmw== 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=ksShTwDXvIxeZmfo01nywUSUGNciOmkbZQRV2T07X84=; b=GpSDVar7ew5LrDDiQuvCw5N2mYrkTCpJ75Mh0o+vf302s5lHPNeR+TBCltDjQxuiit KjsNzbjaf+BbLkFoIuzmZIEJQ5mJtMLNcbSZ2OaHyzwzGR5/xJt/y+bvMQVdnDlkzshX FutcjPlQswxuiqq/51E/ZwC+TGyf4tHMkXjGV+M2085GcpYrD4Y4xbKXvvD6Skz+dIK3 tliJ4ep3/qkiymMgkjqoUAUcCz21xuCZW6HRz2/sozKGgUHV17X8G1N5TImgrIyPfhn6 HVspNY5Jg8L2/9Ia7UX4Fsk1wuI/zcF94MOoSNN5Mjx7hDQbxM2VAUTZKsASbuI9Cr/C uBlQ== X-Gm-Message-State: AMke39nGmFBtscZE/OrTcXBi5RLtSlCqLifeAApcNOyFrBEQi+bmxH3biSGTc+81evkKBQ== X-Received: by 10.99.94.198 with SMTP id s189mr9929430pgb.211.1486724199366; Fri, 10 Feb 2017 02:56:39 -0800 (PST) Received: from localhost (li405-222.members.linode.com. [106.187.53.222]) by smtp.gmail.com with ESMTPSA id g85sm4553264pfe.38.2017.02.10.02.56.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Feb 2017 02:56:38 -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 v1 2/5] md/raid1: use bio_clone_bioset_partial() in case of write behind Date: Fri, 10 Feb 2017 18:56:14 +0800 Message-Id: <1486724177-14817-3-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486724177-14817-1-git-send-email-tom.leiming@gmail.com> References: <1486724177-14817-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. Signed-off-by: Ming Lei Reviewed-by: Christoph Hellwig --- 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..4d7852c6ae97 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; + int 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;