Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6310166imm; Wed, 27 Jun 2018 05:50:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcfrFikHZcH2QrNp6OG8/fbvq3dr4Q+aqDvS+a7YBP831vLZH5dNylihrgAwvWk0Tg/ve1S X-Received: by 2002:a62:9945:: with SMTP id d66-v6mr5733467pfe.192.1530103856543; Wed, 27 Jun 2018 05:50:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530103856; cv=none; d=google.com; s=arc-20160816; b=qCFxNb8ehBx7gf/JEtJSyaTJ5t6Fmsy3Nd0azx27YJgQbS9l1MsivDkiXo9zZHnt3r DsXmAWjeh7hUkXuwxpQ3m1Gi7XhUOZdoCGjDakYL/2X7Xc/KtSGGwa5/7pqbXst41DZd OjNp7PGQmN+zJSX/GCNYILhJ8QO4Y494MQHnUDEbK9WcwNXmlGlTxnzcW1pHTxB6Q0ie /+uU5zgAZ0daxhoO1mz0rXUWHGjEvw0RGuQOo+B9+mZXjTioZR8JbYms7ahRCrRHEbUH u5N3xvwFWNc3xsoo6IMl3jorBMXBlugWGDdEDgMiI92EoZFj7c52ht7tqnis2IwTSw6E v8nw== 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=8R7mW+cUxt4gaDwsAEyMoQxj9qsXWbG5uLnlyc8xr50=; b=fLPTx4UX0MFb0fVFfIon3/KQrD5rxyd0NVL5CYdxyF4XjAR93uqU0Z2EHPb62fLgcq 5DAXZJU6lvyw5K8HLgBxsHZl5zSB9gQfP6LrpuPS5BHk8qwGb5lwYcSupaDjcm9zVAV2 Dm1EmXM9A5lVlYlqwTaMTOGMnzyIqUSSvgXfY7gB1LtFT3USNy5vE8OkgrQKN2UmdfzB wHbj4GCSxuN/oxaUPTxwYrEdEV6349w2kXESVd19o8j7dK7ONrYr3f0O4qgABgdTxt7f w2uScIiU0hB4us6tQzMpVLH5rbf7Tq2g7ghcxNB49V2B/rOLgtEWhwClh8Vw53pkPSYY fFgw== 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 q4-v6si3894977plb.312.2018.06.27.05.50.42; Wed, 27 Jun 2018 05:50:56 -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 S965239AbeF0MsB (ORCPT + 99 others); Wed, 27 Jun 2018 08:48:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39332 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753325AbeF0Mr7 (ORCPT ); Wed, 27 Jun 2018 08:47:59 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E6D0401EF04; Wed, 27 Jun 2018 12:47:58 +0000 (UTC) Received: from localhost (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB0961C678; Wed, 27 Jun 2018 12:47:46 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Kent Overstreet Cc: David Sterba , Huang Ying , Mike Snitzer , 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 V7 10/24] block: introduce multipage page bvec helpers Date: Wed, 27 Jun 2018 20:45:34 +0800 Message-Id: <20180627124548.3456-11-ming.lei@redhat.com> In-Reply-To: <20180627124548.3456-1-ming.lei@redhat.com> References: <20180627124548.3456-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 27 Jun 2018 12:47:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 27 Jun 2018 12:47:58 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 helpers of 'mp_bvec_iter_*' for multipage bvec support. The introduced interfaces treate one bvec as real multipage segment, for example, .bv_len is the total length of the multipage bvec. The existed helpers of bvec_iter_* are interfaces for supporting current bvec iterator which is thought as singlepage only by drivers, fs, dm and etc. These introduced helpers will build singlepage bvec in flight, so users of current bio/bvec iterator still can work well and needn't any change even though we store real multipage io vector into bvec table. Signed-off-by: Ming Lei --- include/linux/bvec.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index fe7a22dd133b..03a12fbb90d8 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -23,6 +23,44 @@ #include #include #include +#include + +/* + * What is multipage bvecs? + * + * - bvec stored in bio->bi_io_vec is always multipage(mp) style + * + * - bvec(struct bio_vec) represents one physically contiguous I/O + * buffer, now the buffer may include more than one pages since + * multipage(mp) bvec is supported, and all these pages represented + * by one bvec is physically contiguous. Before mp support, at most + * one page can be included in one bvec, we call it singlepage(sp) + * bvec. + * + * - .bv_page of the bvec represents the 1st page in the mp bvec + * + * - .bv_offset of the bvec represents 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 bvec with single page + * + * - bio_for_each_segment*() will be changed to return singlepage + * bvec too + * + * - during iterating, iterator variable(struct bvec_iter) is always + * updated in multipage bvec style and that means bvec_iter_advance() + * is kept not changed + * + * - returned(copied) singlepage bvec is generated in flight by bvec + * helpers from the stored multipage bvec + * + * - In case that some components(such as iov_iter) need to support + * multipage bvec, we introduce new helpers(mp_bvec_iter_*) for + * them. + */ /* * was unsigned short, but we might as well be ready for > 64kB I/O pages @@ -52,16 +90,35 @@ struct bvec_iter { */ #define __bvec_iter_bvec(bvec, iter) (&(bvec)[(iter).bi_idx]) -#define bvec_iter_page(bvec, iter) \ +#define mp_bvec_iter_page(bvec, iter) \ (__bvec_iter_bvec((bvec), (iter))->bv_page) -#define bvec_iter_len(bvec, iter) \ +#define mp_bvec_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 mp_bvec_iter_offset(bvec, iter) \ (__bvec_iter_bvec((bvec), (iter))->bv_offset + (iter).bi_bvec_done) +#define mp_bvec_iter_page_idx(bvec, iter) \ + (mp_bvec_iter_offset((bvec), (iter)) / PAGE_SIZE) + +/* + * of singlepage(sp) segment. + * + * This helpers are for building sp bvec in flight. + */ +#define bvec_iter_offset(bvec, iter) \ + (mp_bvec_iter_offset((bvec), (iter)) % PAGE_SIZE) + +#define bvec_iter_len(bvec, iter) \ + min_t(unsigned, mp_bvec_iter_len((bvec), (iter)), \ + (PAGE_SIZE - (bvec_iter_offset((bvec), (iter))))) + +#define bvec_iter_page(bvec, iter) \ + nth_page(mp_bvec_iter_page((bvec), (iter)), \ + mp_bvec_iter_page_idx((bvec), (iter))) + #define bvec_iter_bvec(bvec, iter) \ ((struct bio_vec) { \ .bv_page = bvec_iter_page((bvec), (iter)), \ -- 2.9.5