From patchwork Sun Feb 5 06:22:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9555909 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 23AC6604DA for ; Sun, 5 Feb 2017 06:23:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1435126E81 for ; Sun, 5 Feb 2017 06:23:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08D0827165; Sun, 5 Feb 2017 06:23:19 +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 AEB2726E81 for ; Sun, 5 Feb 2017 06:23:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752001AbdBEGWr (ORCPT ); Sun, 5 Feb 2017 01:22:47 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33188 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751891AbdBEGWp (ORCPT ); Sun, 5 Feb 2017 01:22:45 -0500 Received: by mail-pf0-f195.google.com with SMTP id e4so4544949pfg.0; Sat, 04 Feb 2017 22:22:44 -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=RYN2lWYZX8A1/3s7uUfpcF7n2/oPJxSwgsrpjBFESLc=; b=OHntbsOvHr2lpYFQQtF4JT2ZlP0EjL9xb5sN5AHi4nVCN9mS4HhLBKclOlV3LxSW6v h5AUMOChhZAwktYOKjRNieBhswSaAmgIm70nBz90gsplaqHkpdhiG3PiQSc1wWGZLiZ+ lL3TsaJ8Lfe6mn+tlk6kZhc4Ed7PradV+zE9sTd7SWnHI/FJoYC2xviXPtp+Z2us/Gm9 3rZjt38JnwbPYjZDWdefS5htSB6bBFnYSD95naVcssVGak4S+qipVarySH889UOHxVN/ +Dm8Qreg8uRZfmr4Upm16VrEXlMnabLQRWh7Ewgjb2dfc3u+z7Io+POWmICiqkl506e3 YgUg== 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=RYN2lWYZX8A1/3s7uUfpcF7n2/oPJxSwgsrpjBFESLc=; b=Hjq6Y2gdGe94/z+R4yudI6KFLIFcXI/5GCaiULUQJ+A1LUlI7cHiImBtBrwhbcDFdL rFuuJmN2vxJgSTAA7K2dBec6G3LAXsAieHXpc4Koi07KIvZoioozxMPVbowQaiC641Eh guYL+zyEy4oL1u3G5NdX0OWqqbYu/snC/Xj+mnO43a/JTA23/sDqZEzq5rVcSWOaqA/6 6o+UOJjcn0tQ/9CNIz3E7Wx+AhG31mtKdOFIwIuQjjkd521Rs8zuzW6kZaDJh/lyY5n+ 6PglFgcs+2C3HkGFSvNzJKkg5A3ypKoXcqdd8aWMyWTQSGoWTACcMsIJ13Aw7JDcRJIP reMw== X-Gm-Message-State: AIkVDXJxPDEQ04iNTLGj6o8diud3YigGb76PuCaV7foVYIM8lAqciuapylsM8qpwV7P5mw== X-Received: by 10.99.67.1 with SMTP id q1mr6486338pga.210.1486275759095; Sat, 04 Feb 2017 22:22:39 -0800 (PST) Received: from localhost (li405-222.members.linode.com. [106.187.53.222]) by smtp.gmail.com with ESMTPSA id c204sm78965137pfb.51.2017.02.04.22.22.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Feb 2017 22:22: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 3/4] md/raid1: use bio_clone_slow_mddev_partial in case of write behind Date: Sun, 5 Feb 2017 14:22:12 +0800 Message-Id: <1486275733-7268-4-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486275733-7268-1-git-send-email-tom.leiming@gmail.com> References: <1486275733-7268-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_slow_mddev_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 --- drivers/md/raid1.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 830ff2b20346..e1c5639febdb 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,14 @@ 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_slow_mddev_partial(bio, + GFP_NOIO, + mddev, + offset, + max_sectors); alloc_behind_pages(mbio, r1_bio); + } bitmap_startwrite(bitmap, r1_bio->sector, r1_bio->sectors, @@ -1366,6 +1371,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;