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)), \