Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1977945imm; Sat, 9 Jun 2018 05:36:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIGTkS4oZgvuQJbTdCPd4GhjG6unvfLQ8unD4PUJufx2/w7mDtVXydqYO6TS4qv4u3D1XwM X-Received: by 2002:a62:aa18:: with SMTP id e24-v6mr10017366pff.72.1528547787291; Sat, 09 Jun 2018 05:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528547787; cv=none; d=google.com; s=arc-20160816; b=VRxQr5ql8EXLVc/4EZml7yKFzTN3peJPg7L9cxFS5o+XbelocR+1fpJOEa45eAn7e0 3Dimig7wcAj4U2uX73cJo2lrokWlazOwKp/8BOm7+cMhRess8ImEUUQG8CjXX4DWR8Gt JsvOwWSRllpnkwroJjp/NmO2CltT8R18m+6PPp9qq9HV4e1fiSbQq9fCNK5AY8tjEvKA 8iuIFjRBJ0Y74R1binegl32r5aVhLPLaEoBr1qiNEe2L1bFPIJtJKb5BRs9xcJrV+lAA v5JaNSE9q2eO0C4vT5OVthxe+H2skELyLaNqPQiWgX6zV+XH5mdKbZuoNDPvZsWn8BHv MFag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=9Ou5+cWWrQNbKp9I7UPiBKTMiT/odzml9PzB2awCeP0=; b=VR6XxnRE+HHEuLvaj5zGX7F0pes3J2ed41ERBKCZy4EpsoNfi5Fkb6LD5UjZdrhI0J PVLxh7lOROYM7SvIeyurUTFNlngrYgbUnyElzZdXu9qdU76GWpOw899YOKXn1nHf02Ft tbixRaMdE0ugdzDAblyA51kehK9vJVeOu6AbdcLMVWCPx/70pudp0cekmqE3KHUsPFXI WtdywJYIj1SyU9K1CcKcoyV1SAj0nTxhdd8bYPm+Wj4J/aQ5bmc4gIngqHq7K/Wx1Mqt 7P+d31ckljE3tLAQgnyngXBi3bhLwJ8swSEAIW9+9kskvqpCSnhyzJa0EZdG1D9WPLiw yqDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p18-v6si12099181pgu.671.2018.06.09.05.36.13; Sat, 09 Jun 2018 05:36:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753422AbeFIMeE (ORCPT + 99 others); Sat, 9 Jun 2018 08:34:04 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38312 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753248AbeFIMeB (ORCPT ); Sat, 9 Jun 2018 08:34:01 -0400 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:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.9.5