From patchwork Sat Jun 9 12:30:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10455593 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CF18F601F7 for ; Sat, 9 Jun 2018 12:34:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C00151FF83 for ; Sat, 9 Jun 2018 12:34:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0C28223A6; Sat, 9 Jun 2018 12:34: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=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 4501E1FF83 for ; Sat, 9 Jun 2018 12:34:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 577566B0282; Sat, 9 Jun 2018 08:34:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 526E06B0284; Sat, 9 Jun 2018 08:34:02 -0400 (EDT) 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 417F76B0285; Sat, 9 Jun 2018 08:34:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f198.google.com (mail-qk0-f198.google.com [209.85.220.198]) by kanga.kvack.org (Postfix) with ESMTP id 132076B0282 for ; Sat, 9 Jun 2018 08:34:02 -0400 (EDT) Received: by mail-qk0-f198.google.com with SMTP id w203-v6so15154110qkb.16 for ; Sat, 09 Jun 2018 05:34:02 -0700 (PDT) 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=9Ou5+cWWrQNbKp9I7UPiBKTMiT/odzml9PzB2awCeP0=; b=dbGbogOBMOZ+1hdIZhEUWf1W7YJuokN4RZaCiVjuV1gLOhI3ew2eMMRLJwp1cI6ovJ vOkJyzQLoxXdUdcGQt+g6IfkXnmwhNSMBjOmLxPgvGqngVrCRrL1L79NqiHwBlTz0M2c 6r4JQ2t7/dNHKqZtQOMHmAwioQ+m49EuCa2ZxOepjLhe2CQY3p5XvFM8xPJEUtaredwH /PhfrwlrRW5ADdVZ3W4ys5g0HqVWV3xGWQKZnmXTJSk4PoZmt3q4uuO8GNxDcibmlghS aG4P/tXJR3KKvx7TYUPHlMbVS275diFsjaLQAZtmWFnNRRyMTepwcQClNga5WtAh/I4C 8WUA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 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: APt69E2OMg8NXdj8ISNVSp4yQJaVTLrG+GF0OXOE+It3ZlaoQz0KoOIu 7SoDfwfj65mdI2uIMWkHB5WFudJFi99lei4CJd06UDvHp9N2MAIzQ5dgvsTdokz/iE3P9Ff+fht 5MIqvMLUwbRHEBz2iKDSlpFrC0XeDMXwiCKSg/hny6dgDAIB1shDRlJ2q/8flwCA7IA== X-Received: by 2002:a37:4ac4:: with SMTP id x187-v6mr8647261qka.156.1528547641862; Sat, 09 Jun 2018 05:34:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLy+N0v6Xar/7kUGKElp8DcwG7qoAXzaO5M4imjhWJ0QvR+SaSBonvd9IZE7qpuptpBkJEx X-Received: by 2002:a37:4ac4:: with SMTP id x187-v6mr8647245qka.156.1528547641235; Sat, 09 Jun 2018 05:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528547641; cv=none; d=google.com; s=arc-20160816; b=UzZ60vRf0qBtzLNh4hlYenkDnwVs12rSNUA/Rm9b2b4s3XiiAOr35XOtKJkOQp1Qed BzH839PgVjkQuXOxSCyx5GcqopnH1SkLWbz56wIUb8kwkPx4HDGHqEq3hUUkqAyHp8mi XgMVvQEw7Eg/dGE4ivT9B/CORzgqUj2LmbyUoopqQYhaiKd8tNNqd4KquyJwm7quWhxF Q4APaVssFPYLwfcuU8d7B2QZZThAibAQeblQfiP6jNRBrZQmBFQnNHEI0BbTsmj+n6yl tEx2zyrfqh3RAo/mYk3vPFY/rxbt3p74bF81lXhdNEZR8VsJJtZ2FspO+G9L97QXIdun gVmw== 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 :arc-authentication-results; bh=9Ou5+cWWrQNbKp9I7UPiBKTMiT/odzml9PzB2awCeP0=; b=Hr8piLJkajbCuvO3EP0h1B6AE3GeR9AUhLupTgpZHdNMPmoNxwiMCBErtnH/mk8cGJ 1xC6sc6z0i3zY7OFWNjRMySrwOS59dhmih7x5fO4LXs8M4cUIQjnCOSCtPTiMQIH7bJh mVDSERtqBliIYWhW+4bTeHtSy8R7tpMp0Kr17dkfAO8vrvIckh4Xy/do+TnFJFVZYB9o DLwujdKTFET9URx1dU+9ObkyWPct3NYszM9r/CfcamLR9M/NyUR3f9XjiR7+Ov+QSrly ndulDtt+HD42FHG8Y0Mcy2ehK0U0jXaXn1Bwm2uomiVIrD8Zp7srmlC5ojzQX/2VL3gq CW8A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 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 (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id q37-v6si524541qtc.381.2018.06.09.05.34.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jun 2018 05:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 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.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0279818BAF3; Sat, 9 Jun 2018 12:34:00 +0000 (UTC) Received: from localhost (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C1641116709; Sat, 9 Jun 2018 12:33:51 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Alexander Viro , Kent Overstreet Cc: David Sterba , Huang Ying , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , "Darrick J . Wong" , Coly Li , Filipe Manana , Randy Dunlap , Ming Lei Subject: [PATCH V6 17/30] block: introduce bio_for_each_chunk_all and bio_for_each_chunk_segment_all Date: Sat, 9 Jun 2018 20:30:01 +0800 Message-Id: <20180609123014.8861-18-ming.lei@redhat.com> In-Reply-To: <20180609123014.8861-1-ming.lei@redhat.com> References: <20180609123014.8861-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 09 Jun 2018 12:34:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 09 Jun 2018 12:34:00 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' 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 bio_for_each_chunk_all() and bio_for_each_chunk_segment_all(), which are for replacing the current bio_for_each_segment_all(). bio_for_each_chunk_all() will iterate one chunk by chunk, which is multipage based. bio_for_each_chunk_segment_all() will iterate one segment by segment, which is singlepage based. For using bio_for_each_chunk_segment_all(), one 24-bytes extra local variable has to be introduced. Signed-off-by: Ming Lei --- include/linux/bio.h | 13 +++++++++++++ include/linux/bvec.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 0fa1035dde38..f21384be9b51 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -168,6 +168,19 @@ 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++) +#define bio_for_each_chunk_all(bvl, bio, i) \ + bio_for_each_segment_all(bvl, bio, i) + +#define chunk_for_each_segment(bv, bvl, i, citer) \ + for (bv = bvec_init_chunk_iter(&citer); \ + (citer.done < (bvl)->bv_len) && \ + ((chunk_next_segment((bvl), &citer)), 1); \ + citer.done += bv->bv_len, i += 1) + +#define bio_for_each_chunk_segment_all(bvl, bio, i, citer) \ + for (i = 0, citer.idx = 0; citer.idx < (bio)->bi_vcnt; citer.idx++) \ + chunk_for_each_segment(bvl, &((bio)->bi_io_vec[citer.idx]), i, citer) + static inline void __bio_advance_iter(struct bio *bio, struct bvec_iter *iter, unsigned bytes, bool chunk) { diff --git a/include/linux/bvec.h b/include/linux/bvec.h index aac75d87d884..d4eaa0c26bb5 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -84,6 +84,12 @@ struct bvec_iter { current bvec */ }; +struct bvec_chunk_iter { + 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 @@ -219,6 +225,31 @@ static inline bool bvec_iter_chunk_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +static inline struct bio_vec *bvec_init_chunk_iter(struct bvec_chunk_iter *citer) +{ + citer->bv.bv_page = NULL; + citer->done = 0; + + return &citer->bv; +} + +/* used for chunk_for_each_segment */ +static inline void chunk_next_segment(const struct bio_vec *chunk, + struct bvec_chunk_iter *iter) +{ + struct bio_vec *bv = &iter->bv; + + if (bv->bv_page) { + bv->bv_page += 1; + bv->bv_offset = 0; + } else { + bv->bv_page = chunk->bv_page; + bv->bv_offset = chunk->bv_offset; + } + bv->bv_len = min_t(unsigned int, PAGE_SIZE - bv->bv_offset, + chunk->bv_len - iter->done); +} + /* * Get the last singlepage segment from the multipage bvec and store it * in @seg