From patchwork Wed Nov 21 03:23:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09A6613BB for ; Wed, 21 Nov 2018 03:25:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECCC92B409 for ; Wed, 21 Nov 2018 03:25:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E00CA2B40A; Wed, 21 Nov 2018 03:25:03 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C4952B406 for ; Wed, 21 Nov 2018 03:25:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAFF26B2392; Tue, 20 Nov 2018 22:25:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B5D2D6B2393; Tue, 20 Nov 2018 22:25:02 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A280E6B2394; Tue, 20 Nov 2018 22:25:02 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id 747936B2392 for ; Tue, 20 Nov 2018 22:25:02 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id c84so5471725qkb.13 for ; Tue, 20 Nov 2018 19:25:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=ElsrrhpAVIbsmTVlPH0nJbaneQL9iVm2pKo9WSx+m1k=; b=DKBFYs3/huCXhpeVkn03eYKVrvz0LSdpwADp+m3C4l8i0kqf2cVx0Mu/nHwi4SiQmY nn9ZPPesMmkwnxrTowQjNrZayfnjQk9R63jUjjeesdSOwj/I/KyEI8V9Cxpo9hG58UVw jROqq2G+n9t2zuN6eTP8aVimoUFWK3qh6UZgOiqxWJCEPfgefdyqojCLcEeJDRXFhqXN RaiBql0mItCg/O75BGYLyXye9bdwV8uzSVp1bXKgelPnfNOI76i689IL5NsTsbrE4tbY pW8pz2HtxoSDkRiBQohz4qMMVUoknBHNXqMNAmflybPX2EShvh2kXrMZQHEp7Bj9VBXe ww2g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWaEEbvBE2Uhc3RF0IMZUM3r71VmbvwIJMkrMfp+QeZWY4Y2Q9IE pOH7nSG0IIm45HNNtM8VXCYtRMbHAqcELtvpQD+bLtW6QrQFhQ+Xe0ku+t6Hwd37mlX1Nue3aIs 5caWsokH/8e/YIEdh4DPajyfAs6fm5p3xWgnoRM6I8wTfNjRtjVYdJOtlW6A3tIO+Vg== X-Received: by 2002:a37:5bc1:: with SMTP id p184mr4197644qkb.121.1542770702241; Tue, 20 Nov 2018 19:25:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ve78mHdHFkbcYxz1Ki3lxPZMdnNP03oGfamwmp+iMdG6VrBqVI6b+vN+0SAIRDV10YKyPH X-Received: by 2002:a37:5bc1:: with SMTP id p184mr4197621qkb.121.1542770701575; Tue, 20 Nov 2018 19:25:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770701; cv=none; d=google.com; s=arc-20160816; b=ssheAglYzzQP+t5JLkvkLdJpu8kuB8s+o7/OfySei8/Z7EHNx3f97MyivqMCRzIQsG Haj89Htr1I+qTGG/+UaKabIG0jbnsLtwEv1DnpFYFAEHLg1u4ykCUgV1xglSzP9uPWyY rGmFcpYdkAFrwPJnuHKwOb3TbCcYbeuOt4Qa+K+1U8k1sWdtdkKXON3RH9HgyX7halc6 xq+AkIY6zBaBiD21PQyICbdZbIidsPkIbFRQUpGsuI2KZmLMnf0MqybjHEFR1k4rkdrX IA8ndBsai7aSARSTs/dc0fmslqYilcjUj8fAXgw+9TRCuS4OztgRXetXdmtU6+j9cPCf Pmnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=ElsrrhpAVIbsmTVlPH0nJbaneQL9iVm2pKo9WSx+m1k=; b=XiSWRC21EwgLWPZ8ncXyOVEda2SjXRjSZZUiiwmhyedjxfyyIt1a9nRu58wW37NLx7 U6gcDUbb2p1WeA+CcQ5P98p9ZNidQtp63o88h0b3idTew3irNdVah83k3xd8WfB2tESK 2EJlfuuaaEc7fwuKpZITqO+umImuZnFcUPHC+njyy0722EZwS8YqjAq5Su87t+xNEN1w wo6WUtw8pd2qa6ED+OG2lQ3YHrWnr48g2E6O/UPxgdbga0PAuHK/1b6P2y6PT9Eniiji jeFOk+kOHZDjE15STjNGR9p5hWKOMQkPx4d0kIX1dFCCIjJB2ecA91kw+0eo5O8e3G9C FEzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id l5si468786qkh.194.2018.11.20.19.25.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:25:01 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 81FB337E79; Wed, 21 Nov 2018 03:25:00 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97DDA608C4; Wed, 21 Nov 2018 03:24:46 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 01/19] block: don't use bio->bi_vcnt to figure out segment number Date: Wed, 21 Nov 2018 11:23:09 +0800 Message-Id: <20181121032327.8434-2-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 21 Nov 2018 03:25:00 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP It is wrong to use bio->bi_vcnt to figure out how many segments there are in the bio even though CLONED flag isn't set on this bio, because this bio may be splitted or advanced. So always use bio_segments() in blk_recount_segments(), and it shouldn't cause any performance loss now because the physical segment number is figured out in blk_queue_split() and BIO_SEG_VALID is set meantime since bdced438acd83ad83a6c ("block: setup bi_phys_segments after splitting"). Reviewed-by: Christoph Hellwig Fixes: 76d8137a3113 ("blk-merge: recaculate segment if it isn't less than max segments") Signed-off-by: Ming Lei --- block/blk-merge.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index b1df622cbd85..f52400ce2187 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -368,13 +368,7 @@ void blk_recalc_rq_segments(struct request *rq) void blk_recount_segments(struct request_queue *q, struct bio *bio) { - unsigned short seg_cnt; - - /* estimate segment number by bi_vcnt for non-cloned bio */ - if (bio_flagged(bio, BIO_CLONED)) - seg_cnt = bio_segments(bio); - else - seg_cnt = bio->bi_vcnt; + unsigned short seg_cnt = bio_segments(bio); if (test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags) && (seg_cnt < queue_max_segments(q))) From patchwork Wed Nov 21 03:23:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC12813BB for ; Wed, 21 Nov 2018 03:25:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B89592B406 for ; Wed, 21 Nov 2018 03:25:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC10A2B413; Wed, 21 Nov 2018 03:25:20 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 174CA2B406 for ; Wed, 21 Nov 2018 03:25:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 485566B2394; Tue, 20 Nov 2018 22:25:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 43FA36B2395; Tue, 20 Nov 2018 22:25:19 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FBFB6B2396; Tue, 20 Nov 2018 22:25:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id F3E046B2394 for ; Tue, 20 Nov 2018 22:25:18 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id c84so5472120qkb.13 for ; Tue, 20 Nov 2018 19:25:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=9sBbZxly7Ha46yKMPLQbnYuDoY9c8jcNIKOydaDcQGg=; b=LzUILfVexwJdbEeQzElb9yK2jGv/DzbI7DS5YW0Ty1XBSeRGUm+/uh8Tlh6pj7ILj0 vj70PIwJPxs1aDF/dHsxAh9LA4CgvTucQlF2NHrGYmpf4x5NV8f4nacpCXRf3LA7IX1a mGaVL5+h51oXXFSybWsUGfMU9/BrcZv3W4nQcxJ/1n8ixTV7ohg7nH9QtDp6OKS1LR7g BGg9/Bguzxz8vXyyMWJiNBwxoRIk4HZzCoNoMwEBVWeWgwVFTDOd24I8VD17PdsRI3f6 Z2NT92a8bJy7017esCPous/Bwh9XA4hBqcNiQEbov7SvSv5s8d4WT7wO5zv/71GqKt6A HnlA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gLCe8hPUCwPh09f3180qQYXl/ljJMcrpKRRjD4y6eCD4Rxw5dC/ IFZilYM4bXouy3/I24kCala8BBmQcujnNGdW8nqlhjQZ9qsOdL+LGlrWbndV4MHcH0dWJeA5A/L jRVR0DBZV1hmcXy9f6iRuNB+PfZ1tm2b07zNh59RnhJtlTuP8tcjtUXMZOLG6wjNRmw== X-Received: by 2002:ac8:1909:: with SMTP id t9mr4142905qtj.327.1542770718735; Tue, 20 Nov 2018 19:25:18 -0800 (PST) X-Google-Smtp-Source: AFSGD/UiHHeJTJBOvt3Y2YZYXVVdDoCwdwiexxuEpyC0T9leE5SuV28uCr0ijAF1rvqRp/3bvQcV X-Received: by 2002:ac8:1909:: with SMTP id t9mr4142879qtj.327.1542770718083; Tue, 20 Nov 2018 19:25:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770718; cv=none; d=google.com; s=arc-20160816; b=MT2wvfPExTHO/1P0QATiRPyfswa0Hs0NbvXwlTha3iOa0zmMUj3Mi1uHeXagzAPxWk Z9EbAgJIlZhVBoI82a8s+iU5LTFEUflvXKlOsjiyc/Ik/8FD9wyG0hm5j2HN3BFjvQU4 GSjQegBTZJYdr5ofysR6IwbyJ4d19f+a9b7rBQYq6GGqTKCNebd66W6kjhX9lL2rjhM8 wDl++ygWf3+Iw7DyBX3CCz+HjdC2gfiYH3CpMnlkm8rXQFuWi5Is+q93UshPAkQRq6iz TGeUQIoEGeB6Z4NFmyJTN3ypmj9tPByISWpUWX+ul6A4lHHitzXgbd7V160FnFireI6u UvVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=9sBbZxly7Ha46yKMPLQbnYuDoY9c8jcNIKOydaDcQGg=; b=gW3g1375/QS+GM/tm5kqpCfb03Oeh6kF3TgqZOFVA6rmbGOK/ixSRtpKWXpRftee4E 2Z0rErq7UVZX9z2YnALm1p+DSWtf60UPmUxFWvE7p0MFytb9yx4+V4xUhnmJiGtC1xcc j5qhGjqVhRu9fzGCI3v4gXJTcEVzDb3+aCkXnAcIMsqM96twtP4UY0AEzKTZV+BzwaZl pu1yC0rSB+w9/d1h3VB0IGC9yIlvNqwgNpUm+ZvM3bywQz4OXSCFp8lc7uEV4GcjQ3y8 4RAwS1bN29QZGT+/wA3prVjkPL4QLZNxcL3xMh6xoTS3dykYj63Eh5uVjtgMMv/bU75i 6fZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id q4si2945568qkj.161.2018.11.20.19.25.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:25:18 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E04BD81DE1; Wed, 21 Nov 2018 03:25:16 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFB61BABB; Wed, 21 Nov 2018 03:25:02 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 02/19] block: introduce multi-page bvec helpers Date: Wed, 21 Nov 2018 11:23:10 +0800 Message-Id: <20181121032327.8434-3-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 21 Nov 2018 03:25:17 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces helpers of 'segment_iter_*' for multipage bvec support. The introduced helpers treate one bvec as real multi-page segment, which may include more than one pages. The existed helpers of bvec_iter_* are interfaces for supporting current bvec iterator which is thought as single-page by drivers, fs, dm and etc. These introduced helpers will build single-page bvec in flight, so this way won't break current bio/bvec users, which needn't any change. Follows some multi-page bvec background: - bvecs stored in bio->bi_io_vec is always multi-page style - bvec(struct bio_vec) represents one physically contiguous I/O buffer, now the buffer may include more than one page after multi-page bvec is supported, and all these pages represented by one bvec is physically contiguous. Before multi-page bvec support, at most one page is included in one bvec, we call it single-page bvec. - .bv_page of the bvec points to the 1st page in the multi-page bvec - .bv_offset of the bvec is the offset of the buffer in the bvec The effect on the current drivers/filesystem/dm/bcache/...: - almost everyone supposes that one bvec only includes one single page, so we keep the sp interface not changed, for example, bio_for_each_segment() still returns single-page bvec - bio_for_each_segment_all() will return single-page bvec too - during iterating, iterator variable(struct bvec_iter) is always updated in multi-page bvec style, and bvec_iter_advance() is kept not changed - returned(copied) single-page bvec is built in flight by bvec helpers from the stored multi-page bvec Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- include/linux/bvec.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 02c73c6aa805..ed90bbf4c9c9 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -23,6 +23,7 @@ #include #include #include +#include /* * was unsigned short, but we might as well be ready for > 64kB I/O pages @@ -50,16 +51,35 @@ struct bvec_iter { */ #define __bvec_iter_bvec(bvec, iter) (&(bvec)[(iter).bi_idx]) -#define bvec_iter_page(bvec, iter) \ +#define segment_iter_page(bvec, iter) \ (__bvec_iter_bvec((bvec), (iter))->bv_page) -#define bvec_iter_len(bvec, iter) \ +#define segment_iter_len(bvec, iter) \ min((iter).bi_size, \ __bvec_iter_bvec((bvec), (iter))->bv_len - (iter).bi_bvec_done) -#define bvec_iter_offset(bvec, iter) \ +#define segment_iter_offset(bvec, iter) \ (__bvec_iter_bvec((bvec), (iter))->bv_offset + (iter).bi_bvec_done) +#define segment_iter_page_idx(bvec, iter) \ + (segment_iter_offset((bvec), (iter)) / PAGE_SIZE) + +/* + * of single-page segment. + * + * This helpers are for building single-page bvec in flight. + */ +#define bvec_iter_offset(bvec, iter) \ + (segment_iter_offset((bvec), (iter)) % PAGE_SIZE) + +#define bvec_iter_len(bvec, iter) \ + min_t(unsigned, segment_iter_len((bvec), (iter)), \ + PAGE_SIZE - bvec_iter_offset((bvec), (iter))) + +#define bvec_iter_page(bvec, iter) \ + nth_page(segment_iter_page((bvec), (iter)), \ + segment_iter_page_idx((bvec), (iter))) + #define bvec_iter_bvec(bvec, iter) \ ((struct bio_vec) { \ .bv_page = bvec_iter_page((bvec), (iter)), \ From patchwork Wed Nov 21 03:23:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4234E13BB for ; Wed, 21 Nov 2018 03:25:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3003F2B406 for ; Wed, 21 Nov 2018 03:25:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2418E2B412; Wed, 21 Nov 2018 03:25:34 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86F2E2B406 for ; Wed, 21 Nov 2018 03:25:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEB896B2396; Tue, 20 Nov 2018 22:25:32 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A9B1C6B2397; Tue, 20 Nov 2018 22:25:32 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 961E36B2398; Tue, 20 Nov 2018 22:25:32 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 679F56B2396 for ; Tue, 20 Nov 2018 22:25:32 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id u20so2180625qtk.6 for ; Tue, 20 Nov 2018 19:25:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=dATZ+onzNec9eH4mZTMiBL4VrKgcARS/iyEbycoE0rk=; b=kgniQQ/yfaViZrJingEqDHm+7Z/PU1yyunb5mT56OOfqnjmo2s/MVldbPLj6AdjDO2 SqwHvX4RzUrWRl7qStjQ3Tjufwj57nLr7H53NQM43QGqDYAfboC7iSptceAMUNa5Ki8R VSboZ63da/G4fL2/HgbI94O3scdCtnCJ38B9X4rC6z0SKNnUXhUj9eZ0O3lUcmkqtPBR FgRfhYCjfKQF2rfLx3YgWRHCjd4Z8i73ahz+Xqz3TXqrQYJ7jzyh9A31eeZlyGfkjLTG 4esAIJWXn7S3xuHZlhIFqAF4C9ysDy7zMlW8vOhwM2Nb2mlY5OxmPpB0FEoSUjY+5zwv wH5Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gJW7DCImarok0ccNssURUPqWlciudLVmXihPRurM836L8WkfZvU eZQBnUm/dWLu2F4gkMde2sxjc2tlhkK59wgnzSyKUavbOocabK6UAuhG0MS5XJI4KdoesPTcrGU DMKsCP20vrmwk9wReIw3+OZhI3gaau09DLR8lGeRagAoe7fn1bxQhPVTe67q/CsoEvQ== X-Received: by 2002:ac8:39c2:: with SMTP id v60mr4324249qte.142.1542770732188; Tue, 20 Nov 2018 19:25:32 -0800 (PST) X-Google-Smtp-Source: AJdET5cHMTfpoQwOq89DOEZxzTbUcQ1qz9jqpAzqbGJEtmRJlGkduTuBa23PJcOKqX+dJ+F93nMg X-Received: by 2002:ac8:39c2:: with SMTP id v60mr4324226qte.142.1542770731391; Tue, 20 Nov 2018 19:25:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770731; cv=none; d=google.com; s=arc-20160816; b=Xa+X42/Y9irGKWLIVCoQ3+ns3ROWh1d+uK3aSi9IVE9VfmxsDwrf3df1Bna3Fi2RL5 Mp1y5FHrUgjyKd9AsMFnxYj2qMRnu/aTOOPsiNQIyhHqq36gDdaWsOgEJ2h6TwBk7Jkm nDJ1aMaCWAC4tTcmjL7ObP7GoU3BxPDBSfUWXnAc3ugrTqaQhS5iHIseX1uDWZG2Bnlv 1ro0/vOaFGOu3dhA75f2kqZMPVr+iZNfld/IgWRCQqjXy6Roxego72DWGKNlHWyamTYX klszbyD3EphX9ec6yGUOXIpiQvZa9HeE6hO2ZZEnExTaHHlDxC014oRdZH/cYZUPms/+ CRpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=dATZ+onzNec9eH4mZTMiBL4VrKgcARS/iyEbycoE0rk=; b=ixN2CPTCJrbZtTtsQtOZZMlRuimiD/CqPttlmq/z31RmqVQb5331FokH012hXTTeyK QO25hVZm3qgY8ib2BAeB25i0h8073uTjwxvhS32F9S7PfV6MK0ay7yU5R5O2yZMOlC3N lJBiDZHcl+cAETyF1YrvqU6w8X3uGOuakGAglZ6//V/m2AmtJzQt2f/XE7YRGZWOcQEi xwtUX81hHvkpwQVnos3ZFdXAM1RUY1+t2tLEk63WLrp6c1R6EDC3s5TrjuNcA/xpsX3h rN0Tx5ejZY+rG4zvY3hPqmG7rSern0lHzjOM2uthhowGKWz0TPcsL7r/A2dxb6Up0V0x mGKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id n127si4589244qkf.230.2018.11.20.19.25.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:25:31 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47485C050DFB; Wed, 21 Nov 2018 03:25:30 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 187B47E102; Wed, 21 Nov 2018 03:25:18 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 03/19] block: introduce bio_for_each_bvec() Date: Wed, 21 Nov 2018 11:23:11 +0800 Message-Id: <20181121032327.8434-4-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 21 Nov 2018 03:25:30 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This helper is used for iterating over multi-page bvec for bio split & merge code. Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- include/linux/bio.h | 25 ++++++++++++++++++++++--- include/linux/bvec.h | 36 +++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index 056fb627edb3..7560209d6a8a 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -76,6 +76,9 @@ #define bio_data_dir(bio) \ (op_is_write(bio_op(bio)) ? WRITE : READ) +#define bio_iter_mp_iovec(bio, iter) \ + segment_iter_bvec((bio)->bi_io_vec, (iter)) + /* * Check whether this bio carries any data or not. A NULL bio is allowed. */ @@ -135,18 +138,24 @@ static inline bool bio_full(struct bio *bio) #define bio_for_each_segment_all(bvl, bio, i) \ for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++) -static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, - unsigned bytes) +static inline void __bio_advance_iter(struct bio *bio, struct bvec_iter *iter, + unsigned bytes, unsigned max_seg_len) { iter->bi_sector += bytes >> 9; if (bio_no_advance_iter(bio)) iter->bi_size -= bytes; else - bvec_iter_advance(bio->bi_io_vec, iter, bytes); + __bvec_iter_advance(bio->bi_io_vec, iter, bytes, max_seg_len); /* TODO: It is reasonable to complete bio with error here. */ } +static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, + unsigned bytes) +{ + __bio_advance_iter(bio, iter, bytes, PAGE_SIZE); +} + #define __bio_for_each_segment(bvl, bio, iter, start) \ for (iter = (start); \ (iter).bi_size && \ @@ -156,6 +165,16 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, #define bio_for_each_segment(bvl, bio, iter) \ __bio_for_each_segment(bvl, bio, iter, (bio)->bi_iter) +#define __bio_for_each_bvec(bvl, bio, iter, start) \ + for (iter = (start); \ + (iter).bi_size && \ + ((bvl = bio_iter_mp_iovec((bio), (iter))), 1); \ + __bio_advance_iter((bio), &(iter), (bvl).bv_len, BVEC_MAX_LEN)) + +/* returns one real segment(multi-page bvec) each time */ +#define bio_for_each_bvec(bvl, bio, iter) \ + __bio_for_each_bvec(bvl, bio, iter, (bio)->bi_iter) + #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len) static inline unsigned bio_segments(struct bio *bio) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index ed90bbf4c9c9..b279218c5c4d 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -25,6 +25,8 @@ #include #include +#define BVEC_MAX_LEN ((unsigned int)-1) + /* * was unsigned short, but we might as well be ready for > 64kB I/O pages */ @@ -87,8 +89,15 @@ struct bvec_iter { .bv_offset = bvec_iter_offset((bvec), (iter)), \ }) -static inline bool bvec_iter_advance(const struct bio_vec *bv, - struct bvec_iter *iter, unsigned bytes) +#define segment_iter_bvec(bvec, iter) \ +((struct bio_vec) { \ + .bv_page = segment_iter_page((bvec), (iter)), \ + .bv_len = segment_iter_len((bvec), (iter)), \ + .bv_offset = segment_iter_offset((bvec), (iter)), \ +}) + +static inline bool __bvec_iter_advance(const struct bio_vec *bv, + struct bvec_iter *iter, unsigned bytes, unsigned max_seg_len) { if (WARN_ONCE(bytes > iter->bi_size, "Attempted to advance past end of bvec iter\n")) { @@ -97,12 +106,18 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, } while (bytes) { - unsigned iter_len = bvec_iter_len(bv, *iter); - unsigned len = min(bytes, iter_len); + unsigned segment_len = segment_iter_len(bv, *iter); - bytes -= len; - iter->bi_size -= len; - iter->bi_bvec_done += len; + if (max_seg_len < BVEC_MAX_LEN) + segment_len = min_t(unsigned, segment_len, + max_seg_len - + bvec_iter_offset(bv, *iter)); + + segment_len = min(bytes, segment_len); + + bytes -= segment_len; + iter->bi_size -= segment_len; + iter->bi_bvec_done += segment_len; if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) { iter->bi_bvec_done = 0; @@ -136,6 +151,13 @@ static inline bool bvec_iter_rewind(const struct bio_vec *bv, return true; } +static inline bool bvec_iter_advance(const struct bio_vec *bv, + struct bvec_iter *iter, + unsigned bytes) +{ + return __bvec_iter_advance(bv, iter, bytes, PAGE_SIZE); +} + #define for_each_bvec(bvl, bio_vec, iter, start) \ for (iter = (start); \ (iter).bi_size && \ From patchwork Wed Nov 21 03:23:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE95D16B1 for ; Wed, 21 Nov 2018 03:25:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B8512B406 for ; Wed, 21 Nov 2018 03:25:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FBE32B40A; Wed, 21 Nov 2018 03:25:50 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F6882B406 for ; Wed, 21 Nov 2018 03:25:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3729B6B2399; Tue, 20 Nov 2018 22:25:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 320286B239A; Tue, 20 Nov 2018 22:25:49 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E8A66B239B; Tue, 20 Nov 2018 22:25:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id E40DC6B2399 for ; Tue, 20 Nov 2018 22:25:48 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id f22so5408066qkm.11 for ; Tue, 20 Nov 2018 19:25:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=wqdoEzWuH2Khs9YEZzBBs3VzYLH7cCmoAFW+Gss4ZYc=; b=JIdOiEUvClPLNMOTg6Wi/x3PI+WHiq1dgdv2dBYTUGij4tE6AFXHUmu9e7rr4wkNlW /Eiknv/20QJVkbs0Q3Gni8uSV284nXl62JxOTrg3o/FSza4IgBW5pGH/GFH5mld3oslw hIRw8J6s48uLiZaTqzakXWwV1+Y4tqaN+sJ4K16qhx6e5JA6yDcdJafaxmGnULauXkP5 dNE+h6+uair5P4Kq3zGLmT58ryXGjKUAMJH4Y1uxIA2I94F1VZdKF2U6Dl0/3jIZbrsJ iwjKBQcN3QNa6ICBcRBw2uw9EPZgi+Gn3GVO5iFHDmEJiUmq5XrxOXXFtIGEuUj2ZcvE 6a/A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWYXNuYRMvY/Rz+VxSUaeaqTyPyTNGzwnJ4pYnMMjTbhoYF5kxOP IuRWMRXeqMdo7B/h1d7i25LWHtXMaeabFftECAAApNYMH1iq393WT0akRZY7tsEMvRHlheNZYJT 4Y2XVqSze02XArYToq6b4YuU92O828dTcMpVAeruPRNVlaRWVamk+ffONdimJQDQ9/w== X-Received: by 2002:ac8:7482:: with SMTP id v2mr4477123qtq.57.1542770748686; Tue, 20 Nov 2018 19:25:48 -0800 (PST) X-Google-Smtp-Source: AJdET5fuRxJAR+9TeDCEBncmui4SozBJDEouwA/Us6wwfNhC4fF+U8xUXifF5Zlm/VfkuxBfDBYS X-Received: by 2002:ac8:7482:: with SMTP id v2mr4477106qtq.57.1542770748016; Tue, 20 Nov 2018 19:25:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770747; cv=none; d=google.com; s=arc-20160816; b=ukPZM+uIL6jl8vlY0vTaTiK8Vi9xrTU4z7n+a6Xfp1AM7v6L5uKwg1yy8bSgpEWLam nHYVq9sg3QBcB4aOROErPpUhhOe3PfjsxzWe0rV68tiSuUJGEvQIEI6v5tMQoskwsUEf IPjD9edV7hoXL/w5vKwfLmmATrlj5kNrpjbaIBeX0qVcyRXQRvLdhnMdyT5Z8Pudld7Z PDDXQAvUCuiN6GTNzdNwDEVkZU5K8TCITzoCVWE56xkYxHulu6xEETno0mWsth0wlHHr zv9+LipsysnPJ4LEcriRI6FAhFIC529nwNXQOvZT+xbsVTaC99hhSxgA2vZpvFHca8J6 ZnIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=wqdoEzWuH2Khs9YEZzBBs3VzYLH7cCmoAFW+Gss4ZYc=; b=tWic0biHVkwjUIu++jm6KU7jvEaldWIYiA+HqoSI0V0ykJduwjbcIoNRXZFAGpTkQp EnWOSXJqsfVJb8dD3uLU6iuH/IJ0RrngBux72toqzoOiYkg6dsLo1ask+kU2mtPSf5Kf HJ417u5nx9Ep2/chKAMRt2DpOgg88goUTv838rcFdSt0AnhGGTVCrjOGbGNJAwX+EadR VqEf4qjU6X5WZcwnSJ5y9BDywz2HSPUkmg4hQPVtj7XJTpEDtM8/R9NCkXmzKVZivucG Y1A2okXw7QaTXcxns/ra49QXk/3xX3XI4NYFfUnzOfW4uXQg/MA6CbOLmb0KC3MKjgKY 0Dog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 14si5809585qka.272.2018.11.20.19.25.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:25:47 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B820B811D7; Wed, 21 Nov 2018 03:25:46 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69B805C221; Wed, 21 Nov 2018 03:25:32 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 04/19] block: use bio_for_each_bvec() to compute multi-page bvec count Date: Wed, 21 Nov 2018 11:23:12 +0800 Message-Id: <20181121032327.8434-5-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 21 Nov 2018 03:25:47 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP First it is more efficient to use bio_for_each_bvec() in both blk_bio_segment_split() and __blk_recalc_rq_segments() to compute how many multi-page bvecs there are in the bio. Secondly once bio_for_each_bvec() is used, the bvec may need to be splitted because its length can be very longer than max segment size, so we have to split the big bvec into several segments. Thirdly when splitting multi-page bvec into segments, the max segment limit may be reached, so the bio split need to be considered under this situation too. Signed-off-by: Ming Lei --- block/blk-merge.c | 87 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index f52400ce2187..ec0b93fa1ff8 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -161,6 +161,54 @@ static inline unsigned get_max_io_size(struct request_queue *q, return sectors; } +/* + * Split the bvec @bv into segments, and update all kinds of + * variables. + */ +static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv, + unsigned *nsegs, unsigned *last_seg_size, + unsigned *front_seg_size, unsigned *sectors) +{ + unsigned len = bv->bv_len; + unsigned total_len = 0; + unsigned new_nsegs = 0, seg_size = 0; + + /* + * Multipage bvec may be too big to hold in one segment, + * so the current bvec has to be splitted as multiple + * segments. + */ + while (len && new_nsegs + *nsegs < queue_max_segments(q)) { + seg_size = min(queue_max_segment_size(q), len); + + new_nsegs++; + total_len += seg_size; + len -= seg_size; + + if ((bv->bv_offset + total_len) & queue_virt_boundary(q)) + break; + } + + /* update front segment size */ + if (!*nsegs) { + unsigned first_seg_size = seg_size; + + if (new_nsegs > 1) + first_seg_size = queue_max_segment_size(q); + if (*front_seg_size < first_seg_size) + *front_seg_size = first_seg_size; + } + + /* update other varibles */ + *last_seg_size = seg_size; + *nsegs += new_nsegs; + if (sectors) + *sectors += total_len >> 9; + + /* split in the middle of the bvec if len != 0 */ + return !!len; +} + static struct bio *blk_bio_segment_split(struct request_queue *q, struct bio *bio, struct bio_set *bs, @@ -174,7 +222,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, struct bio *new = NULL; const unsigned max_sectors = get_max_io_size(q, bio); - bio_for_each_segment(bv, bio, iter) { + bio_for_each_bvec(bv, bio, iter) { /* * If the queue doesn't support SG gaps and adding this * offset would create a gap, disallow it. @@ -189,8 +237,12 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, */ if (nsegs < queue_max_segments(q) && sectors < max_sectors) { - nsegs++; - sectors = max_sectors; + /* split in the middle of bvec */ + bv.bv_len = (max_sectors - sectors) << 9; + bvec_split_segs(q, &bv, &nsegs, + &seg_size, + &front_seg_size, + §ors); } goto split; } @@ -212,14 +264,12 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, if (nsegs == queue_max_segments(q)) goto split; - if (nsegs == 1 && seg_size > front_seg_size) - front_seg_size = seg_size; - - nsegs++; bvprv = bv; bvprvp = &bvprv; - seg_size = bv.bv_len; - sectors += bv.bv_len >> 9; + + if (bvec_split_segs(q, &bv, &nsegs, &seg_size, + &front_seg_size, §ors)) + goto split; } @@ -233,8 +283,6 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, bio = new; } - if (nsegs == 1 && seg_size > front_seg_size) - front_seg_size = seg_size; bio->bi_seg_front_size = front_seg_size; if (seg_size > bio->bi_seg_back_size) bio->bi_seg_back_size = seg_size; @@ -297,6 +345,7 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q, struct bio_vec bv, bvprv = { NULL }; int cluster, prev = 0; unsigned int seg_size, nr_phys_segs; + unsigned front_seg_size = bio->bi_seg_front_size; struct bio *fbio, *bbio; struct bvec_iter iter; @@ -317,7 +366,7 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q, seg_size = 0; nr_phys_segs = 0; for_each_bio(bio) { - bio_for_each_segment(bv, bio, iter) { + bio_for_each_bvec(bv, bio, iter) { /* * If SG merging is disabled, each bio vector is * a segment @@ -337,20 +386,20 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q, continue; } new_segment: - if (nr_phys_segs == 1 && seg_size > - fbio->bi_seg_front_size) - fbio->bi_seg_front_size = seg_size; + if (nr_phys_segs == 1 && seg_size > front_seg_size) + front_seg_size = seg_size; - nr_phys_segs++; bvprv = bv; prev = 1; - seg_size = bv.bv_len; + bvec_split_segs(q, &bv, &nr_phys_segs, &seg_size, + &front_seg_size, NULL); } bbio = bio; } - if (nr_phys_segs == 1 && seg_size > fbio->bi_seg_front_size) - fbio->bi_seg_front_size = seg_size; + if (nr_phys_segs == 1 && seg_size > front_seg_size) + front_seg_size = seg_size; + fbio->bi_seg_front_size = front_seg_size; if (seg_size > bbio->bi_seg_back_size) bbio->bi_seg_back_size = seg_size; From patchwork Wed Nov 21 03:23:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 537DF1923 for ; Wed, 21 Nov 2018 03:26:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D4B72B406 for ; Wed, 21 Nov 2018 03:26:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30D532B40A; Wed, 21 Nov 2018 03:26:10 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEFD82B409 for ; Wed, 21 Nov 2018 03:26:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E205D6B239B; Tue, 20 Nov 2018 22:26:08 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DCDA96B239C; Tue, 20 Nov 2018 22:26:08 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C97B56B239D; Tue, 20 Nov 2018 22:26:08 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by kanga.kvack.org (Postfix) with ESMTP id 9C1E86B239B for ; Tue, 20 Nov 2018 22:26:08 -0500 (EST) Received: by mail-qt1-f198.google.com with SMTP id j5so2168383qtk.11 for ; Tue, 20 Nov 2018 19:26:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=ctB9bvpZ9ruaYVuIaoGAbYczS2Xsp8WdFrFGH1VOZb8=; b=gm1jJ40IrZX7yjgB7n1QCX57OGtp0AwbpoE8VKcH5o6ljwGGfX+Qe11NdvvIPP1F+o DJYgyf5xBDQrNGmNiwL1yW/ffSwdvdCNrRUmtmSQXeYGBYO21ld5vmFlhyzn2uGSeOXC dzMGEX4OPo9MOLEyfn7Uek8XGv17DCO0RCDGmxBNTNyEcCC33yEBZx5pYCAtimFLdnZq OZhlpuzo45yyKL5MSps+BWH4IUU2atL9LTzwSn72MlWcwHt9Ta4yyv02bktfFIxJGeXu 8rEP4dSum2mq605HNFXDQweHUpc0MfLoVy4bQ/G9c1blEzrpFOzEmHqSj9DoXs0tmVZF DWgQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWbnBV8YTBdBWXlhufDbbamspA6uhxNyj+O1+t9rtBvBrRYxFmDj iQlzJ45BIVdE7klIQsSknFeGwixSK1xyGhAaYnisIy1MIy5B8Db+VeJf0IqJRK5BLdSRXWMlpoV PWBfXDh1MmXso+lw4xKr8THp7devyvMb9wAG2jSueaRZL9ewaat9G1vUpA+b1mA8PuA== X-Received: by 2002:a37:f8c:: with SMTP id 12mr1132480qkp.48.1542770768417; Tue, 20 Nov 2018 19:26:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/WUTBqFVDnU4fS0tIQ1HCepH/Vq9GXJEgA6fnbWB48lpUV2DXfNxXh3US6gbjwQLRHrKsPj X-Received: by 2002:a37:f8c:: with SMTP id 12mr1132459qkp.48.1542770767642; Tue, 20 Nov 2018 19:26:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770767; cv=none; d=google.com; s=arc-20160816; b=p43NRftd6LrLFVVPn6EBxRBWgxc6xkkbb229Dzlk8dZrs1ga3lskyyuVKhFkj/hM2+ fXzgche8f+iPGy+Z3r/nf+BtzZyjMyNZbMI90EsXg4jp4q5rt24cv3jn9rQbLzib0UxL +hxJWWzZXffpyE2VEbySD+7aGxBMBw+LdB04UX8FUI22zY77/py+byPmCPiRa5cHB0Zm lKFo+bBZLqQRQ2w1aj9lk3l7o+qG0L08k9NLAPtXpq6b7PK8YSW5iIrAk+bFF/dQI2D/ aeBNWRBFxj+ao/QmSLigyIzYBa7iBRrzJGazjD93uXtyTFlZ9BPn16xaJhsV/SvfpdgM Omhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=ctB9bvpZ9ruaYVuIaoGAbYczS2Xsp8WdFrFGH1VOZb8=; b=QDnu41HMkAh3cknDZB0f/CQDswnhz+7WU/CsYyZps5S9B0Ix2rXilUnb3xTuN0OVV+ gU4ZaOoRyq7TlmHL8OwPN4MTcMyw19NzUlDVzDe7fLWcc5TRQmonnU2O5RA4NT4yu6VU GIHW6/hP/cn03X6Rm9o+ijb7JkPN/AnA0cvm2AEtHaI2yW4UcxZkLCkEgTOmhVUq33y2 8WH1GsxYF0wZQIr4RkGY2TWk4ozRh4GABbjo92FAhGqv9++NUKwDplz69Y0rth1dg5Sv tP1Dis0F17cbITnGj3zg1Wp164ZHFgfttsdwsqy6sP0TW/2VoAz9XmhDw7tmxlQxeq44 3XMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id l8si202245qte.153.2018.11.20.19.26.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:26:07 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59539308428D; Wed, 21 Nov 2018 03:26:06 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA5367D2CF; Wed, 21 Nov 2018 03:25:48 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 05/19] block: use bio_for_each_bvec() to map sg Date: Wed, 21 Nov 2018 11:23:13 +0800 Message-Id: <20181121032327.8434-6-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 21 Nov 2018 03:26:06 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP It is more efficient to use bio_for_each_bvec() to map sg, meantime we have to consider splitting multipage bvec as done in blk_bio_segment_split(). Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- block/blk-merge.c | 68 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index ec0b93fa1ff8..8829c51b4e75 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -455,6 +455,52 @@ static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio, return biovec_phys_mergeable(q, &end_bv, &nxt_bv); } +static struct scatterlist *blk_next_sg(struct scatterlist **sg, + struct scatterlist *sglist) +{ + if (!*sg) + return sglist; + + /* + * If the driver previously mapped a shorter list, we could see a + * termination bit prematurely unless it fully inits the sg table + * on each mapping. We KNOW that there must be more entries here + * or the driver would be buggy, so force clear the termination bit + * to avoid doing a full sg_init_table() in drivers for each command. + */ + sg_unmark_end(*sg); + return sg_next(*sg); +} + +static unsigned blk_bvec_map_sg(struct request_queue *q, + struct bio_vec *bvec, struct scatterlist *sglist, + struct scatterlist **sg) +{ + unsigned nbytes = bvec->bv_len; + unsigned nsegs = 0, total = 0; + + while (nbytes > 0) { + unsigned seg_size; + struct page *pg; + unsigned offset, idx; + + *sg = blk_next_sg(sg, sglist); + + seg_size = min(nbytes, queue_max_segment_size(q)); + offset = (total + bvec->bv_offset) % PAGE_SIZE; + idx = (total + bvec->bv_offset) / PAGE_SIZE; + pg = nth_page(bvec->bv_page, idx); + + sg_set_page(*sg, pg, seg_size, offset); + + total += seg_size; + nbytes -= seg_size; + nsegs++; + } + + return nsegs; +} + static inline void __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec, struct scatterlist *sglist, struct bio_vec *bvprv, @@ -472,25 +518,7 @@ __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec, (*sg)->length += nbytes; } else { new_segment: - if (!*sg) - *sg = sglist; - else { - /* - * If the driver previously mapped a shorter - * list, we could see a termination bit - * prematurely unless it fully inits the sg - * table on each mapping. We KNOW that there - * must be more entries here or the driver - * would be buggy, so force clear the - * termination bit to avoid doing a full - * sg_init_table() in drivers for each command. - */ - sg_unmark_end(*sg); - *sg = sg_next(*sg); - } - - sg_set_page(*sg, bvec->bv_page, nbytes, bvec->bv_offset); - (*nsegs)++; + (*nsegs) += blk_bvec_map_sg(q, bvec, sglist, sg); } *bvprv = *bvec; } @@ -512,7 +540,7 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio, int cluster = blk_queue_cluster(q), nsegs = 0; for_each_bio(bio) - bio_for_each_segment(bvec, bio, iter) + bio_for_each_bvec(bvec, bio, iter) __blk_segment_map_sg(q, &bvec, sglist, &bvprv, sg, &nsegs, &cluster); From patchwork Wed Nov 21 03:23:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88AA013BB for ; Wed, 21 Nov 2018 03:26:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74DCB2B406 for ; Wed, 21 Nov 2018 03:26:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68FB72B412; Wed, 21 Nov 2018 03:26: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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E9352B406 for ; Wed, 21 Nov 2018 03:26:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E5276B239E; Tue, 20 Nov 2018 22:26:23 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 393926B239F; Tue, 20 Nov 2018 22:26:23 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 284386B23A0; Tue, 20 Nov 2018 22:26:23 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id EB9BB6B239E for ; Tue, 20 Nov 2018 22:26:22 -0500 (EST) Received: by mail-qk1-f198.google.com with SMTP id c84so5473794qkb.13 for ; Tue, 20 Nov 2018 19:26:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=M9HjZiyQLRotInpEIRM/jIIFKCG3bEPf2w3BspfUEys=; b=WvCi/3JVFXGqaDjExMh224Xk/5VZfSof0v3gofqDqMMK/vpHwX63b8FVkcgeyhsYub Ep8HDhT3i10HqrVGgB+Se3NZJHK/fDZbrKXoD8ix5zI618D0Sy05R/IAUFQEgcC9u9L6 JXNEvG0pY7NerYsk7rAAS3zZCcT2eVkFm3bKnT+nvfhNs+Ub4yoJ2uuJvOUnfsNkAofY Tr0iIKJIKa7GKp+XEy5tXL+sSJGaniUt5bPILv4osljieOHCgZ8ohcdrNHjfiD7BYmFz V6iydZQ3ZYzq+zDGBJ3vjzLmb7WGD3Z6DEzyFdm5AudEe9ykqRnyoArRc0C5dWzFm3CS oueQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWYzHR34xva3rmIX5TdFHAy9tkIIOQuZW3lJ4/Fg8HY2OIr4JJHY 4+UBCZq5xCI3pARPGoaiQtOc4bAcfycFFryp36qJXZnUTguL+G+o4N9e7u7MT8rEldDRCb6PMnf lxSs8HlxYVtwHO3o4u9DsRvZsL5mna6sOLkt9lYewvMFhaz6TWwsoNLSlhlQe9Gk8Sg== X-Received: by 2002:a0c:e9c4:: with SMTP id q4mr4447981qvo.18.1542770782741; Tue, 20 Nov 2018 19:26:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/WKNePAObBpgOzFzz7U6p4AIt4iZLJZkFIBYs3I+rFhpvMQfRiXVZSrPGIGcXwLxiBJLOGT X-Received: by 2002:a0c:e9c4:: with SMTP id q4mr4447958qvo.18.1542770782096; Tue, 20 Nov 2018 19:26:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770782; cv=none; d=google.com; s=arc-20160816; b=Da+RWmXizD0wJNnnPMvV2ynU0KvRJFaez+IUbaOFXLlK7Teos+oD055svp6LzZpiI1 pnvrmr93y7To6y0pedVEvn0IPrTAGZWK5/C560TgiMCJoEdi6krDWeUi8whZzrHVuW2Y w1VRRO/EngJsFAEz0iNOhgjzrdzfAwMCmWr6YuzaRmJBqBYMiJLUa5iPF1gL4TgOFQ5v jYFHhdMcq5ZA3FviooG2SbvVRUf/5cxsdypckye7rPNTYPXzLRYhk265JGjUUYUcD/Ow yY++vchaZEXMcwKst5mP8v6cuFKKJBAxWCEWm/a5DqjzTCRY+CnoX5g4mCU+qMwkx+kW uvdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=M9HjZiyQLRotInpEIRM/jIIFKCG3bEPf2w3BspfUEys=; b=QGeuxu2HPA4NbvKS3XGAWCGLiVnwlRsFpfOsvw6Y9FxqfPdHICYA+jc/m/pXD9h98K 18jXBsNOmAQTcs0kh4ZXGw51DtOYsBm+hsIg61+guZapXBeFPndq6S1Qo0MSXB0elxYr doF9M6vNzVrS6qsvE8jHy8FZJ4qhsWw1IuaKVTfBjyWpJUkDKird20KovoLUTwbbKS5W +42oOWFfUtTD0PMIMBT+AsUG6vHQdLZ7P5ZheOgk1RBRcDk6ord3pajv3CcjdBB6CIL/ tLIVFcKTpnoz1kbKc8OZgI5UTgcKG072LNtjNXYclmHWndhPpFVe/uX0/ey74mp8QOlB MoRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id d42si5030617qve.68.2018.11.20.19.26.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:26:22 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E170C308FB94; Wed, 21 Nov 2018 03:26:20 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 874A7600C5; Wed, 21 Nov 2018 03:26:08 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 06/19] block: introduce bvec_last_segment() Date: Wed, 21 Nov 2018 11:23:14 +0800 Message-Id: <20181121032327.8434-7-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 21 Nov 2018 03:26:21 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP BTRFS and guard_bio_eod() need to get the last singlepage segment from one multipage bvec, so introduce this helper to make them happy. Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- include/linux/bvec.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index b279218c5c4d..b37d13a79a7d 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -173,4 +173,26 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +/* + * Get the last single-page segment from the multi-page bvec and store it + * in @seg + */ +static inline void bvec_last_segment(const struct bio_vec *bvec, + struct bio_vec *seg) +{ + unsigned total = bvec->bv_offset + bvec->bv_len; + unsigned last_page = (total - 1) / PAGE_SIZE; + + seg->bv_page = nth_page(bvec->bv_page, last_page); + + /* the whole segment is inside the last page */ + if (bvec->bv_offset >= last_page * PAGE_SIZE) { + seg->bv_offset = bvec->bv_offset % PAGE_SIZE; + seg->bv_len = bvec->bv_len; + } else { + seg->bv_offset = 0; + seg->bv_len = total - last_page * PAGE_SIZE; + } +} + #endif /* __LINUX_BVEC_ITER_H */ From patchwork Wed Nov 21 03:23:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691673 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 138AE1923 for ; Wed, 21 Nov 2018 03:26:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 010F82B409 for ; Wed, 21 Nov 2018 03:26:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E88682B412; Wed, 21 Nov 2018 03:26:38 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CCA82B409 for ; Wed, 21 Nov 2018 03:26:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD3E96B239F; Tue, 20 Nov 2018 22:26:37 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B82766B23A1; Tue, 20 Nov 2018 22:26:37 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A23B56B23A2; Tue, 20 Nov 2018 22:26:37 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 735406B239F for ; Tue, 20 Nov 2018 22:26:37 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id n45so2207964qta.5 for ; Tue, 20 Nov 2018 19:26:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=c2SF5KIPKkkjYa6soG59vjMHK08LElFkLaPhpIbMqOY=; b=Q99DoT8NDX5eh0MlpgWmjRbw26EmiNwYquLTdri+dWl9CKJ7viwamXfI0rrnkA6d4s OuAxayCwjnj+7QtE4+rsSgSxPc2KDtzjrHhBdxyllYhs/5Kr29Fve2aj6RpAHHWGOviN LVzfvqCyJ7vXBqSwzCQ6wRKfUBtZPU57y8/mIq/MMPFCbObF/g5KaSSJtkHntLL8sL/P spTLYx7R9KVQCRLQNYRWib2NRx1GGV9ar+Ub6+jcoi8qhsW4tkb9TXPwAh9e0M94cWvG 8PkLc85o+sZ5pn99zGJ6kkmIUyd8u0LNvAJR2AUPEmsEk1NawKgLjjqYB6ccbhjNvnoH QWUA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWa9s4HvikX+FIuKSO2V0xPQUBeq8WTc3gdTZ1yBirfSZwjd4n4W HKyqP0jrzkfVAF9BykLWBlLsATjaeE8QxcZov3eRoKqkr8z0L5TaL+VapyEEnxZ2sLgQWK205uY gU1F5nbE9FtiMHsU+29OvttjeyOxEkt2No105wazu9okDmuDY9JV9YCX7EmYUoHALKg== X-Received: by 2002:a37:492:: with SMTP id 140mr4036238qke.95.1542770797220; Tue, 20 Nov 2018 19:26:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/VzfBelotGg7BWoQXe3zDFk55O1tW2GnWu18AxDASCBlNXasLFJ+AusXbVyirl0dLDtfEQ2 X-Received: by 2002:a37:492:: with SMTP id 140mr4036218qke.95.1542770796493; Tue, 20 Nov 2018 19:26:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770796; cv=none; d=google.com; s=arc-20160816; b=ZAKX+VBRbwXko7wGCTZEWzvf7BTu7k2umSxqRIgoQN8bkR4aw4vDTlZR/+gnx6Jgqu 0gALopCrh9xXidhoY5DCH6HtxF1rU4y18FA7febtdMG0FxmH5LFAfEaVYFVEiRSckYNY ObOXlQXmuj18urJB1/jldjRGu6LoIXfCURPLhXtGlJKwhAvRyDGSJZKP0YVmNdnx80ae 4upD55+Q7FfgEzkVIY0ZTEL90UkRpkJdgwiiwi8s9uuaPZEr7H7THzYnwf1mEsrbSpgR 6X4KLfFnPl56ojr/qdlHodOI66otE15Z2JMXMXZwqi3F/mxtKeqLKo/bg/3nm+zz018s Jb3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=c2SF5KIPKkkjYa6soG59vjMHK08LElFkLaPhpIbMqOY=; b=QnygpCuEbtipknziLelrdEbQajQgt8WIfCTs8Yu3Re/iTUpEVE8PlWE6xPvVai2gnZ c5xTKI0Dr0Q468Rndobqttxp8MCUhpBaEUE/fCqRrEfIuiT6V5wZL1YSbfvWOzqZwjUH 5eEj6595l/NRevQaCv2QnvX6YvIIjcU3mS72v0nUBZDJ/kwBfIbj686V4y+Bc3dopKxX WNNduB5liC0W7ghs1pAGoq7IVCMcKu7EWpM15LSeFmDQ/9e/7AL18XdbnLSimDwS+gPS 0B+BR3RMraROaSo1DSuiGqVtIBl13Bo+nnhmVgPZBwcQdlqUxMSB0B9CM2YADoCDxPD4 A3wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id v184si5858200qkh.60.2018.11.20.19.26.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:26:36 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C75B7F6A8; Wed, 21 Nov 2018 03:26:35 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17CC25DD86; Wed, 21 Nov 2018 03:26:22 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 07/19] fs/buffer.c: use bvec iterator to truncate the bio Date: Wed, 21 Nov 2018 11:23:15 +0800 Message-Id: <20181121032327.8434-8-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 21 Nov 2018 03:26:35 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Once multi-page bvec is enabled, the last bvec may include more than one page, this patch use bvec_last_segment() to truncate the bio. Reviewed-by: Omar Sandoval Reviewed-by: Christoph Hellwig Signed-off-by: Ming Lei --- fs/buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/buffer.c b/fs/buffer.c index 1286c2b95498..fa37ad52e962 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -3032,7 +3032,10 @@ void guard_bio_eod(int op, struct bio *bio) /* ..and clear the end of the buffer for reads */ if (op == REQ_OP_READ) { - zero_user(bvec->bv_page, bvec->bv_offset + bvec->bv_len, + struct bio_vec bv; + + bvec_last_segment(bvec, &bv); + zero_user(bv.bv_page, bv.bv_offset + bv.bv_len, truncated_bytes); } } From patchwork Wed Nov 21 03:23:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1422E13BB for ; Wed, 21 Nov 2018 03:26:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 021B32B409 for ; Wed, 21 Nov 2018 03:26:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E99DA2B412; Wed, 21 Nov 2018 03:26: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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 940792B40C for ; Wed, 21 Nov 2018 03:26:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B600F6B23A1; Tue, 20 Nov 2018 22:26:47 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B0F606B23A3; Tue, 20 Nov 2018 22:26:47 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D8DA6B23A4; Tue, 20 Nov 2018 22:26:47 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 6BC566B23A1 for ; Tue, 20 Nov 2018 22:26:47 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id n95so2196201qte.16 for ; Tue, 20 Nov 2018 19:26:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=VqUMvNlEfNjUE6i3yi2LxyYeVZbGn1qv90D3YZNYJU4=; b=LW3KuOnjcUGORK4kdBuhiUtXEAWXW8Z10xw0c9mswPzQb0cZ2GBow8XPgqC1zYejTR AX32Ns/a2Iz9tb1GXn+Pl5W/kXt4RFYMR0bksa02zWe9Un3p5+F2swJ1M6MWKhzk8RC0 8qiNn1ewm/NVhwYaePLqqzXntNM92tV3aPwu94JjimTheE+f2T/ecjtQWg4fdLBfm9Yv bXQ2MuytNaaulmKMDaimMm/p4w39GwdT0OqElXl2MN07vr0p157oZm6e59tY0sma6gHO hwLjvSwQYydjYVgFLO5lnBdBV80rgfPiWPgqF8IS1lJ5ubbykIQW2oePSxExhmwEcymO 5Cjg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWYdKK8kZ7zOlKuW44wXdhZE1NIdIq2olgjAh8rHwqVsZX5H+WAR OSFMieUpaZ8mZRheSFae6qkC19W7oMAGhVeDzcec0CvXKyo/MMyBWSRwNoZUylR2rxZbuiI6xuh BzfpZuh9d88iopT03PUYC+86kQTJ+PHedp/r1iHMOExPddOopD66EQdBW00dwoba2aQ== X-Received: by 2002:a0c:e789:: with SMTP id x9mr4399427qvn.245.1542770807222; Tue, 20 Nov 2018 19:26:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/WFCMtDD0XzzS9Lbj52Lj+kWYKdSdzZKSMEBdUPtXTCDecA+0rQcfz3ZlzQCi7+vAvVJA4y X-Received: by 2002:a0c:e789:: with SMTP id x9mr4399410qvn.245.1542770806684; Tue, 20 Nov 2018 19:26:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770806; cv=none; d=google.com; s=arc-20160816; b=dNqYeRKTSyPRIpQgB7YC3i9sj8dobVmbDhn5leDxV075I4a6JBJBlT0WVl5SI+VIwH VKdubW66kMJ9WpSQrYXNyFXT+rrxsnATxnYDt/PWm/1XO7pS3hd9GJCGl87H1AF7jESP P+LN+LcYywBpa+DtBMbbAtbX3g0+YwaBVLlycACaE9yNQlN1RJ1gmW4UcV+zhKJHYEXD fSkBsIMoh9Wf46ughUQ/N502ESWxuuw0Ue33puA0zzx/xY0eTOyzOksB3s4B2U0av9Oz llqUnEz8hSKLou/GQNBAZCb/NKdzgIjDxYaZupeAVwROYwkNr11pxMz+ckAHWUtPtFX+ a6hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=VqUMvNlEfNjUE6i3yi2LxyYeVZbGn1qv90D3YZNYJU4=; b=U9njWTG5AqdHpZ+aEDsGOr2NdCkKqIr/mZ1MQy67LVkeQecZy93W39o9vgojcpWSq6 Nf45+bQmZtukupyrvWCJf29/VG3FiVrUqy30Aa6xKmF/5QtlfwykJ3dNFzM73BGCV0Dn IjVZM/08blGR/qpw1610pw5C8Mk5ZBJ5covbuHsJ5Niuae4XCsjD++zirxsS/vKVWOvm F4FGE3oeQybD3Ux7hfdwPDOS1/tsUemTIpRikvpYJJKqDCJr0xdKA9Rr3UWuW2RwpLEk 8Xrnrg5rtiEh38kcewgCK9KsV9Fm+ZJs2jgqa9s8qUF5Qh5ae//Cr7nzrCj5duHyNkrg T8kg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 26si5736971qvl.219.2018.11.20.19.26.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:26:46 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94672C058CA6; Wed, 21 Nov 2018 03:26:45 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 924975C226; Wed, 21 Nov 2018 03:26:37 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 08/19] btrfs: use bvec_last_segment to get bio's last page Date: Wed, 21 Nov 2018 11:23:16 +0800 Message-Id: <20181121032327.8434-9-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 21 Nov 2018 03:26:45 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Preparing for supporting multi-page bvec. Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- fs/btrfs/extent_io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index d228f706ff3e..5d5965297e7e 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2720,11 +2720,12 @@ static int __must_check submit_one_bio(struct bio *bio, int mirror_num, { blk_status_t ret = 0; struct bio_vec *bvec = bio_last_bvec_all(bio); - struct page *page = bvec->bv_page; + struct bio_vec bv; struct extent_io_tree *tree = bio->bi_private; u64 start; - start = page_offset(page) + bvec->bv_offset; + bvec_last_segment(bvec, &bv); + start = page_offset(bv.bv_page) + bv.bv_offset; bio->bi_private = NULL; From patchwork Wed Nov 21 03:23:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1808B13BB for ; Wed, 21 Nov 2018 03:27:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFBB92B412 for ; Wed, 21 Nov 2018 03:27:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E030C2B409; Wed, 21 Nov 2018 03:27:02 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76EE92B409 for ; Wed, 21 Nov 2018 03:27:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D8736B23A3; Tue, 20 Nov 2018 22:27:01 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 987FF6B23A5; Tue, 20 Nov 2018 22:27:01 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8768D6B23A6; Tue, 20 Nov 2018 22:27:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 51F216B23A3 for ; Tue, 20 Nov 2018 22:27:01 -0500 (EST) Received: by mail-qt1-f199.google.com with SMTP id n50so2206895qtb.9 for ; Tue, 20 Nov 2018 19:27:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=tEMVf7aaXzhIFZ7juhc3JwrvQlu0r1fvaDx0TitR7hU=; b=tbgSnfJjCFmycBOYd1hVF8H0SHFi4oNuwCovTH+YlKhxX57MMSAcSLWsPmd9XDgJoc WImTdyQTZQVQmOWsu4d0gBR9CYZ+jyK1q57MBHGCfQ1iBAefV7lBps1MKAczwuBoIC8E m5eqaaMIW4ADHfX9V4tj8Fr1jVxnVJt4MfQE5yggDDtbUV9jCgrxLiNmZYQ4YpVR+684 gJ6AN67JwHEC6tZhE/fM6urwGnH2MMc8hdnnOzO3fqWDGNtHqJ/vyBFjxO4Yl4+DNIda ZN8rWsCvs8sYyN0j6a5pORMYEwfyi5hU7jSEpVcJYWu/dzUwVOg+0NDSdjObHQVNp0b2 xLDQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gK58GiLtyl1WOH3ugrGtgjlTvNqxzDrkFDDI++uZi6zoNbqvfWp iJwM+a32DzjV6P3HqUAC0PfogbBAkxJPB8XHD86PXvDtOBoWOiq7XW7QDfGxvkkDAzZrkUGGT0v aO05WwV207ynNxYfUzwsWehX2JOiUOwdnFYThha8W+h0xATK8Yhw+vdEkGxkdoBfPVw== X-Received: by 2002:ac8:3790:: with SMTP id d16mr4424016qtc.20.1542770821066; Tue, 20 Nov 2018 19:27:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ur9aNdchmVasR/mQ29pLW7eLDQ4xHxAhEg+CT+l05pKIqGurJdB2fgsVn+zd+WPLWoZbGA X-Received: by 2002:ac8:3790:: with SMTP id d16mr4423996qtc.20.1542770820503; Tue, 20 Nov 2018 19:27:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770820; cv=none; d=google.com; s=arc-20160816; b=WpwdNVbHDnQfsHvwdGDFyfAnXxDes1X1Nx2t0wGZr4GasJ6TPD2+Xxlcm9Fpkc7rD+ o1cqGlPZA0L3REsZkkg93VdeLGh9Ak7ceKXxhxJ6N3sLOr/pe+LmMi8TCTmmRvvYMn9K mrgqt6SNzqK0ah4QRlf8uRE2LifmH5+tMBVLcmjAYbFSlC+j9PY1osT+sDngO0jM1ejN uTh0rHonr9bHoySW0lrnCsnqeWOuYL7UIQrOksPQxbtj3cE5n3cfKZILpvLY/WAGOSC5 Z0jWKGRyHZ9EQEAURY6a6clGYhZExQGrX9na8T33LLA0TxtcsJ/q4ECDZflYc7f6TZpq AW3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=tEMVf7aaXzhIFZ7juhc3JwrvQlu0r1fvaDx0TitR7hU=; b=B8V2XjTUVh5aFOHLi2i1AJOP6QsWuFXW60nT3jd8r0LbbkqqoUL7avpryucln09dIg N/ZOCnGo/ueYPqipdiaxGM90GS/pcM2ZSytJp3BL1PTF0jPA/FaFgzmo+hJkTijiQzod tn4mLoh1JvQYiCaXELo1aSZVgLNAv/sT2qqA0phkkyZg1+o/98LQ1XRjr8wEGeL4EIxI wUGEGls3GWwfYTdkGbPdRn2NfupeXTVdNU8xFcPSoN9Rkf550jp49SVzslLlC8JDSC9b 4DDWksWalgIaEHu9Kv1oXFZzPFOeHWLnKWh8vG7HyZS4HrfweXsbcNPaqF/lU+AL7huD fDug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id f3si16236373qkf.49.2018.11.20.19.27.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:27:00 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E2DAC057E26; Wed, 21 Nov 2018 03:26:59 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7C4D6012B; Wed, 21 Nov 2018 03:26:47 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 09/19] btrfs: move bio_pages_all() to btrfs Date: Wed, 21 Nov 2018 11:23:17 +0800 Message-Id: <20181121032327.8434-10-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 21 Nov 2018 03:26:59 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP BTRFS is the only user of this helper, so move this helper into BTRFS, and implement it via bio_for_each_segment_all(), since bio->bi_vcnt may not equal to number of pages after multipage bvec is enabled. Signed-off-by: Ming Lei --- fs/btrfs/extent_io.c | 14 +++++++++++++- include/linux/bio.h | 6 ------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 5d5965297e7e..874bb9aeebdc 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2348,6 +2348,18 @@ struct bio *btrfs_create_repair_bio(struct inode *inode, struct bio *failed_bio, return bio; } +static unsigned btrfs_bio_pages_all(struct bio *bio) +{ + unsigned i; + struct bio_vec *bv; + + WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)); + + bio_for_each_segment_all(bv, bio, i) + ; + return i; +} + /* * this is a generic handler for readpage errors (default * readpage_io_failed_hook). if other copies exist, read those and write back @@ -2368,7 +2380,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset, int read_mode = 0; blk_status_t status; int ret; - unsigned failed_bio_pages = bio_pages_all(failed_bio); + unsigned failed_bio_pages = btrfs_bio_pages_all(failed_bio); BUG_ON(bio_op(failed_bio) == REQ_OP_WRITE); diff --git a/include/linux/bio.h b/include/linux/bio.h index 7560209d6a8a..9d6284f53c07 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -282,12 +282,6 @@ static inline void bio_get_last_bvec(struct bio *bio, struct bio_vec *bv) bv->bv_len = iter.bi_bvec_done; } -static inline unsigned bio_pages_all(struct bio *bio) -{ - WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)); - return bio->bi_vcnt; -} - static inline struct bio_vec *bio_first_bvec_all(struct bio *bio) { WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)); From patchwork Wed Nov 21 03:23:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6666216B1 for ; Wed, 21 Nov 2018 03:27:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50A2F2B40C for ; Wed, 21 Nov 2018 03:27:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 417332B413; Wed, 21 Nov 2018 03:27:20 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C41122B415 for ; Wed, 21 Nov 2018 03:27:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE2516B23A7; Tue, 20 Nov 2018 22:27:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E917B6B23A8; Tue, 20 Nov 2018 22:27:18 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D81946B23A9; Tue, 20 Nov 2018 22:27:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id A94F46B23A7 for ; Tue, 20 Nov 2018 22:27:18 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id y83so5410722qka.7 for ; Tue, 20 Nov 2018 19:27:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=TSBLWrtYdTLJ/i/PjrMa6QoZNwXwGBQxVHczPRHzxZo=; b=HNh1xdhvQM0lPtdB86LOWo/Hkp65SHpQ99G7nl3QeXKiqugoF/33DyEztk/WgUDQ31 ex89r8Kh1MdJ6oSxjwmA3/ySegSAU1eth1b0aKgz98836VywAdUNyAmR8WJldK9of4eO c8J3Vj6J2cZ7beRvhoX2hMlKXhWisLHQTurZRnyqWzxhU2EdanmhlPI9wj2j9jhvhVwB U6ndcNWHzcN4w6mnwbpJcRTNDjwBDK3d2mJD9B/AgF4nRwEMWFdYlr5NwoiEyBw/aNuS C1WhsgObzQwKE7xOy9hUu6pLT7E/AY8VmHzujaT2/J/xtmDL80b4bx03x3njqtbcagPC WdPA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWZGUVGndWP0QNfqQfAYT0dV+3WroJ4SUAsB97Ch/Z7hebC/oWau uHAHdl3l43YPMXI+2PVRDtoX7348z/2XLPobDiqZd6c6AnrqcOPN/f4a0MhXALiZPByOzd/LQrm e0FJNiWv0neqKI+TjES4UL4xYrq/Y/URoBVHLLMUQcMi9pSa13IjgBZWHXzscyuCWaA== X-Received: by 2002:ae9:edd8:: with SMTP id c207mr3924879qkg.184.1542770838447; Tue, 20 Nov 2018 19:27:18 -0800 (PST) X-Google-Smtp-Source: AFSGD/XTb0Z1Wij/ybRJqgIsrDHu+bSpPLlHDUZiAkZ7tkpZGz7twgTJInmQSpDIgBMXq3JlvO13 X-Received: by 2002:ae9:edd8:: with SMTP id c207mr3924856qkg.184.1542770837798; Tue, 20 Nov 2018 19:27:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770837; cv=none; d=google.com; s=arc-20160816; b=kpTfFjyS1MVVHT3ClzpY7fh2Yxuvmoiuz/EWBoo5sxbnrdqIABHkCrPKN5BToL4iPS hbYHNeX7T+YGtJEGHq75T1K1DnfcYyKko16jO5/C4cWzPN9vMpFktt4RBrB7b65eqNSB ygltvjp7pd9hOG9wZ0zGnhiNKouFivP++cYVfawJSj4lhaT23VywV8LZ1Zc85raS3sCo OJ+xQOSXV/4aTHTgQ65PKB3JMnDnAMA0A2nU/a/u0W9fs0icNei8MJ9f5wujIdVPeyNg hAOCtGk7KLD7oN6QcJ6RGi8fiFxQY5BvrBlyWQqI2zcwmAJn0RciuU6/uxotEbRTJx5/ pd7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=TSBLWrtYdTLJ/i/PjrMa6QoZNwXwGBQxVHczPRHzxZo=; b=F5NMpUwsorG2xb4MBwItYO5xOgAkOD0xhnKwBzjcJM+PZhjm+Ea1I+6NT709rQBHDl LICC0ZZOyUdbttDq8Plzc3h2dsfciuXxu0S7yHJDz/GhDKhPXGFnGQBiQ15k3zTl4Eqv 8GGexCnQhYFq1LnkI622zqn/1y932hO4RNp0PP2vALRe1qeJTfKH3yX0imYHHKeWmNIX tXnPqGK1KuLQTekgVbcjnX0rFN1lG1+A8TJcH1cs+qp1vCWppUzoGr4WwYP9UnRb49LI PhlVlC1SeqIHXYyHv/7vREdnBnQWKaRf+rGI7g9mx5w3uyQPpKISA4pgphZyXSfK7dSe Fwyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id p190si2376772qke.19.2018.11.20.19.27.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:27:17 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CB3E30B2537; Wed, 21 Nov 2018 03:27:16 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 991F47D2F2; Wed, 21 Nov 2018 03:27:01 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 10/19] block: loop: pass multi-page bvec to iov_iter Date: Wed, 21 Nov 2018 11:23:18 +0800 Message-Id: <20181121032327.8434-11-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 21 Nov 2018 03:27:16 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP iov_iter is implemented on bvec itererator helpers, so it is safe to pass multi-page bvec to it, and this way is much more efficient than passing one page in each bvec. Signed-off-by: Ming Lei Reviewed-by: Christoph Hellwig --- drivers/block/loop.c | 20 ++++++++++---------- include/linux/blkdev.h | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 176ab1f28eca..e3683211f12d 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -510,21 +510,22 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, loff_t pos, bool rw) { struct iov_iter iter; + struct req_iterator rq_iter; struct bio_vec *bvec; struct request *rq = blk_mq_rq_from_pdu(cmd); struct bio *bio = rq->bio; struct file *file = lo->lo_backing_file; + struct bio_vec tmp; unsigned int offset; - int segments = 0; + int nr_bvec = 0; int ret; + rq_for_each_bvec(tmp, rq, rq_iter) + nr_bvec++; + if (rq->bio != rq->biotail) { - struct req_iterator iter; - struct bio_vec tmp; - __rq_for_each_bio(bio, rq) - segments += bio_segments(bio); - bvec = kmalloc_array(segments, sizeof(struct bio_vec), + bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), GFP_NOIO); if (!bvec) return -EIO; @@ -533,10 +534,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, /* * The bios of the request may be started from the middle of * the 'bvec' because of bio splitting, so we can't directly - * copy bio->bi_iov_vec to new bvec. The rq_for_each_segment + * copy bio->bi_iov_vec to new bvec. The rq_for_each_bvec * API will take care of all details for us. */ - rq_for_each_segment(tmp, rq, iter) { + rq_for_each_bvec(tmp, rq, rq_iter) { *bvec = tmp; bvec++; } @@ -550,11 +551,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, */ offset = bio->bi_iter.bi_bvec_done; bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); - segments = bio_segments(bio); } atomic_set(&cmd->ref, 2); - iov_iter_bvec(&iter, rw, bvec, segments, blk_rq_bytes(rq)); + iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq)); iter.iov_offset = offset; cmd->iocb.ki_pos = pos; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 1ad6eafc43f2..a281b6737b61 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -805,6 +805,10 @@ struct req_iterator { __rq_for_each_bio(_iter.bio, _rq) \ bio_for_each_segment(bvl, _iter.bio, _iter.iter) +#define rq_for_each_bvec(bvl, _rq, _iter) \ + __rq_for_each_bio(_iter.bio, _rq) \ + bio_for_each_bvec(bvl, _iter.bio, _iter.iter) + #define rq_iter_last(bvec, _iter) \ (_iter.bio->bi_next == NULL && \ bio_iter_last(bvec, _iter.iter)) From patchwork Wed Nov 21 03:23:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0CF713BB for ; Wed, 21 Nov 2018 03:27:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC1B32B40C for ; Wed, 21 Nov 2018 03:27:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF3312B412; Wed, 21 Nov 2018 03:27:34 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 687E12B415 for ; Wed, 21 Nov 2018 03:27:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 962916B23A8; Tue, 20 Nov 2018 22:27:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 913116B23AA; Tue, 20 Nov 2018 22:27:33 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 803D66B23AB; Tue, 20 Nov 2018 22:27:33 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 4F3BE6B23A8 for ; Tue, 20 Nov 2018 22:27:33 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id m37so2188054qte.10 for ; Tue, 20 Nov 2018 19:27:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=IlLTWLk28CoX+iGvEA9mJmelkxne3MUdqKGOcV+1Va4=; b=kqkTKKUpw9oFqVGwUzCrIVxR6yzPlFj1c41+LIBHfInHwQj0nkJVtVRsakNNw6dyje oW34kQiM+mpt/c0Su8IOpU9Vp3D7UOqf8hOkESG3TzftDEv62lRjMA4SyJNIV5umK0IG SfNhtyMYsoSIgGx5PS3YjfuhH0LXZ3kJJEpamq8skjdHwSZATLcgcFKFIbnZxB3XeBfn GxBZ5xzfAlk3ePvLqKlFlZGV/Wd4Oa4ZSnX7kJd0nbq1B7szUJ866fph6LCGrdHjRrWz iIkn03LE+o+N1Y7titAi3lAemWOrno8+ukfFFAHkBKYhwW0hCSmdBpzIbFI81jCb1Ftf GlPA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWYdTzcxmCapAf3Bs36jf0JbX9XpoHSZOv7UJxX73rSOtJnHTBuy 5/8Elg3I3RKAC8fnUiP6mpFjbftPur8a0ZWlNQuttwlEm+8utRGs8lex8emG/QHI3QS1awpmhad 1TRWiLXGLS3wMusMF8wwVW/zFhFkFVzjPz6JoERXsQPVH2RIye1/CHOrfMyxiPbWs1g== X-Received: by 2002:a05:6214:110e:: with SMTP id e14mr4449092qvs.10.1542770853106; Tue, 20 Nov 2018 19:27:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/VXEDwy/dxNModoxIVmRAM25cEq4p26uanfjHVh/DgNpGwoMG5CgASoJzKAq+JfFHmAs70q X-Received: by 2002:a05:6214:110e:: with SMTP id e14mr4449076qvs.10.1542770852556; Tue, 20 Nov 2018 19:27:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770852; cv=none; d=google.com; s=arc-20160816; b=aqMC6HHwi2KCSwWWJ2WeyCKldRGZel5bzvrEz1+WT20zO3U5N8UQfX+DDW29WwtBXX m3SAYU8JANXXExoDzAN+B7PYKhky97IuVrGti6l21sjJwEkJ8o1Es5M7tTe+/GpmQAKq gBZrLhVeA7qFgZep9BVMHO0MV3yqGGV/SQCdxxV4815ZxcUIOsWpVNhHblSBwIsTkaJc A8yXmumruCUVaNAUAktyA/CzDnLf/74bdGvZ7fJY4PZhamgpcaiNQTzqC9YGjfBAQFUe Ep5jlqfvfXX079wQsQZftp1RFmCeuwvokwiYEuFA71DzaUTgURglbsfluvErl1HjcwIa 1xXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=IlLTWLk28CoX+iGvEA9mJmelkxne3MUdqKGOcV+1Va4=; b=Qx6dofAg10f5jB9chGepngBHtCzXDEucJlj/nozvLJ/ncKObMyE4/4Zn9uaU3+9AiH +Csdctu8hvCPrlwoHs7wQJhkVltzbsDxhAiGX+SyEeHr8BZ4LJa5Z9QpHYGskEA64Pwi CDeAET2W3Ac3uGoxmZx1PSAp8QW3DWGyg1flvg2IYL2RD81ZeGIGgWNTHzAdc+ZjwOia d8ZaHN10y/bBT9e9l/GOaXfPPxX/lG8p6YBzJ1p/zIzoRqqPI548qbOiVNbubpNI95Gd G0AQ+k0VGsxKD9GmsqgiOteFQirha4Fr5VNcUZSwnePmi78ABekFVavIwCq/rms7vipr SLUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id o14si9123169qtb.200.2018.11.20.19.27.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:27:32 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71CCD637FC; Wed, 21 Nov 2018 03:27:31 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAA9D60BF6; Wed, 21 Nov 2018 03:27:18 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 11/19] bcache: avoid to use bio_for_each_segment_all() in bch_bio_alloc_pages() Date: Wed, 21 Nov 2018 11:23:19 +0800 Message-Id: <20181121032327.8434-12-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 21 Nov 2018 03:27:31 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP bch_bio_alloc_pages() is always called on one new bio, so it is safe to access the bvec table directly. Given it is the only kind of this case, open code the bvec table access since bio_for_each_segment_all() will be changed to support for iterating over multipage bvec. Acked-by: Coly Li Signed-off-by: Ming Lei Reviewed-by: Christoph Hellwig --- drivers/md/bcache/util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c index 20eddeac1531..62fb917f7a4f 100644 --- a/drivers/md/bcache/util.c +++ b/drivers/md/bcache/util.c @@ -270,7 +270,11 @@ int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask) int i; struct bio_vec *bv; - bio_for_each_segment_all(bv, bio, i) { + /* + * This is called on freshly new bio, so it is safe to access the + * bvec table directly. + */ + for (i = 0, bv = bio->bi_io_vec; i < bio->bi_vcnt; bv++, i++) { bv->bv_page = alloc_page(gfp_mask); if (!bv->bv_page) { while (--bv >= bio->bi_io_vec) From patchwork Wed Nov 21 03:23:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5E8616B1 for ; Wed, 21 Nov 2018 03:27:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D10742B40C for ; Wed, 21 Nov 2018 03:27:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4C112B413; Wed, 21 Nov 2018 03:27:51 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F5DD2B40C for ; Wed, 21 Nov 2018 03:27:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A36A6B23AA; Tue, 20 Nov 2018 22:27:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6544F6B23AC; Tue, 20 Nov 2018 22:27:49 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F5196B23AD; Tue, 20 Nov 2018 22:27:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 1ED0D6B23AA for ; Tue, 20 Nov 2018 22:27:49 -0500 (EST) Received: by mail-qk1-f198.google.com with SMTP id z126so5452733qka.10 for ; Tue, 20 Nov 2018 19:27:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=XDNIYuEIUPhLYboa4c28j6/GxlcC2gGSH2S8F5s7UYs=; b=NAVw+fQCvqxGZHQ/x7fxpiBhfi+d1n3Bwmx8d+NUTwsFDGjL1B6mWhnW97nqgDv7t3 SEZQiu8n9YJd/kVvI+jE3Q4PPXuWeGFWeXEiQkwJ2+bKIurGNVh/dXNVs5yEePwGOeH+ 0kxrhSn00mcnRQqmQx6Eh4SwPy5VIl95VBC96/4hdXM1ZcHJzWiwMgKoiNY+uxZQyHQ2 Su5BtkOWa49c8l2s6CmP3BFwhQNW2TcFz7rX+OziGbiS1MOsnQ2kMCzr54RMVJ1vUmE0 OVsAacsN9sSj4izAS+j6c8rJID0iz3CIV4L5F4XxlEJG98ZlcByDa1xZtLT8Yi+2Jqp2 erqg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWb1Xe+kMGqDQYFEtc/tGL8K5sFbeA+6d03J3yMH//WQ8/Zq+pIZ tlbdjR2iaB511Ayunfkvka7SQSdF73uu0P2rUVvAMkw7AG+dJBktttf+nAfUJqKJZ1R6y31BI7G ICbB/RC2g62S8RCJrXp2G2b2hwR/H+5VACSSbhJ4DnC+o4MnLoz5kTO8Q24JCIfRq9g== X-Received: by 2002:a0c:d40f:: with SMTP id t15mr4429754qvh.117.1542770868817; Tue, 20 Nov 2018 19:27:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/WlbRoxA63yv+TOeO7+TEnwn+QIFUwQSTSWYvuuLBHtXe3K9CLJL1GtnbiAiskZ2+ehuOHy X-Received: by 2002:a0c:d40f:: with SMTP id t15mr4429699qvh.117.1542770867043; Tue, 20 Nov 2018 19:27:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770867; cv=none; d=google.com; s=arc-20160816; b=E2FOChl4EYDAHCwGBqSOfbAfovDQBCc1ivJD2HT1hklwcrEMtuar2ioJOb+RaQifT8 klZ3g14YMqDXZL55VVUCrP41HGIg+JepI8vn3l+cFotyeJiG7DG2eewyoDNn033kxwh9 Qe1fUX9Y3IgTA/mh+ydD9cGsYQAXsr7gorZi5AETcD94EOf+8xi5GJMU/gWKQ2wdHlAk rR81OXCYrSLeC1Irl9cyZw0AwDfUGliTcb73jc3IVnqTGXL8Rx/s1zY1twJsrGuLBTEp bvXaIYaoS7JGpvYFAnRZOR1hZux65zReF9B9IKbqM0dkC3stmeUkFnnPfPK+Obtwc198 Za/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=XDNIYuEIUPhLYboa4c28j6/GxlcC2gGSH2S8F5s7UYs=; b=TbFqnOCl94CrNJvMAsmz59ybjFgfbYpzaUwy7/kWTDq+J6jYg+sXnPrKRPWLIfv5AP tCFzmcutvU+OGp3MkshG8z34n77LRHAbgtrwypno3rnm3gICfIQrijolUKexB/XzXoGs Ly4mE23RNTz1LDHWJNHjesjycVTkWukLqcAwl/Ezfw4UJcnQJVSW1pFHWG/NI5z9jEJs w+dOeL+DMcsF/HlW95oJ2qfZu5yACsIf9GC8xT9yIvwAxUynoO2ZV8PjQ0RZYh0Idz43 J75KWCpKoNTtCbm6xG72pSC2RVDz8rHdfpFrwh/sperASpLcLlu5ThoBSe4/Qslcvty+ nUaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id f46si866288qta.336.2018.11.20.19.27.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:27:46 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D103E3084243; Wed, 21 Nov 2018 03:27:45 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D3B610021B6; Wed, 21 Nov 2018 03:27:33 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 12/19] block: allow bio_for_each_segment_all() to iterate over multi-page bvec Date: Wed, 21 Nov 2018 11:23:20 +0800 Message-Id: <20181121032327.8434-13-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 21 Nov 2018 03:27:46 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces one extra iterator variable to bio_for_each_segment_all(), then we can allow bio_for_each_segment_all() to iterate over multi-page bvec. Given it is just one mechannical & simple change on all bio_for_each_segment_all() users, this patch does tree-wide change in one single patch, so that we can avoid to use a temporary helper for this conversion. Signed-off-by: Ming Lei Reviewed-by: Christoph Hellwig --- block/bio.c | 27 ++++++++++++++++++--------- block/bounce.c | 6 ++++-- drivers/md/bcache/btree.c | 3 ++- drivers/md/dm-crypt.c | 3 ++- drivers/md/raid1.c | 3 ++- drivers/staging/erofs/data.c | 3 ++- drivers/staging/erofs/unzip_vle.c | 3 ++- fs/block_dev.c | 6 ++++-- fs/btrfs/compression.c | 3 ++- fs/btrfs/disk-io.c | 3 ++- fs/btrfs/extent_io.c | 12 ++++++++---- fs/btrfs/inode.c | 6 ++++-- fs/btrfs/raid56.c | 3 ++- fs/crypto/bio.c | 3 ++- fs/direct-io.c | 4 +++- fs/exofs/ore.c | 3 ++- fs/exofs/ore_raid.c | 3 ++- fs/ext4/page-io.c | 3 ++- fs/ext4/readpage.c | 3 ++- fs/f2fs/data.c | 9 ++++++--- fs/gfs2/lops.c | 6 ++++-- fs/gfs2/meta_io.c | 3 ++- fs/iomap.c | 6 ++++-- fs/mpage.c | 3 ++- fs/xfs/xfs_aops.c | 5 +++-- include/linux/bio.h | 11 +++++++++-- include/linux/bvec.h | 31 +++++++++++++++++++++++++++++++ 27 files changed, 128 insertions(+), 46 deletions(-) diff --git a/block/bio.c b/block/bio.c index 4f4d9884443b..2680aa42a625 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1073,8 +1073,9 @@ static int bio_copy_from_iter(struct bio *bio, struct iov_iter *iter) { int i; struct bio_vec *bvec; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { ssize_t ret; ret = copy_page_from_iter(bvec->bv_page, @@ -1104,8 +1105,9 @@ static int bio_copy_to_iter(struct bio *bio, struct iov_iter iter) { int i; struct bio_vec *bvec; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { ssize_t ret; ret = copy_page_to_iter(bvec->bv_page, @@ -1127,8 +1129,9 @@ void bio_free_pages(struct bio *bio) { struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) + bio_for_each_segment_all(bvec, bio, i, iter_all) __free_page(bvec->bv_page); } EXPORT_SYMBOL(bio_free_pages); @@ -1295,6 +1298,7 @@ struct bio *bio_map_user_iov(struct request_queue *q, struct bio *bio; int ret; struct bio_vec *bvec; + struct bvec_iter_all iter_all; if (!iov_iter_count(iter)) return ERR_PTR(-EINVAL); @@ -1368,7 +1372,7 @@ struct bio *bio_map_user_iov(struct request_queue *q, return bio; out_unmap: - bio_for_each_segment_all(bvec, bio, j) { + bio_for_each_segment_all(bvec, bio, j, iter_all) { put_page(bvec->bv_page); } bio_put(bio); @@ -1379,11 +1383,12 @@ static void __bio_unmap_user(struct bio *bio) { struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; /* * make sure we dirty pages we wrote to */ - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { if (bio_data_dir(bio) == READ) set_page_dirty_lock(bvec->bv_page); @@ -1475,8 +1480,9 @@ static void bio_copy_kern_endio_read(struct bio *bio) char *p = bio->bi_private; struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { memcpy(p, page_address(bvec->bv_page), bvec->bv_len); p += bvec->bv_len; } @@ -1585,8 +1591,9 @@ void bio_set_pages_dirty(struct bio *bio) { struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { if (!PageCompound(bvec->bv_page)) set_page_dirty_lock(bvec->bv_page); } @@ -1597,8 +1604,9 @@ static void bio_release_pages(struct bio *bio) { struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) + bio_for_each_segment_all(bvec, bio, i, iter_all) put_page(bvec->bv_page); } @@ -1645,8 +1653,9 @@ void bio_check_pages_dirty(struct bio *bio) struct bio_vec *bvec; unsigned long flags; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { if (!PageDirty(bvec->bv_page) && !PageCompound(bvec->bv_page)) goto defer; } diff --git a/block/bounce.c b/block/bounce.c index 559c55bda040..7338041e3042 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -165,11 +165,12 @@ static void bounce_end_io(struct bio *bio, mempool_t *pool) struct bio_vec *bvec, orig_vec; int i; struct bvec_iter orig_iter = bio_orig->bi_iter; + struct bvec_iter_all iter_all; /* * free up bounce indirect pages used */ - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { orig_vec = bio_iter_iovec(bio_orig, orig_iter); if (bvec->bv_page != orig_vec.bv_page) { dec_zone_page_state(bvec->bv_page, NR_BOUNCE); @@ -293,6 +294,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, bool bounce = false; int sectors = 0; bool passthrough = bio_is_passthrough(*bio_orig); + struct bvec_iter_all iter_all; bio_for_each_segment(from, *bio_orig, iter) { if (i++ < BIO_MAX_PAGES) @@ -312,7 +314,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, bio = bounce_clone_bio(*bio_orig, GFP_NOIO, passthrough ? NULL : &bounce_bio_set); - bio_for_each_segment_all(to, bio, i) { + bio_for_each_segment_all(to, bio, i, iter_all) { struct page *page = to->bv_page; if (page_to_pfn(page) <= q->limits.bounce_pfn) diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 3f4211b5cd33..6242ae4e2127 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -427,8 +427,9 @@ static void do_btree_node_write(struct btree *b) int j; struct bio_vec *bv; void *base = (void *) ((unsigned long) i & ~(PAGE_SIZE - 1)); + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bv, b->bio, j) + bio_for_each_segment_all(bv, b->bio, j, iter_all) memcpy(page_address(bv->bv_page), base + j * PAGE_SIZE, PAGE_SIZE); diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index b8eec515a003..a0dcf28c01b5 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -1447,8 +1447,9 @@ static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone) { unsigned int i; struct bio_vec *bv; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bv, clone, i) { + bio_for_each_segment_all(bv, clone, i, iter_all) { BUG_ON(!bv->bv_page); mempool_free(bv->bv_page, &cc->page_pool); } diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 1d54109071cc..6f74a3b06c7e 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -2114,13 +2114,14 @@ static void process_checks(struct r1bio *r1_bio) struct page **spages = get_resync_pages(sbio)->pages; struct bio_vec *bi; int page_len[RESYNC_PAGES] = { 0 }; + struct bvec_iter_all iter_all; if (sbio->bi_end_io != end_sync_read) continue; /* Now we can 'fixup' the error value */ sbio->bi_status = 0; - bio_for_each_segment_all(bi, sbio, j) + bio_for_each_segment_all(bi, sbio, j, iter_all) page_len[j] = bi->bv_len; if (!status) { diff --git a/drivers/staging/erofs/data.c b/drivers/staging/erofs/data.c index 6384f73e5418..96240ceca02a 100644 --- a/drivers/staging/erofs/data.c +++ b/drivers/staging/erofs/data.c @@ -20,8 +20,9 @@ static inline void read_endio(struct bio *bio) int i; struct bio_vec *bvec; const blk_status_t err = bio->bi_status; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { struct page *page = bvec->bv_page; /* page is already locked */ diff --git a/drivers/staging/erofs/unzip_vle.c b/drivers/staging/erofs/unzip_vle.c index 79d3ba62b298..41a8a9399863 100644 --- a/drivers/staging/erofs/unzip_vle.c +++ b/drivers/staging/erofs/unzip_vle.c @@ -731,11 +731,12 @@ static inline void z_erofs_vle_read_endio(struct bio *bio) const blk_status_t err = bio->bi_status; unsigned int i; struct bio_vec *bvec; + struct bvec_iter_all iter_all; #ifdef EROFS_FS_HAS_MANAGED_CACHE struct address_space *mngda = NULL; #endif - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { struct page *page = bvec->bv_page; bool cachemngd = false; diff --git a/fs/block_dev.c b/fs/block_dev.c index 4d79bc80fb41..6f505982e6b1 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -197,6 +197,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, ssize_t ret; blk_qc_t qc; int i; + struct bvec_iter_all iter_all; if ((pos | iov_iter_alignment(iter)) & (bdev_logical_block_size(bdev) - 1)) @@ -246,7 +247,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, } __set_current_state(TASK_RUNNING); - bio_for_each_segment_all(bvec, &bio, i) { + bio_for_each_segment_all(bvec, &bio, i, iter_all) { if (should_dirty && !PageCompound(bvec->bv_page)) set_page_dirty_lock(bvec->bv_page); put_page(bvec->bv_page); @@ -314,8 +315,9 @@ static void blkdev_bio_end_io(struct bio *bio) } else { struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) + bio_for_each_segment_all(bvec, bio, i, iter_all) put_page(bvec->bv_page); bio_put(bio); } diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 2955a4ea2fa8..602a74c645c3 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -162,13 +162,14 @@ static void end_compressed_bio_read(struct bio *bio) } else { int i; struct bio_vec *bvec; + struct bvec_iter_all iter_all; /* * we have verified the checksum already, set page * checked so the end_io handlers know about it */ ASSERT(!bio_flagged(bio, BIO_CLONED)); - bio_for_each_segment_all(bvec, cb->orig_bio, i) + bio_for_each_segment_all(bvec, cb->orig_bio, i, iter_all) SetPageChecked(bvec->bv_page); bio_endio(cb->orig_bio); diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 3f0b6d1936e8..9f2a31bea08d 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -819,9 +819,10 @@ static blk_status_t btree_csum_one_bio(struct bio *bio) struct bio_vec *bvec; struct btrfs_root *root; int i, ret = 0; + struct bvec_iter_all iter_all; ASSERT(!bio_flagged(bio, BIO_CLONED)); - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { root = BTRFS_I(bvec->bv_page->mapping->host)->root; ret = csum_dirty_buffer(root->fs_info, bvec->bv_page); if (ret) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 874bb9aeebdc..9373eb8ade06 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2352,10 +2352,11 @@ static unsigned btrfs_bio_pages_all(struct bio *bio) { unsigned i; struct bio_vec *bv; + struct bvec_iter_all iter_all; WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)); - bio_for_each_segment_all(bv, bio, i) + bio_for_each_segment_all(bv, bio, i, iter_all) ; return i; } @@ -2457,9 +2458,10 @@ static void end_bio_extent_writepage(struct bio *bio) u64 start; u64 end; int i; + struct bvec_iter_all iter_all; ASSERT(!bio_flagged(bio, BIO_CLONED)); - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { struct page *page = bvec->bv_page; struct inode *inode = page->mapping->host; struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); @@ -2528,9 +2530,10 @@ static void end_bio_extent_readpage(struct bio *bio) int mirror; int ret; int i; + struct bvec_iter_all iter_all; ASSERT(!bio_flagged(bio, BIO_CLONED)); - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { struct page *page = bvec->bv_page; struct inode *inode = page->mapping->host; struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); @@ -3682,9 +3685,10 @@ static void end_bio_extent_buffer_writepage(struct bio *bio) struct bio_vec *bvec; struct extent_buffer *eb; int i, done; + struct bvec_iter_all iter_all; ASSERT(!bio_flagged(bio, BIO_CLONED)); - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { struct page *page = bvec->bv_page; eb = (struct extent_buffer *)page->private; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9ea4c6f0352f..2850fca6cc44 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7822,6 +7822,7 @@ static void btrfs_retry_endio_nocsum(struct bio *bio) struct bio_vec *bvec; struct extent_io_tree *io_tree, *failure_tree; int i; + struct bvec_iter_all iter_all; if (bio->bi_status) goto end; @@ -7833,7 +7834,7 @@ static void btrfs_retry_endio_nocsum(struct bio *bio) done->uptodate = 1; ASSERT(!bio_flagged(bio, BIO_CLONED)); - bio_for_each_segment_all(bvec, bio, i) + bio_for_each_segment_all(bvec, bio, i, iter_all) clean_io_failure(BTRFS_I(inode)->root->fs_info, failure_tree, io_tree, done->start, bvec->bv_page, btrfs_ino(BTRFS_I(inode)), 0); @@ -7912,6 +7913,7 @@ static void btrfs_retry_endio(struct bio *bio) int uptodate; int ret; int i; + struct bvec_iter_all iter_all; if (bio->bi_status) goto end; @@ -7925,7 +7927,7 @@ static void btrfs_retry_endio(struct bio *bio) failure_tree = &BTRFS_I(inode)->io_failure_tree; ASSERT(!bio_flagged(bio, BIO_CLONED)); - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { ret = __readpage_endio_check(inode, io_bio, i, bvec->bv_page, bvec->bv_offset, done->start, bvec->bv_len); diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index df41d7049936..e33a99871d60 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -1443,10 +1443,11 @@ static void set_bio_pages_uptodate(struct bio *bio) { struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; ASSERT(!bio_flagged(bio, BIO_CLONED)); - bio_for_each_segment_all(bvec, bio, i) + bio_for_each_segment_all(bvec, bio, i, iter_all) SetPageUptodate(bvec->bv_page); } diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c index 0959044c5cee..5759bcd018cd 100644 --- a/fs/crypto/bio.c +++ b/fs/crypto/bio.c @@ -30,8 +30,9 @@ static void __fscrypt_decrypt_bio(struct bio *bio, bool done) { struct bio_vec *bv; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bv, bio, i) { + bio_for_each_segment_all(bv, bio, i, iter_all) { struct page *page = bv->bv_page; int ret = fscrypt_decrypt_page(page->mapping->host, page, PAGE_SIZE, 0, page->index); diff --git a/fs/direct-io.c b/fs/direct-io.c index ea07d5a34317..5904fc2e180c 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -551,7 +551,9 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio) if (dio->is_async && dio->op == REQ_OP_READ && dio->should_dirty) { bio_check_pages_dirty(bio); /* transfers ownership */ } else { - bio_for_each_segment_all(bvec, bio, i) { + struct bvec_iter_all iter_all; + + bio_for_each_segment_all(bvec, bio, i, iter_all) { struct page *page = bvec->bv_page; if (dio->op == REQ_OP_READ && !PageCompound(page) && diff --git a/fs/exofs/ore.c b/fs/exofs/ore.c index 5331a15a61f1..24a8e34882e9 100644 --- a/fs/exofs/ore.c +++ b/fs/exofs/ore.c @@ -420,8 +420,9 @@ static void _clear_bio(struct bio *bio) { struct bio_vec *bv; unsigned i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bv, bio, i) { + bio_for_each_segment_all(bv, bio, i, iter_all) { unsigned this_count = bv->bv_len; if (likely(PAGE_SIZE == this_count)) diff --git a/fs/exofs/ore_raid.c b/fs/exofs/ore_raid.c index 199590f36203..e83bab54b03e 100644 --- a/fs/exofs/ore_raid.c +++ b/fs/exofs/ore_raid.c @@ -468,11 +468,12 @@ static void _mark_read4write_pages_uptodate(struct ore_io_state *ios, int ret) /* loop on all devices all pages */ for (d = 0; d < ios->numdevs; d++) { struct bio *bio = ios->per_dev[d].bio; + struct bvec_iter_all iter_all; if (!bio) continue; - bio_for_each_segment_all(bv, bio, i) { + bio_for_each_segment_all(bv, bio, i, iter_all) { struct page *page = bv->bv_page; SetPageUptodate(page); diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index db7590178dfc..0644b4e7d6d4 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -63,8 +63,9 @@ static void ext4_finish_bio(struct bio *bio) { int i; struct bio_vec *bvec; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { struct page *page = bvec->bv_page; #ifdef CONFIG_EXT4_FS_ENCRYPTION struct page *data_page = NULL; diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c index f461d75ac049..b0d9537bc797 100644 --- a/fs/ext4/readpage.c +++ b/fs/ext4/readpage.c @@ -72,6 +72,7 @@ static void mpage_end_io(struct bio *bio) { struct bio_vec *bv; int i; + struct bvec_iter_all iter_all; if (ext4_bio_encrypted(bio)) { if (bio->bi_status) { @@ -81,7 +82,7 @@ static void mpage_end_io(struct bio *bio) return; } } - bio_for_each_segment_all(bv, bio, i) { + bio_for_each_segment_all(bv, bio, i, iter_all) { struct page *page = bv->bv_page; if (!bio->bi_status) { diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b293cb3e27a2..d28f482a0d52 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -87,8 +87,9 @@ static void __read_end_io(struct bio *bio) struct page *page; struct bio_vec *bv; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bv, bio, i) { + bio_for_each_segment_all(bv, bio, i, iter_all) { page = bv->bv_page; /* PG_error was set if any post_read step failed */ @@ -164,13 +165,14 @@ static void f2fs_write_end_io(struct bio *bio) struct f2fs_sb_info *sbi = bio->bi_private; struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; if (time_to_inject(sbi, FAULT_WRITE_IO)) { f2fs_show_injection_info(FAULT_WRITE_IO); bio->bi_status = BLK_STS_IOERR; } - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { struct page *page = bvec->bv_page; enum count_type type = WB_DATA_TYPE(page); @@ -347,6 +349,7 @@ static bool __has_merged_page(struct f2fs_bio_info *io, struct inode *inode, struct bio_vec *bvec; struct page *target; int i; + struct bvec_iter_all iter_all; if (!io->bio) return false; @@ -354,7 +357,7 @@ static bool __has_merged_page(struct f2fs_bio_info *io, struct inode *inode, if (!inode && !page && !ino) return true; - bio_for_each_segment_all(bvec, io->bio, i) { + bio_for_each_segment_all(bvec, io->bio, i, iter_all) { if (bvec->bv_page->mapping) target = bvec->bv_page; diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 4c7069b8f3c1..f2f165620161 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -168,7 +168,8 @@ u64 gfs2_log_bmap(struct gfs2_sbd *sdp) * that is pinned in the pagecache. */ -static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, struct bio_vec *bvec, +static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, + struct bio_vec *bvec, blk_status_t error) { struct buffer_head *bh, *next; @@ -207,6 +208,7 @@ static void gfs2_end_log_write(struct bio *bio) struct bio_vec *bvec; struct page *page; int i; + struct bvec_iter_all iter_all; if (bio->bi_status) { fs_err(sdp, "Error %d writing to journal, jid=%u\n", @@ -214,7 +216,7 @@ static void gfs2_end_log_write(struct bio *bio) wake_up(&sdp->sd_logd_waitq); } - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { page = bvec->bv_page; if (page_has_buffers(page)) gfs2_end_log_write_bh(sdp, bvec, bio->bi_status); diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index be9c0bf697fe..3201342404a7 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -190,8 +190,9 @@ static void gfs2_meta_read_endio(struct bio *bio) { struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) { + bio_for_each_segment_all(bvec, bio, i, iter_all) { struct page *page = bvec->bv_page; struct buffer_head *bh = page_buffers(page); unsigned int len = bvec->bv_len; diff --git a/fs/iomap.c b/fs/iomap.c index b0462b363bad..f5fb8bf75cc8 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -262,8 +262,9 @@ iomap_read_end_io(struct bio *bio) int error = blk_status_to_errno(bio->bi_status); struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) + bio_for_each_segment_all(bvec, bio, i, iter_all) iomap_read_page_end_io(bvec, error); bio_put(bio); } @@ -1541,8 +1542,9 @@ static void iomap_dio_bio_end_io(struct bio *bio) } else { struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bvec, bio, i) + bio_for_each_segment_all(bvec, bio, i, iter_all) put_page(bvec->bv_page); bio_put(bio); } diff --git a/fs/mpage.c b/fs/mpage.c index c820dc9bebab..3f19da75178b 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -48,8 +48,9 @@ static void mpage_end_io(struct bio *bio) { struct bio_vec *bv; int i; + struct bvec_iter_all iter_all; - bio_for_each_segment_all(bv, bio, i) { + bio_for_each_segment_all(bv, bio, i, iter_all) { struct page *page = bv->bv_page; page_endio(page, bio_op(bio), blk_status_to_errno(bio->bi_status)); diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 338b9d9984e0..1f1829e506e8 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -62,7 +62,7 @@ xfs_find_daxdev_for_inode( static void xfs_finish_page_writeback( struct inode *inode, - struct bio_vec *bvec, + struct bio_vec *bvec, int error) { struct iomap_page *iop = to_iomap_page(bvec->bv_page); @@ -98,6 +98,7 @@ xfs_destroy_ioend( for (bio = &ioend->io_inline_bio; bio; bio = next) { struct bio_vec *bvec; int i; + struct bvec_iter_all iter_all; /* * For the last bio, bi_private points to the ioend, so we @@ -109,7 +110,7 @@ xfs_destroy_ioend( next = bio->bi_private; /* walk each page on bio, ending page IO on them */ - bio_for_each_segment_all(bvec, bio, i) + bio_for_each_segment_all(bvec, bio, i, iter_all) xfs_finish_page_writeback(inode, bvec, error); bio_put(bio); } diff --git a/include/linux/bio.h b/include/linux/bio.h index 9d6284f53c07..7edad188568a 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -131,12 +131,19 @@ static inline bool bio_full(struct bio *bio) return bio->bi_vcnt >= bio->bi_max_vecs; } +#define bvec_for_each_segment(bv, bvl, i, iter_all) \ + for (bv = bvec_init_iter_all(&iter_all); \ + (iter_all.done < (bvl)->bv_len) && \ + (bvec_next_segment((bvl), &iter_all), 1); \ + iter_all.done += bv->bv_len, i += 1) + /* * drivers should _never_ use the all version - the bio may have been split * before it got to the driver and the driver won't own all of it */ -#define bio_for_each_segment_all(bvl, bio, i) \ - for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++) +#define bio_for_each_segment_all(bvl, bio, i, iter_all) \ + for (i = 0, iter_all.idx = 0; iter_all.idx < (bio)->bi_vcnt; iter_all.idx++) \ + bvec_for_each_segment(bvl, &((bio)->bi_io_vec[iter_all.idx]), i, iter_all) static inline void __bio_advance_iter(struct bio *bio, struct bvec_iter *iter, unsigned bytes, unsigned max_seg_len) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index b37d13a79a7d..cab36d838ed0 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -47,6 +47,12 @@ struct bvec_iter { current bvec */ }; +struct bvec_iter_all { + struct bio_vec bv; + int idx; + unsigned done; +}; + /* * various member access, note that bio_data should of course not be used * on highmem page vectors @@ -173,6 +179,31 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +static inline struct bio_vec *bvec_init_iter_all(struct bvec_iter_all *iter_all) +{ + iter_all->bv.bv_page = NULL; + iter_all->done = 0; + + return &iter_all->bv; +} + +/* used for chunk_for_each_segment */ +static inline void bvec_next_segment(const struct bio_vec *bvec, + struct bvec_iter_all *iter_all) +{ + struct bio_vec *bv = &iter_all->bv; + + if (bv->bv_page) { + bv->bv_page += 1; + bv->bv_offset = 0; + } else { + bv->bv_page = bvec->bv_page; + bv->bv_offset = bvec->bv_offset; + } + bv->bv_len = min_t(unsigned int, PAGE_SIZE - bv->bv_offset, + bvec->bv_len - iter_all->done); +} + /* * Get the last single-page segment from the multi-page bvec and store it * in @seg From patchwork Wed Nov 21 03:23:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCF9A16B1 for ; Wed, 21 Nov 2018 03:27:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8BD22B40C for ; Wed, 21 Nov 2018 03:27:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B7762B413; Wed, 21 Nov 2018 03:27:59 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D7132B40C for ; Wed, 21 Nov 2018 03:27:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2855B6B23AC; Tue, 20 Nov 2018 22:27:58 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 25B576B23AE; Tue, 20 Nov 2018 22:27:58 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1235F6B23AF; Tue, 20 Nov 2018 22:27:58 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id CD5336B23AC for ; Tue, 20 Nov 2018 22:27:57 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id k90so2205753qte.0 for ; Tue, 20 Nov 2018 19:27:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=63G3Yiof/TLe/YK7FUAO4Ce9oknIz89WHs4FwByfDTI=; b=puw/Mzhx3EtvHqU2Ygiy3Yeoi7EobrEGYNzzgsJ5nbv8Mz4i/3oFnvqNX/lQ+spe7+ UGoA/7t/XtV7FaPfKXdEvwN6td9DJwAyCgerRLKQ0w2bj6SQjDmzoFaO7yAdBzaMsWDx YZo8mZmUXvdk4y2D26TU29ZiIkL9TNSGo8htjqI5CPOwGLBvdECM13+aL6l7oG6uVG4d eRfdFlErbTmtBk6bmdFDcwBlVD9TO+XNjenNf/tzC9F9ZJQTcHozr0zc6SOVngpYcPxM 0Z/I4xKrvc9hDao1k34sJWWdtEiJTDEPBVoc8k46rr1ROl6jWkTy3kMVOwip88Yoeds5 QK3w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gIrCUtKFWj7Pw5XOIs6XKY8Gx/hEhJMz8PDnmjvX6J70bhLE8QL EnnkmR6JBqyl39OfjaX9+JJzjk71abu3wO7TAGgonFizwAAXWeziKJXYaZoI9hX73O6Yq+JTjTp 53OoBHPZ2CkRo8bxOtOjJUIHZfYOx9ZadLOmNEIVjgKgiLPzbBP4HBoW6gR7EJdnIcg== X-Received: by 2002:ac8:3a22:: with SMTP id w31mr4295857qte.302.1542770877569; Tue, 20 Nov 2018 19:27:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/Voq+694iyajeqYvd/vcuB+6NPQ8mT+8UqPQ2TjK7XPgZXr6YwjI1yUntCWHyfxsJV1Adoi X-Received: by 2002:ac8:3a22:: with SMTP id w31mr4295831qte.302.1542770876724; Tue, 20 Nov 2018 19:27:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770876; cv=none; d=google.com; s=arc-20160816; b=UCidd8QAUzGNw0ewDHBFUldQ7/kib0z9vblzO3Tj34dTmUiJwRJpoJ9TOO6/QT5agK S2PmHGGcrvervU3z3GF+lRhkgMFSDTslUH43tZLFBWxLvnyoZOUpPW+GFmGDKnnUZhP5 g/pGyuDmUoT4fWtaz4AAIYXKk6wTm4uwarGTNZtO+JWupHkEAUgY7XbBsadukZU3mJj+ bHqDUYGadaQTPDd8pRpwPJZ4pncz2iKD/YxeuZgpdKi3eFoDWuSoMjrwB2muP4fci8Jf C8qoSpDjbrQNdaI3TYnf8CSmI0FjjYO0a58qOjVH2zTJTHlpUv4fh5FKlvrGV1HMK0/I bX4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=63G3Yiof/TLe/YK7FUAO4Ce9oknIz89WHs4FwByfDTI=; b=fqkLn0MLPzPwALu1xY0MygjqkhJyRNHOVqykAehNd64lu0FBTNC39H8hEu3T0U789W 0Wet2xskBW8XVycht/xdosBlD6QihYNiDjLF5sF1ykctvBqS4VLUIMifR1G+++GRnxDv hX4JsObfwaU7/qZk+9YaMXWO+5WNexMLK4KFpPmoR1coOj7yeYy6AKTiQNJV15AlZMRh yxHfwvLSS48JoiNIY9rCPG380UVRWCfaFxC0HA42xcFXc1oyQe+FEgQSMd6dbcleWK+e j1hx2CmUvQJPag7RUUBqcLMeUHLoumGriqCAvk5z5YnGwzvBiS6SMiydGpo4X6o6mxuW oj1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id q49si3042533qtc.78.2018.11.20.19.27.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:27:56 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 81F973083390; Wed, 21 Nov 2018 03:27:55 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 091845D75D; Wed, 21 Nov 2018 03:27:47 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 13/19] block: move bounce_clone_bio into bio.c Date: Wed, 21 Nov 2018 11:23:21 +0800 Message-Id: <20181121032327.8434-14-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 21 Nov 2018 03:27:55 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We will reuse bounce_clone_bio() for cloning bio in case of !blk_queue_cluster(q), so move this helper into bio.c and rename it as bio_clone_bioset(). No function change. Signed-off-by: Ming Lei --- block/bio.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ block/blk.h | 2 ++ block/bounce.c | 70 +--------------------------------------------------------- 3 files changed, 72 insertions(+), 69 deletions(-) diff --git a/block/bio.c b/block/bio.c index 2680aa42a625..0f1635b9ec50 100644 --- a/block/bio.c +++ b/block/bio.c @@ -647,6 +647,75 @@ struct bio *bio_clone_fast(struct bio *bio, gfp_t gfp_mask, struct bio_set *bs) } EXPORT_SYMBOL(bio_clone_fast); +/* block core only helper */ +struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, + struct bio_set *bs) +{ + struct bvec_iter iter; + struct bio_vec bv; + struct bio *bio; + + /* + * Pre immutable biovecs, __bio_clone() used to just do a memcpy from + * bio_src->bi_io_vec to bio->bi_io_vec. + * + * We can't do that anymore, because: + * + * - The point of cloning the biovec is to produce a bio with a biovec + * the caller can modify: bi_idx and bi_bvec_done should be 0. + * + * - The original bio could've had more than BIO_MAX_PAGES biovecs; if + * we tried to clone the whole thing bio_alloc_bioset() would fail. + * But the clone should succeed as long as the number of biovecs we + * actually need to allocate is fewer than BIO_MAX_PAGES. + * + * - Lastly, bi_vcnt should not be looked at or relied upon by code + * that does not own the bio - reason being drivers don't use it for + * iterating over the biovec anymore, so expecting it to be kept up + * to date (i.e. for clones that share the parent biovec) is just + * asking for trouble and would force extra work on + * __bio_clone_fast() anyways. + */ + + bio = bio_alloc_bioset(gfp_mask, bio_segments(bio_src), bs); + if (!bio) + return NULL; + bio->bi_disk = bio_src->bi_disk; + bio->bi_opf = bio_src->bi_opf; + bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_write_hint = bio_src->bi_write_hint; + bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; + bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; + + switch (bio_op(bio)) { + case REQ_OP_DISCARD: + case REQ_OP_SECURE_ERASE: + case REQ_OP_WRITE_ZEROES: + break; + case REQ_OP_WRITE_SAME: + bio->bi_io_vec[bio->bi_vcnt++] = bio_src->bi_io_vec[0]; + break; + default: + bio_for_each_segment(bv, bio_src, iter) + bio->bi_io_vec[bio->bi_vcnt++] = bv; + break; + } + + if (bio_integrity(bio_src)) { + int ret; + + ret = bio_integrity_clone(bio, bio_src, gfp_mask); + if (ret < 0) { + bio_put(bio); + return NULL; + } + } + + bio_clone_blkcg_association(bio, bio_src); + + return bio; +} + /** * bio_add_pc_page - attempt to add page to bio * @q: the target queue diff --git a/block/blk.h b/block/blk.h index 816a9abb87cd..31c0e45aba3a 100644 --- a/block/blk.h +++ b/block/blk.h @@ -336,6 +336,8 @@ static inline int blk_iolatency_init(struct request_queue *q) { return 0; } struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp); +struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, struct bio_set *bs); + #ifdef CONFIG_BLK_DEV_ZONED void blk_queue_free_zone_bitmaps(struct request_queue *q); #else diff --git a/block/bounce.c b/block/bounce.c index 7338041e3042..4947c36173b2 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -215,74 +215,6 @@ static void bounce_end_io_read_isa(struct bio *bio) __bounce_end_io_read(bio, &isa_page_pool); } -static struct bio *bounce_clone_bio(struct bio *bio_src, gfp_t gfp_mask, - struct bio_set *bs) -{ - struct bvec_iter iter; - struct bio_vec bv; - struct bio *bio; - - /* - * Pre immutable biovecs, __bio_clone() used to just do a memcpy from - * bio_src->bi_io_vec to bio->bi_io_vec. - * - * We can't do that anymore, because: - * - * - The point of cloning the biovec is to produce a bio with a biovec - * the caller can modify: bi_idx and bi_bvec_done should be 0. - * - * - The original bio could've had more than BIO_MAX_PAGES biovecs; if - * we tried to clone the whole thing bio_alloc_bioset() would fail. - * But the clone should succeed as long as the number of biovecs we - * actually need to allocate is fewer than BIO_MAX_PAGES. - * - * - Lastly, bi_vcnt should not be looked at or relied upon by code - * that does not own the bio - reason being drivers don't use it for - * iterating over the biovec anymore, so expecting it to be kept up - * to date (i.e. for clones that share the parent biovec) is just - * asking for trouble and would force extra work on - * __bio_clone_fast() anyways. - */ - - bio = bio_alloc_bioset(gfp_mask, bio_segments(bio_src), bs); - if (!bio) - return NULL; - bio->bi_disk = bio_src->bi_disk; - bio->bi_opf = bio_src->bi_opf; - bio->bi_ioprio = bio_src->bi_ioprio; - bio->bi_write_hint = bio_src->bi_write_hint; - bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; - bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; - - switch (bio_op(bio)) { - case REQ_OP_DISCARD: - case REQ_OP_SECURE_ERASE: - case REQ_OP_WRITE_ZEROES: - break; - case REQ_OP_WRITE_SAME: - bio->bi_io_vec[bio->bi_vcnt++] = bio_src->bi_io_vec[0]; - break; - default: - bio_for_each_segment(bv, bio_src, iter) - bio->bi_io_vec[bio->bi_vcnt++] = bv; - break; - } - - if (bio_integrity(bio_src)) { - int ret; - - ret = bio_integrity_clone(bio, bio_src, gfp_mask); - if (ret < 0) { - bio_put(bio); - return NULL; - } - } - - bio_clone_blkcg_association(bio, bio_src); - - return bio; -} - static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, mempool_t *pool) { @@ -311,7 +243,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, generic_make_request(*bio_orig); *bio_orig = bio; } - bio = bounce_clone_bio(*bio_orig, GFP_NOIO, passthrough ? NULL : + bio = bio_clone_bioset(*bio_orig, GFP_NOIO, passthrough ? NULL : &bounce_bio_set); bio_for_each_segment_all(to, bio, i, iter_all) { From patchwork Wed Nov 21 03:23:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691761 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A33A13BB for ; Wed, 21 Nov 2018 03:28:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 382E92B412 for ; Wed, 21 Nov 2018 03:28:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B3192B415; Wed, 21 Nov 2018 03:28:20 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A52DF2B412 for ; Wed, 21 Nov 2018 03:28:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B36E06B23B0; Tue, 20 Nov 2018 22:28:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AE4E76B23B1; Tue, 20 Nov 2018 22:28:18 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D7F96B23B2; Tue, 20 Nov 2018 22:28:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 6CA1A6B23B0 for ; Tue, 20 Nov 2018 22:28:18 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id q3so2203683qtq.15 for ; Tue, 20 Nov 2018 19:28:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=u/GwWcK6UN3Z/q7XxvOIQRRKJq08yyNNXRcBbF1NJ+s=; b=Yzs7hYT736vvk+wowv+gJ14qk1HwFMWBjb+UfIdbEgnNVG9W5oVKkjCjQxRU4NhDTO fH1hwa2BVjlcf+y4n5JkKdg92W4yqZ2IlVVEdCa6LAWOd+LMW7xn7ELR73RpZ4ZD0YE/ 4UQ2TUBKaH2qh0OkR2+DyamfAMFLt2f95ThduxA+ESEqqd8+frkJgiZlTPEI343tAH5x dBlDKbv5rH8Ilf2gqvaCM5BAYqfXDNuHveAq5aPP9Y/+vEL2CKOivcfiVdYZyHJNl6Eb RF53SUNuC7cA8neUZOUobiH7SJ/gkMNoHWpCsufKChOzIatOKzSovZDPi1AXjKdMa1WN ZBGw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWaMNzwP+jiFueUQyby7iw3Q/7IMBv+61lHuvrqWbwf2ROk1MTkO zUangdFh2FyZxCCNySDP5PGVPOyVOedEleihBPADuysX6Go54gS7aWN3AcMdzTUn+GaStRq0PBf sOHfBgNfqry33bPLRsNHEnng15tZbXJDpfQAokNlwWwUfkfWTe61OYsBJha4giX5GOA== X-Received: by 2002:aed:3802:: with SMTP id j2mr4468653qte.146.1542770898209; Tue, 20 Nov 2018 19:28:18 -0800 (PST) X-Google-Smtp-Source: AJdET5eX3SoqgO6KmiiWjso5hy2ojcYWW7vF/pLcWsceMGOZIFUQ75jHGyo3FksmM49UW71Szwkc X-Received: by 2002:aed:3802:: with SMTP id j2mr4468607qte.146.1542770897005; Tue, 20 Nov 2018 19:28:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770896; cv=none; d=google.com; s=arc-20160816; b=aU9PgzM5JsFoFw3aVcgv1AGlOQ91kq6Yp+RBQN60+9A4Tb1fo8RzdfRH1sOk+Jn97I G5eDPWzd/GRklUhHA5eWnJNk2nCEfevp36FXgB/L3dJGX/TcB0shjD8iDfYY8QIR9vwE mW4ld1fivIrX3wfFrUv0rPJ6W5dvxhMk8UPydOe3wsE/+EjKqU0NrNkZjK514RAr2vKm uip0E4nrn6Q5AmZwlBszKRCfic8n6euPDPjJe0t9F2p8R3qijraQqnsmvW5KcZk7MRny 1FviFzA5nrLFh6CO6ci7v7LTZRwZXxjbHX8zMAhzroB4b8aO35cu/LfejWPv6ChyOojE uPeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=u/GwWcK6UN3Z/q7XxvOIQRRKJq08yyNNXRcBbF1NJ+s=; b=PhjKdoiz8bRLX2SJGLVkGG6dLHU8NSqfaEVf8AxerysbPCsWRJGwtIV+BiUp5METBb 8Hc993fhMadXbQidPnXfSkfYaraqo/fgX70A22LB0mHaYNI0osWlIW2zPJ+uLYSxzSQ+ OzudZmBMfPiRWbNYcvf/cU7FPtKV7MGEf3F6sTJgbEJfhu/+EK07fcZjldDv0AiqQDur fiMzxCD06uqoOkPimbBSyLSz8Cv4hUewn1lya7Al2TtrdMbvI9JthI6S5sQHYS84jm4g RBIjwI3gbrQPrGf4UiHFuxu1Rv+LS0iU6Y6IhrMTW8TgdI7M3+EbZnxfY3TnUo8bBizb qvUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id d42si5034877qve.68.2018.11.20.19.28.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:28:16 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD8E4309706B; Wed, 21 Nov 2018 03:28:15 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id B383B17188; Wed, 21 Nov 2018 03:27:57 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 14/19] block: handle non-cluster bio out of blk_bio_segment_split Date: Wed, 21 Nov 2018 11:23:22 +0800 Message-Id: <20181121032327.8434-15-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 21 Nov 2018 03:28:16 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We will enable multi-page bvec soon, but non-cluster queue can't handle the multi-page bvec at all. This patch borrows bounce's idea to clone new single-page bio for non-cluster queue, and moves its handling out of blk_bio_segment_split(). Signed-off-by: Ming Lei Signed-off-by: Christoph Hellwig --- block/Makefile | 3 ++- block/blk-merge.c | 6 ++++- block/blk.h | 2 ++ block/non-cluster.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 block/non-cluster.c diff --git a/block/Makefile b/block/Makefile index eee1b4ceecf9..e07d59438c4b 100644 --- a/block/Makefile +++ b/block/Makefile @@ -9,7 +9,8 @@ obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-sysfs.o \ blk-lib.o blk-mq.o blk-mq-tag.o blk-stat.o \ blk-mq-sysfs.o blk-mq-cpumap.o blk-mq-sched.o ioctl.o \ genhd.o partition-generic.o ioprio.o \ - badblocks.o partitions/ blk-rq-qos.o + badblocks.o partitions/ blk-rq-qos.o \ + non-cluster.o obj-$(CONFIG_BOUNCE) += bounce.o obj-$(CONFIG_BLK_SCSI_REQUEST) += scsi_ioctl.o diff --git a/block/blk-merge.c b/block/blk-merge.c index 8829c51b4e75..7c44216c1b58 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -247,7 +247,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, goto split; } - if (bvprvp && blk_queue_cluster(q)) { + if (bvprvp) { if (seg_size + bv.bv_len > queue_max_segment_size(q)) goto new_segment; if (!biovec_phys_mergeable(q, bvprvp, &bv)) @@ -307,6 +307,10 @@ void blk_queue_split(struct request_queue *q, struct bio **bio) split = blk_bio_write_same_split(q, *bio, &q->bio_split, &nsegs); break; default: + if (!blk_queue_cluster(q)) { + blk_queue_non_cluster_bio(q, bio); + return; + } split = blk_bio_segment_split(q, *bio, &q->bio_split, &nsegs); break; } diff --git a/block/blk.h b/block/blk.h index 31c0e45aba3a..6fc5821ced55 100644 --- a/block/blk.h +++ b/block/blk.h @@ -338,6 +338,8 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp); struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, struct bio_set *bs); +void blk_queue_non_cluster_bio(struct request_queue *q, struct bio **bio_orig); + #ifdef CONFIG_BLK_DEV_ZONED void blk_queue_free_zone_bitmaps(struct request_queue *q); #else diff --git a/block/non-cluster.c b/block/non-cluster.c new file mode 100644 index 000000000000..9c2910be9404 --- /dev/null +++ b/block/non-cluster.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +/* non-cluster handling for block devices */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "blk.h" + +static struct bio_set non_cluster_bio_set, non_cluster_bio_split; + +static __init int init_non_cluster_bioset(void) +{ + WARN_ON(bioset_init(&non_cluster_bio_set, BIO_POOL_SIZE, 0, + BIOSET_NEED_BVECS)); + WARN_ON(bioset_integrity_create(&non_cluster_bio_set, BIO_POOL_SIZE)); + WARN_ON(bioset_init(&non_cluster_bio_split, BIO_POOL_SIZE, 0, 0)); + + return 0; +} +__initcall(init_non_cluster_bioset); + +static void non_cluster_end_io(struct bio *bio) +{ + struct bio *bio_orig = bio->bi_private; + + bio_orig->bi_status = bio->bi_status; + bio_endio(bio_orig); + bio_put(bio); +} + +void blk_queue_non_cluster_bio(struct request_queue *q, struct bio **bio_orig) +{ + struct bio *bio; + struct bvec_iter iter; + struct bio_vec from; + unsigned i = 0; + unsigned sectors = 0; + unsigned short max_segs = min_t(unsigned short, BIO_MAX_PAGES, + queue_max_segments(q)); + + bio_for_each_segment(from, *bio_orig, iter) { + if (i++ < max_segs) + sectors += from.bv_len >> 9; + else + break; + } + + if (sectors < bio_sectors(*bio_orig)) { + bio = bio_split(*bio_orig, sectors, GFP_NOIO, + &non_cluster_bio_split); + bio_chain(bio, *bio_orig); + generic_make_request(*bio_orig); + *bio_orig = bio; + } + bio = bio_clone_bioset(*bio_orig, GFP_NOIO, &non_cluster_bio_set); + + bio->bi_phys_segments = bio_segments(bio); + bio_set_flag(bio, BIO_SEG_VALID); + bio->bi_end_io = non_cluster_end_io; + + bio->bi_private = *bio_orig; + *bio_orig = bio; +} From patchwork Wed Nov 21 03:23:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 562FE13BB for ; Wed, 21 Nov 2018 03:28:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41EFD2AB6F for ; Wed, 21 Nov 2018 03:28:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34FAD2B440; Wed, 21 Nov 2018 03:28:35 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4EA12B3F4 for ; Wed, 21 Nov 2018 03:28:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7EF36B23B1; Tue, 20 Nov 2018 22:28:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D2FBC6B23B3; Tue, 20 Nov 2018 22:28:33 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C21566B23B4; Tue, 20 Nov 2018 22:28:33 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 906416B23B1 for ; Tue, 20 Nov 2018 22:28:33 -0500 (EST) Received: by mail-qk1-f198.google.com with SMTP id n68so5398387qkn.8 for ; Tue, 20 Nov 2018 19:28:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=9NZ8XI0wSMWu+PvCtOk6AcrbND/96y9gK36RFJAfcOQ=; b=g9lz21REOQhSrq4EvUzLJVWh8l4TXpe1oASbbtMGFM3Haw+zDA7Fjk0JfElX4KAYSf Ggukz1/hnQnXatQuJqekpVW9OvA6z2rsVW8EpHmL9h9Yp9jLtwYqgxZD+f8IzSwJRtaw VdFy5iGMh2Rivkx2DJgUH98on+Z97D8mIavEzvNa81yQ6Vc/Y9unEXpmwFGhnIwhCs/l 6BIF0yraSN/qUQk1xkHY1rR8TN7L4udvATIxrarQ0PhsDJDYVQWvN+CevMRnvZFDT4nn hIFGBsiKCr0IJS/Iy2Xv/YAaJ0qmWjM9ngRqnnhgOVT1WSCumEKSe1Ac10btN5PN2IXT Uu8Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWbnUeH3lhGtFIBugWJr+BDszXktEDmxT1H5j8pzZanLvGEWpkQp HLIkQPkMk3bOCyyBBvsxOE8dNb/HoiYkedAZK4OUf55A/K1CV5oZ4uzUERHn/vyXJgXzwMHDRvU SESvtE1eXoPkmJy8fwGJ8SobCg01hQpEVlaZFhVzNplZ9axu6sA6byOlg/UKjDStrxQ== X-Received: by 2002:a37:b1c7:: with SMTP id a190mr3983525qkf.94.1542770913344; Tue, 20 Nov 2018 19:28:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/UV2YjV+8Kq1wZnkcsF6OMjciwvZhKhrqZRWwHykVBW4Mn0Vhd4Sc2FipBml7mfG/c0+bzR X-Received: by 2002:a37:b1c7:: with SMTP id a190mr3983497qkf.94.1542770912092; Tue, 20 Nov 2018 19:28:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770912; cv=none; d=google.com; s=arc-20160816; b=Zxnt1XH7p2UEY1gE034CYfJmFUQAuo+8VLvx9Mem5DpCK28HoCP6/mtOoAia8U9DNr eVgZHTTYv837YfMpFI87A0QT8DdORrAbdUm7Im1NFP1V0bvsZQ40rZ8U9RHNpIdhwOoP 1cFRKj+8tdH3FbInejkEeztiHFXX2dfQHC5XUL4ajPo4U85rVGVoPpfjX6jo6BfQ4ed0 hc+Qw/RUeL6yJq0Xi4MCCO9kuOC1/wQS8S6yRyyw+SvJ6mNdkdne8mQ8fL507999Y+Us KerzZ6gaX/2fdN68bPpCfrW0c8GqjtZQpjSdR9YODPZTtL6o97UC5yxwVHHdaFaFUtXN CWkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=9NZ8XI0wSMWu+PvCtOk6AcrbND/96y9gK36RFJAfcOQ=; b=wrvhmY0XvFm6RFXaGxhAgFgrik17yj6o7ObbVD//P+DlUm4gSrJLSR8IFcbcXasXBU R0tBb4KRts8tmQZoFhOjJ3i0a5R3LIS5fZY3bMP5KLj0K/5vVKXMFkQyksLjtuIudp9j aO9eQ4TsR3MUEOI/N06BWuO2S1I79NI0hBlYHiW5Qq3+Wp8UqrpgIsg1oK8m1KwCq9Mk 4vTpyvyVz/CRZMvBCEq29Bz1eVuZnh/M6/ucvlYlgpMPDgu6RQ6XIkm4jiCahyqEdPCR MsmFZkJ0GayQb7OeZRiTUwC+N73Vh0uGOUl37ZmIlDLOimHXSuUjWwYl7c52OWdDtXGL 9mow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id a22si153514qtc.162.2018.11.20.19.28.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:28:32 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E45D3083390; Wed, 21 Nov 2018 03:28:30 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 072B117A6A; Wed, 21 Nov 2018 03:28:17 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 15/19] block: enable multipage bvecs Date: Wed, 21 Nov 2018 11:23:23 +0800 Message-Id: <20181121032327.8434-16-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 21 Nov 2018 03:28:31 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch pulls the trigger for multi-page bvecs. Signed-off-by: Ming Lei --- block/bio.c | 32 +++++++++++++++++++++++++++----- fs/iomap.c | 2 +- fs/xfs/xfs_aops.c | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/block/bio.c b/block/bio.c index 0f1635b9ec50..854676edc438 100644 --- a/block/bio.c +++ b/block/bio.c @@ -823,7 +823,7 @@ EXPORT_SYMBOL(bio_add_pc_page); * @len: length of the data to add * @off: offset of the data in @page * - * Try to add the data at @page + @off to the last bvec of @bio. This is a + * Try to add the data at @page + @off to the last page of @bio. This is a * a useful optimisation for file systems with a block size smaller than the * page size. * @@ -836,10 +836,13 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page, return false; if (bio->bi_vcnt > 0) { - struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1]; + struct bio_vec bv; + struct bio_vec *seg = &bio->bi_io_vec[bio->bi_vcnt - 1]; - if (page == bv->bv_page && off == bv->bv_offset + bv->bv_len) { - bv->bv_len += len; + bvec_last_segment(seg, &bv); + + if (page == bv.bv_page && off == bv.bv_offset + bv.bv_len) { + seg->bv_len += len; bio->bi_iter.bi_size += len; return true; } @@ -848,6 +851,25 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page, } EXPORT_SYMBOL_GPL(__bio_try_merge_page); +static bool bio_try_merge_segment(struct bio *bio, struct page *page, + unsigned int len, unsigned int off) +{ + if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED))) + return false; + + if (bio->bi_vcnt > 0) { + struct bio_vec *seg = &bio->bi_io_vec[bio->bi_vcnt - 1]; + + if (page_to_phys(seg->bv_page) + seg->bv_offset + seg->bv_len == + page_to_phys(page) + off) { + seg->bv_len += len; + bio->bi_iter.bi_size += len; + return true; + } + } + return false; +} + /** * __bio_add_page - add page to a bio in a new segment * @bio: destination bio @@ -888,7 +910,7 @@ EXPORT_SYMBOL_GPL(__bio_add_page); int bio_add_page(struct bio *bio, struct page *page, unsigned int len, unsigned int offset) { - if (!__bio_try_merge_page(bio, page, len, offset)) { + if (!bio_try_merge_segment(bio, page, len, offset)) { if (bio_full(bio)) return 0; __bio_add_page(bio, page, len, offset); diff --git a/fs/iomap.c b/fs/iomap.c index f5fb8bf75cc8..ccc2ba115f4d 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -344,7 +344,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, ctx->bio->bi_end_io = iomap_read_end_io; } - __bio_add_page(ctx->bio, page, plen, poff); + bio_add_page(ctx->bio, page, plen, poff); done: /* * Move the caller beyond our range so that it keeps making progress. diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 1f1829e506e8..5c2190216614 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -621,7 +621,7 @@ xfs_add_to_ioend( atomic_inc(&iop->write_count); if (bio_full(wpc->ioend->io_bio)) xfs_chain_bio(wpc->ioend, wbc, bdev, sector); - __bio_add_page(wpc->ioend->io_bio, page, len, poff); + bio_add_page(wpc->ioend->io_bio, page, len, poff); } wpc->ioend->io_size += len; From patchwork Wed Nov 21 03:23:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D9B41923 for ; Wed, 21 Nov 2018 03:28:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 688122AB6F for ; Wed, 21 Nov 2018 03:28:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C6362B4A2; Wed, 21 Nov 2018 03:28:50 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 052312AB6F for ; Wed, 21 Nov 2018 03:28:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3203E6B23B3; Tue, 20 Nov 2018 22:28:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2CF956B23B5; Tue, 20 Nov 2018 22:28:49 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BE1B6B23B6; Tue, 20 Nov 2018 22:28:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by kanga.kvack.org (Postfix) with ESMTP id D9E4F6B23B3 for ; Tue, 20 Nov 2018 22:28:48 -0500 (EST) Received: by mail-qt1-f198.google.com with SMTP id t42so2165974qth.12 for ; Tue, 20 Nov 2018 19:28:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=ccjdxmidawr//6DUiNVasZz3CTPbE58G5NElQttCP+E=; b=Hr1zjl+H63VEDQer9ARMBRSsYibUOlMIbUjhEZslFSweQLCk+ihp98BZHuInZmoQEY v3x6Jj1rXqnjCEzANBkIBYGrfVg0ShZFEIeNzbw2a1vPNvn7kKTrVrEnpqEHzpRUSICZ m8ypx/UcKcsbAAzhK/PuD6SK0sv4r9CLRypjFMYJBhBklWEk1H7lFe353hr9IULIuDpB xcBuIGlVaseOixe21gCPD+BjWcltqvtjhiZRLzl1a6Sq6uUy6wgzCbS986LOzXCTLute LhKMauPcYFwCdAz6lCA2GbIJQFj10ksOnQA7BWVVPBkSgowrXY+cz449MqSEAm4bNd99 1Sqg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gJiyesl7yeJkvle0ihNjtAkevrJXQKH2pKzwCCAKrV7UUnrufJv CYR5JlDOjZAdYAN7JJoWRv2AFJ9jEjlwWKeq/bA1w9Slc/S79vPVgvvsQpNhnVcaViKILvVYXO4 hawIAONCnBOwJMCkaDgbR+mH3xgEeK0V7ISmI2m9LV5fF8mVtA+A/a51irrFTcrIx/g== X-Received: by 2002:ac8:1e84:: with SMTP id c4mr4369385qtm.181.1542770928646; Tue, 20 Nov 2018 19:28:48 -0800 (PST) X-Google-Smtp-Source: AJdET5cDqlafpCOnmM+Qdh458r7AQr+mkxvPImvfD8XHh4xet3gecO2f7fpNJWWypaARHlq1M1BV X-Received: by 2002:ac8:1e84:: with SMTP id c4mr4369364qtm.181.1542770928103; Tue, 20 Nov 2018 19:28:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770928; cv=none; d=google.com; s=arc-20160816; b=npPub1cTHXJHYNTidXKsfnSbjkOJksp5iszNrgCetxhvJ15JODPhnUy43M9CgWvzf6 A3VHBthZcBFqNyo/r45yyoWBb1kow7TZ+WB9IDXBYeZK1N4rKXECeeU1i2LztxtrFJPU Pvjt5DmOvLwCg/4m6sLQPJ1NzNLnCrHi/dHc5eK/zx+/xLsc7rbPpXme2xTuZGmEbveg by9Y1AvwLvaMMHXLSh+NgUmCLtkuWAjYzylmvHpvae3xsuC5YB6DfBhLqzMxv8RBZGW/ YxGnUQEB/TMfi4uGr/4Hg/Xamn6X0FHNC81jiWYSjO5hy8PQjQaqPVTXhO/4JQQudiPh yMoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=ccjdxmidawr//6DUiNVasZz3CTPbE58G5NElQttCP+E=; b=YzWcnq/MEv7XMdsAROIZ3M/2Xsjr8L4Fkl+9YlnjrMQ5YToUH5mFLw40kqkZ7JKTqt XJtudfEOTKOJYud4bbrGtB2ldTZHpUJXWKzb1v1hyajLOvMDB7zPTbmopHaMEm9WtWmX qycgZI//shYCnjGlaxBeEkuUiqeM0yA7fS8KO8P6CfoNvavOZVR322DsOYlxtz3DivZr 3fkxc1NogbEChocS31TO5K7nbpVqcnU7tcgsXCPgN3kflSDTz5a9AclpwTMZWVQ2SpTD OT88UDFj4e3QoMylG3NHL+rnAYwi2tdS0g07OdchP1VYD1ixCuceHyxg4/rYrvFRJNta aeyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id e25si11448732qvb.25.2018.11.20.19.28.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:28:48 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 013083082E4D; Wed, 21 Nov 2018 03:28:47 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id C40FF7E383; Wed, 21 Nov 2018 03:28:32 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 16/19] block: always define BIO_MAX_PAGES as 256 Date: Wed, 21 Nov 2018 11:23:24 +0800 Message-Id: <20181121032327.8434-17-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 21 Nov 2018 03:28:47 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Now multi-page bvec can cover CONFIG_THP_SWAP, so we don't need to increase BIO_MAX_PAGES for it. CONFIG_THP_SWAP needs to split one THP into normal pages and adds them all to one bio. With multipage-bvec, it just takes one bvec to hold them all. Reviewed-by: Christoph Hellwig Signed-off-by: Ming Lei --- include/linux/bio.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index 7edad188568a..e5b975fa0558 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -34,15 +34,7 @@ #define BIO_BUG_ON #endif -#ifdef CONFIG_THP_SWAP -#if HPAGE_PMD_NR > 256 -#define BIO_MAX_PAGES HPAGE_PMD_NR -#else #define BIO_MAX_PAGES 256 -#endif -#else -#define BIO_MAX_PAGES 256 -#endif #define bio_prio(bio) (bio)->bi_ioprio #define bio_set_prio(bio, prio) ((bio)->bi_ioprio = prio) From patchwork Wed Nov 21 03:23:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5864716B1 for ; Wed, 21 Nov 2018 03:29:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40DA42B4D2 for ; Wed, 21 Nov 2018 03:29:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3484B2B4A0; Wed, 21 Nov 2018 03:29:02 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4B8E2B4A2 for ; Wed, 21 Nov 2018 03:29:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 010B26B23B5; Tue, 20 Nov 2018 22:29:00 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F03536B23B7; Tue, 20 Nov 2018 22:28:59 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF3626B23B8; Tue, 20 Nov 2018 22:28:59 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id B491E6B23B5 for ; Tue, 20 Nov 2018 22:28:59 -0500 (EST) Received: by mail-qk1-f200.google.com with SMTP id h68so5547006qke.3 for ; Tue, 20 Nov 2018 19:28:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=TATK8tkd/TMB74rZQtUJZl4+I31LsZJ6ZI6wyMCyWVY=; b=p1gKrAto/hqAo/FZLeQVMpiyUW/JJZV5E4cIlhCcBpZKeH2QuKXC5bD7QrTd2bI5Lv hTiu3NtQC6qPsFzksbCAnSkalkscKYz3Knn3W1fKzM7wBdhTT1gyCA8r7zOiewdw3RBF kjtH7l1p5zZLKd8rxbWpYKJHO0iV0DchX/yGqCO40hgyYghG6N2pZ2/awJxpqJCezyOs PjCzdayOa/XRw5lbX0KCs5ygEIpNSa8zwgPqR1IyzgIZ6MPwGAqLcGjvUbHNoCbuqLF9 jP2uHZhN35Uhmmcgdh8iS5eUg6JI82bdTMOvri0Y5sQzxulbNZikxtA0jBlvzKNU2oNu fs6Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWbphRcu5ESvS2hfDLTB8CyDzRqMBmGUwldzIVzMnVWYx0Ws+y+r Oyj60aR0eSkF3i+BmDAaGRpiNcD9EJpFfE7WeBdsrZVH13Rz6vjE71/Bh99Lb9gUc6M9elIuVir kUZ3I13RPelh9H0oy+xDmFHcWyXZcxJ++SbGxQBEoE0IwQdnDOb7OrFwDCgJ2cY2WLQ== X-Received: by 2002:ac8:2276:: with SMTP id p51mr4464252qtp.200.1542770939509; Tue, 20 Nov 2018 19:28:59 -0800 (PST) X-Google-Smtp-Source: AJdET5e0CkAVuahKA1+nQ0QJyxY7jWqb/ImiO4Ikc2/br0WtkLSMJUn/lfYKDQlhp8UjJlafgA/O X-Received: by 2002:ac8:2276:: with SMTP id p51mr4464231qtp.200.1542770939006; Tue, 20 Nov 2018 19:28:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770938; cv=none; d=google.com; s=arc-20160816; b=VVDL4QIstfTSTZzlBlSQiv4K70TQVq5HH0OeSCxIcup9Ew+oiUdxaQq7BXnkgySIBK x0Vyrj3NgUMdMfvri5IS1wHDp/xKdlkCV3Hp4r7WiEJMC3xozc9b7jXAuSVgBk7Rngci 8kQpFdTzxPjOovLnxrpwbdK0wVn1+TfadNPlN2UQT3+QO9rttSo19sRWvhm/PU5Xil30 ulKSHSNsTCFcC2nd4owtWatIYTDU4S0ZJY3gNrt5UuO41sPwIWPlJ+ucjrG+QtlcVOlt husshUx69SjusvBPjO5PtRGgGPa2kRXNMF8g9ghfsfK9AdtPWvMz7q3kRZ12gKqNeYVG ZfpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=TATK8tkd/TMB74rZQtUJZl4+I31LsZJ6ZI6wyMCyWVY=; b=OpClw5FHkVbcfKXV7mMxL1kAU63VaEfRD4i+01qi3pYSHFr9ZZVm0kvg/yphTYDiBw I1dISuIWCnTewwgCkIsJvENgMkjjbdpIBlpR/rnCh2eV9ZOzlkUf0/nLhCp9R6xmoc6K Kazyaf4DBB91uwavgSU2EUOveIGfuHE3a2JM87Wk9NmrardRvabYilRaFaSRXPG8hFjs XYIRyj9a6+xdSsi0N9jjvE6Gm+Ap+uyD+Hw8PsLmpYQYy9WEnWXikzPmpX031Azu33yZ xW3Ffls4Do3DuS7rRH5c1vCrX2V0lDfd+MeYAikswZDB8uHnNbKqu+0vYuCfMt70uOWp +2HA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id z33si18511272qtz.6.2018.11.20.19.28.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:28:58 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13802356D3; Wed, 21 Nov 2018 03:28:58 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36DC810021B6; Wed, 21 Nov 2018 03:28:48 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 17/19] block: document usage of bio iterator helpers Date: Wed, 21 Nov 2018 11:23:25 +0800 Message-Id: <20181121032327.8434-18-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 21 Nov 2018 03:28:58 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Now multi-page bvec is supported, some helpers may return page by page, meantime some may return segment by segment, this patch documents the usage. Signed-off-by: Ming Lei --- Documentation/block/biovecs.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/block/biovecs.txt b/Documentation/block/biovecs.txt index 25689584e6e0..bb008f7afb05 100644 --- a/Documentation/block/biovecs.txt +++ b/Documentation/block/biovecs.txt @@ -117,3 +117,27 @@ Other implications: size limitations and the limitations of the underlying devices. Thus there's no need to define ->merge_bvec_fn() callbacks for individual block drivers. + +Usage of helpers: +================= + +* The following helpers whose names have the suffix of "_all" can only be used +on non-BIO_CLONED bio. They are usually used by filesystem code. Drivers +shouldn't use them because the bio may have been split before it reached the +driver. + + bio_for_each_segment_all() + bio_first_bvec_all() + bio_first_page_all() + bio_last_bvec_all() + +* The following helpers iterate over single-page bvecs. The passed 'struct +bio_vec' will contain a single-page IO vector during the iteration + + bio_for_each_segment() + bio_for_each_segment_all() + +* The following helpers iterate over single-page bvecs. The passed 'struct +bio_vec' will contain a single-page IO vector during the iteration + + bio_for_each_bvec() From patchwork Wed Nov 21 03:23:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D9CD813BB for ; Wed, 21 Nov 2018 03:29:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C83AB2B4D4 for ; Wed, 21 Nov 2018 03:29:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB6C32B4E7; Wed, 21 Nov 2018 03:29:16 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 342C32B4D4 for ; Wed, 21 Nov 2018 03:29:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F4426B23B9; Tue, 20 Nov 2018 22:29:15 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4A3CD6B23BA; Tue, 20 Nov 2018 22:29:15 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 398796B23BB; Tue, 20 Nov 2018 22:29:15 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 0FA306B23B9 for ; Tue, 20 Nov 2018 22:29:15 -0500 (EST) Received: by mail-qt1-f199.google.com with SMTP id t18so2197614qtj.3 for ; Tue, 20 Nov 2018 19:29:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=zWvzvwBbSvMg0u4AHk2nr86cwNuQZP/b35yIk2KGBEA=; b=QOQVCCDXKv/dU2+muJ02m2lXmK/rGixlAOfyD07mFwl6hcwa+gzZcsA52e0bcJdNMu hrm77XExqnRFwK3Vp+WMKWofQJaLfy5MGlVETrd+mXt1aPffsQfkAJAh/rnbN4bP6vzU Sy9Rt/BdGrCbeNPT5BxzHTUlNZbiGreoZpOgsVL94OXGfAS06D26tG3fKABOhdCZw6Qu 58hkI47hHjVleyMeo5DJ1xCe1cJLQWX067TVkExX7TEqxFEw0Prk8At15Rr1fRwRrSuK 5Enbqq8sy9DvJJ5v3mADD/dPizQR2WRsz71UE8R555mLstWgsNA9M5rJuXdUmKeF7sbC 8mAw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gIo4fl/KR2uUJ2NgmfciJa8xVGszhs030m5XskhW1Ygdamllx1R YzJF+JTAEmV83IVbhrTTGmXJoUokcBKPAcBMZaRZsGLCunCt4hicP1Ng4mJoG3eftyEdDjSiaT/ +OUubR4oKyjy/DUKF69J7cdn9QVx/u48zUWHNzu/Nk+K6niFjyyfiyh3eJN5oOJAFbw== X-Received: by 2002:ac8:41c8:: with SMTP id o8mr4400189qtm.232.1542770954803; Tue, 20 Nov 2018 19:29:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/UNOBDK5s5kpSiUiSmFiX4gorrZKFZOPPHQxxEOkdnN1NukPGKyJwnlEQSM5s0WvHoDgvpU X-Received: by 2002:ac8:41c8:: with SMTP id o8mr4400158qtm.232.1542770953603; Tue, 20 Nov 2018 19:29:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770953; cv=none; d=google.com; s=arc-20160816; b=vxuiHURYrh8Pk33T5o1Q8m/mJ2d4w9W2pfc26ZOj+ym+YTM2H9FmUxmU15jW3aolBb v5HOFpKmAg53BkCy4i+0W1nJZNaI87IJMvNTWyAesZmiNz12c2Wfl+fljsbuQpcWeTTM T9TEFX28uaho10BNDaEWmjddExu1yIrHyyEbpVygwDeEcs1KCQ8jL1WgzU/A2jj8K1iQ mzqf23ZF1pEza8/r/vT40Ciqp2LMN6U4dCGlLTPluhAfIcCjWhUNhO+DTMWGyTe2lZex yE8JBi505+mzuTLCshGbaZCM1OsgDgGafkFBN2A92MBRbFUxCxTYDPlqrS3PKhsqJztd dxqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=zWvzvwBbSvMg0u4AHk2nr86cwNuQZP/b35yIk2KGBEA=; b=lutegd5jPhtu6JT08Pq593lXVZdlGfWUC2Ml2VpyouNR7SgQftkCqKCmxBaX0KkrDH H7XVO/fKvrFjdn+Z+vFYjGHhWxcr+fX5BGtJ2i5Q0/xRcEzyapIAkXJlx/xvLV6SDv8V DY9IarBPWTffJAfohBFjrd6aW0nIsEe/D8d1vLNoX7MuRbkhlYvgvz+jCCfQFbQ/e1Oh pmezDfwGl6H1QjL/9kkwA4tPPCit2a7p3qBFtit31v/vhaVdng2goDcagcKvDImScHu/ UoC/ZuSK73COirfbpnM9yH4mz1sZ+x7GIBlZjZssqJ7di+RPqThEa4TwF/mKB7RggVdL EcHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id d16si21674224qtg.395.2018.11.20.19.29.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:29:13 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6FC1437E79; Wed, 21 Nov 2018 03:29:12 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C0BD17A6A; Wed, 21 Nov 2018 03:29:00 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 18/19] block: kill QUEUE_FLAG_NO_SG_MERGE Date: Wed, 21 Nov 2018 11:23:26 +0800 Message-Id: <20181121032327.8434-19-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 21 Nov 2018 03:29:12 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Since bdced438acd83ad83a6c ("block: setup bi_phys_segments after splitting"), physical segment number is mainly figured out in blk_queue_split() for fast path, and the flag of BIO_SEG_VALID is set there too. Now only blk_recount_segments() and blk_recalc_rq_segments() use this flag. Basically blk_recount_segments() is bypassed in fast path given BIO_SEG_VALID is set in blk_queue_split(). For another user of blk_recalc_rq_segments(): - run in partial completion branch of blk_update_request, which is an unusual case - run in blk_cloned_rq_check_limits(), still not a big problem if the flag is killed since dm-rq is the only user. Multi-page bvec is enabled now, not doing S/G merging is rather pointless with the current setup of the I/O path, as it isn't going to save you a significant amount of cycles. Reviewed-by: Christoph Hellwig Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- block/blk-merge.c | 31 ++++++------------------------- block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 3 --- drivers/md/dm-table.c | 13 ------------- include/linux/blkdev.h | 1 - 5 files changed, 6 insertions(+), 43 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 7c44216c1b58..8fcac7855a45 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -343,8 +343,7 @@ void blk_queue_split(struct request_queue *q, struct bio **bio) EXPORT_SYMBOL(blk_queue_split); static unsigned int __blk_recalc_rq_segments(struct request_queue *q, - struct bio *bio, - bool no_sg_merge) + struct bio *bio) { struct bio_vec bv, bvprv = { NULL }; int cluster, prev = 0; @@ -371,13 +370,6 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q, nr_phys_segs = 0; for_each_bio(bio) { bio_for_each_bvec(bv, bio, iter) { - /* - * If SG merging is disabled, each bio vector is - * a segment - */ - if (no_sg_merge) - goto new_segment; - if (prev && cluster) { if (seg_size + bv.bv_len > queue_max_segment_size(q)) @@ -412,27 +404,16 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q, void blk_recalc_rq_segments(struct request *rq) { - bool no_sg_merge = !!test_bit(QUEUE_FLAG_NO_SG_MERGE, - &rq->q->queue_flags); - - rq->nr_phys_segments = __blk_recalc_rq_segments(rq->q, rq->bio, - no_sg_merge); + rq->nr_phys_segments = __blk_recalc_rq_segments(rq->q, rq->bio); } void blk_recount_segments(struct request_queue *q, struct bio *bio) { - unsigned short seg_cnt = bio_segments(bio); - - if (test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags) && - (seg_cnt < queue_max_segments(q))) - bio->bi_phys_segments = seg_cnt; - else { - struct bio *nxt = bio->bi_next; + struct bio *nxt = bio->bi_next; - bio->bi_next = NULL; - bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio, false); - bio->bi_next = nxt; - } + bio->bi_next = NULL; + bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio); + bio->bi_next = nxt; bio_set_flag(bio, BIO_SEG_VALID); } diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index a32bb79d6c95..d752fe4461af 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -127,7 +127,6 @@ static const char *const blk_queue_flag_name[] = { QUEUE_FLAG_NAME(SAME_FORCE), QUEUE_FLAG_NAME(DEAD), QUEUE_FLAG_NAME(INIT_DONE), - QUEUE_FLAG_NAME(NO_SG_MERGE), QUEUE_FLAG_NAME(POLL), QUEUE_FLAG_NAME(WC), QUEUE_FLAG_NAME(FUA), diff --git a/block/blk-mq.c b/block/blk-mq.c index 32b246ed44c0..0375c3bd410e 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2755,9 +2755,6 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT; - if (!(set->flags & BLK_MQ_F_SG_MERGE)) - blk_queue_flag_set(QUEUE_FLAG_NO_SG_MERGE, q); - q->sg_reserved_size = INT_MAX; INIT_DELAYED_WORK(&q->requeue_work, blk_mq_requeue_work); diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 844f7d0f2ef8..a41832cf0c98 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1698,14 +1698,6 @@ static int device_is_not_random(struct dm_target *ti, struct dm_dev *dev, return q && !blk_queue_add_random(q); } -static int queue_supports_sg_merge(struct dm_target *ti, struct dm_dev *dev, - sector_t start, sector_t len, void *data) -{ - struct request_queue *q = bdev_get_queue(dev->bdev); - - return q && !test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags); -} - static bool dm_table_all_devices_attribute(struct dm_table *t, iterate_devices_callout_fn func) { @@ -1902,11 +1894,6 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, if (!dm_table_supports_write_zeroes(t)) q->limits.max_write_zeroes_sectors = 0; - if (dm_table_all_devices_attribute(t, queue_supports_sg_merge)) - blk_queue_flag_clear(QUEUE_FLAG_NO_SG_MERGE, q); - else - blk_queue_flag_set(QUEUE_FLAG_NO_SG_MERGE, q); - dm_table_verify_integrity(t); /* diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index a281b6737b61..8e05966ffe94 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -590,7 +590,6 @@ struct request_queue { #define QUEUE_FLAG_SAME_FORCE 15 /* force complete on same CPU */ #define QUEUE_FLAG_DEAD 16 /* queue tear-down finished */ #define QUEUE_FLAG_INIT_DONE 17 /* queue is initialized */ -#define QUEUE_FLAG_NO_SG_MERGE 18 /* don't attempt to merge SG segments*/ #define QUEUE_FLAG_POLL 19 /* IO polling enabled if set */ #define QUEUE_FLAG_WC 20 /* Write back caching */ #define QUEUE_FLAG_FUA 21 /* device supports FUA writes */ From patchwork Wed Nov 21 03:23:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D155F13BB for ; Wed, 21 Nov 2018 03:29:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE9CC2B4E7 for ; Wed, 21 Nov 2018 03:29:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2B742B4E1; Wed, 21 Nov 2018 03:29:31 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 249862B4D4 for ; Wed, 21 Nov 2018 03:29:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 393936B23BA; Tue, 20 Nov 2018 22:29:30 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 36C2D6B23BC; Tue, 20 Nov 2018 22:29:30 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 283436B23BD; Tue, 20 Nov 2018 22:29:30 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id F06196B23BA for ; Tue, 20 Nov 2018 22:29:29 -0500 (EST) Received: by mail-qk1-f198.google.com with SMTP id k203so5536876qke.2 for ; Tue, 20 Nov 2018 19:29:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=OBBzFrabGyHiHDXbPIAqLO3RzBiYfCeukciydJy6VMA=; b=bRlcM0ZrIwt5ZmHleuVSeKyAsziBjLpAmkcKb2jTM/6RGJQHiGtGA7E1fDh0qm8prF PZRdQi8YO4ecDNuDZeo1NjUVA//j55/scPzkQMKjO48osYsxHXgO9ZfvUixXWHfsbaC/ XDRAwjEWwz0cX7FuH3NhiqqqiaT1h309pvDNdDL2OCKcnFxasYVV1abme3MMLAmyPzI4 V1ADRi7eSzO+km/EH+LwFmk1cbLX5+RnZJq0Du7PgtgS9pJj4Hz1oPg1MIGT2owHkrsO 4WX2MbYQA4l/TWmPml+6KDZjGi2P6WOLZds6k/uTKCV0Ypj4fAHIBZMfcGZR6ssEzYju 9Drw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gLazIBCv6NflnZhu1ABCExAZkp+5FFraaji2l/9XcfGfV244vTf 6uPAOr5olDyTiKGJRV6o3apgmlAO0PSimT4yWalcY3nqkzv+CSmysfTAK0mbYARFmzjxjHpewTY cO3mlYNzc2Y2o4Ruy5psOPSh3byuh833bo7Xm77Iom+n74NYM4aM9uKf4yZCf4AC1dQ== X-Received: by 2002:ac8:4a8e:: with SMTP id l14mr4261861qtq.135.1542770969736; Tue, 20 Nov 2018 19:29:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/UZZoWuTC1GcVm0Teac7RZI9xZa19aQtCcaAa5L9rfuur19A7kAJ/1G3GP+2bKVbO9P95VL X-Received: by 2002:ac8:4a8e:: with SMTP id l14mr4261822qtq.135.1542770968390; Tue, 20 Nov 2018 19:29:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770968; cv=none; d=google.com; s=arc-20160816; b=zcdfdVC8sfTP5T4kvNVVhl2TfT4iw3qq9XggSFxMTWoMMvzHikc7L4C04HkO/XQ3WQ b0ZPXgKEOevBWM59EB1vrSOyh9R+FHJmsBReSmhdkdDD+eSayTUn4F5PM8OcLA+oHwRx s6+PMcYlOfQM25/5GK1Vo4oWghh5ZiVU4nTmJnbZzzFjkBeUfOw7K1AKz5GNpAI0Ddy9 BeCxsxRRuzfMJewhLQJGqEhoHAD6x6xgEZj7ptkW9DY6zvn0NbYFptj3C9DfANOZuiyo 7ZcsDbvKuqmUMaF0UCHyVInnWGlXc4+96KrXQ2jffih5ECb6wxdU9idw2rXzq6DychUd nJ7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=OBBzFrabGyHiHDXbPIAqLO3RzBiYfCeukciydJy6VMA=; b=dakDlV/J6wyBtWYrga/TDFarlcSM9HJVO4ulHh+8/KsMeTSzlYR/udhIoernKCjzM5 U2QpePqzXb34K0eoptsRWinaV1VAeIB2zMaCSK9Zqo62PGIbC2TQ6HKbIJljlqgxDdLC fVewUhP21TvtNL3xFDO49oY8jIXGE6JDb0JqjnJsB+Ejlj3Wp9Dc9Zv0yrwc30R2xRFi dOImLsLGPsR4pwIFedBvXi4Cr8L4D09Lqfl5+ioEneLw5S5vdNudw59GLCPXC9eTeJXq eo0d5180OEHqZrjV0TvAZqKOlHX90NvmJISude1d9sAhOPjOKg9R4793ip6M5+3+bVvd TzTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id s91si726982qtd.154.2018.11.20.19.29.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:29:28 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DD9A96DB; Wed, 21 Nov 2018 03:29:27 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F884600C3; Wed, 21 Nov 2018 03:29:14 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 19/19] block: kill BLK_MQ_F_SG_MERGE Date: Wed, 21 Nov 2018 11:23:27 +0800 Message-Id: <20181121032327.8434-20-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 21 Nov 2018 03:29:27 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP QUEUE_FLAG_NO_SG_MERGE has been killed, so kill BLK_MQ_F_SG_MERGE too. Reviewed-by: Christoph Hellwig Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- block/blk-mq-debugfs.c | 1 - drivers/block/loop.c | 2 +- drivers/block/nbd.c | 2 +- drivers/block/rbd.c | 2 +- drivers/block/skd_main.c | 1 - drivers/block/xen-blkfront.c | 2 +- drivers/md/dm-rq.c | 2 +- drivers/mmc/core/queue.c | 3 +-- drivers/scsi/scsi_lib.c | 2 +- include/linux/blk-mq.h | 1 - 10 files changed, 7 insertions(+), 11 deletions(-) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index d752fe4461af..a6ec055b54fa 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -249,7 +249,6 @@ static const char *const alloc_policy_name[] = { static const char *const hctx_flag_name[] = { HCTX_FLAG_NAME(SHOULD_MERGE), HCTX_FLAG_NAME(TAG_SHARED), - HCTX_FLAG_NAME(SG_MERGE), HCTX_FLAG_NAME(BLOCKING), HCTX_FLAG_NAME(NO_SCHED), }; diff --git a/drivers/block/loop.c b/drivers/block/loop.c index e3683211f12d..4cf5486689de 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1906,7 +1906,7 @@ static int loop_add(struct loop_device **l, int i) lo->tag_set.queue_depth = 128; lo->tag_set.numa_node = NUMA_NO_NODE; lo->tag_set.cmd_size = sizeof(struct loop_cmd); - lo->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE; + lo->tag_set.flags = BLK_MQ_F_SHOULD_MERGE; lo->tag_set.driver_data = lo; err = blk_mq_alloc_tag_set(&lo->tag_set); diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 08696f5f00bb..999c94de78e5 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1570,7 +1570,7 @@ static int nbd_dev_add(int index) nbd->tag_set.numa_node = NUMA_NO_NODE; nbd->tag_set.cmd_size = sizeof(struct nbd_cmd); nbd->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | - BLK_MQ_F_SG_MERGE | BLK_MQ_F_BLOCKING; + BLK_MQ_F_BLOCKING; nbd->tag_set.driver_data = nbd; err = blk_mq_alloc_tag_set(&nbd->tag_set); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 8e5140bbf241..3dfd300b5283 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -3988,7 +3988,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev) rbd_dev->tag_set.ops = &rbd_mq_ops; rbd_dev->tag_set.queue_depth = rbd_dev->opts->queue_depth; rbd_dev->tag_set.numa_node = NUMA_NO_NODE; - rbd_dev->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE; + rbd_dev->tag_set.flags = BLK_MQ_F_SHOULD_MERGE; rbd_dev->tag_set.nr_hw_queues = 1; rbd_dev->tag_set.cmd_size = sizeof(struct work_struct); diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c index a10d5736d8f7..a7040f9a1b1b 100644 --- a/drivers/block/skd_main.c +++ b/drivers/block/skd_main.c @@ -2843,7 +2843,6 @@ static int skd_cons_disk(struct skd_device *skdev) skdev->sgs_per_request * sizeof(struct scatterlist); skdev->tag_set.numa_node = NUMA_NO_NODE; skdev->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | - BLK_MQ_F_SG_MERGE | BLK_ALLOC_POLICY_TO_MQ_FLAG(BLK_TAG_ALLOC_FIFO); skdev->tag_set.driver_data = skdev; rc = blk_mq_alloc_tag_set(&skdev->tag_set); diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 0ed4b200fa58..d43a5677ccbc 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -977,7 +977,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size, } else info->tag_set.queue_depth = BLK_RING_SIZE(info); info->tag_set.numa_node = NUMA_NO_NODE; - info->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE; + info->tag_set.flags = BLK_MQ_F_SHOULD_MERGE; info->tag_set.cmd_size = sizeof(struct blkif_req); info->tag_set.driver_data = info; diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c index 1f1fe9a618ea..afbac62a02a2 100644 --- a/drivers/md/dm-rq.c +++ b/drivers/md/dm-rq.c @@ -536,7 +536,7 @@ int dm_mq_init_request_queue(struct mapped_device *md, struct dm_table *t) md->tag_set->ops = &dm_mq_ops; md->tag_set->queue_depth = dm_get_blk_mq_queue_depth(); md->tag_set->numa_node = md->numa_node_id; - md->tag_set->flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE; + md->tag_set->flags = BLK_MQ_F_SHOULD_MERGE; md->tag_set->nr_hw_queues = dm_get_blk_mq_nr_hw_queues(); md->tag_set->driver_data = md; diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c index 35cc138b096d..cc19e71c71d4 100644 --- a/drivers/mmc/core/queue.c +++ b/drivers/mmc/core/queue.c @@ -410,8 +410,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card) else mq->tag_set.queue_depth = MMC_QUEUE_DEPTH; mq->tag_set.numa_node = NUMA_NO_NODE; - mq->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE | - BLK_MQ_F_BLOCKING; + mq->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING; mq->tag_set.nr_hw_queues = 1; mq->tag_set.cmd_size = sizeof(struct mmc_queue_req); mq->tag_set.driver_data = mq; diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 0df15cb738d2..4091a67d23e5 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1890,7 +1890,7 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) shost->tag_set.queue_depth = shost->can_queue; shost->tag_set.cmd_size = cmd_size; shost->tag_set.numa_node = NUMA_NO_NODE; - shost->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE; + shost->tag_set.flags = BLK_MQ_F_SHOULD_MERGE; shost->tag_set.flags |= BLK_ALLOC_POLICY_TO_MQ_FLAG(shost->hostt->tag_alloc_policy); shost->tag_set.driver_data = shost; diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 929e8abc5535..ca7389d7e04f 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -211,7 +211,6 @@ struct blk_mq_ops { enum { BLK_MQ_F_SHOULD_MERGE = 1 << 0, BLK_MQ_F_TAG_SHARED = 1 << 1, - BLK_MQ_F_SG_MERGE = 1 << 2, BLK_MQ_F_BLOCKING = 1 << 5, BLK_MQ_F_NO_SCHED = 1 << 6, BLK_MQ_F_ALLOC_POLICY_START_BIT = 8,