From patchwork Mon Nov 26 02:17:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10697337 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 C7E1417FE for ; Mon, 26 Nov 2018 02:19:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B65F929A29 for ; Mon, 26 Nov 2018 02:19:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A941A29A2C; Mon, 26 Nov 2018 02:19:05 +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 3359F29A2A for ; Mon, 26 Nov 2018 02:19:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 503296B3F73; Sun, 25 Nov 2018 21:19:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4D8D36B3F74; Sun, 25 Nov 2018 21:19:04 -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 3A0EE6B3F75; Sun, 25 Nov 2018 21:19:04 -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 0DFC16B3F73 for ; Sun, 25 Nov 2018 21:19:04 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id z6so15255363qtj.21 for ; Sun, 25 Nov 2018 18:19:04 -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=lloQNHzy519wn2iu+Z2myWbbZPs4FDGIkPv0Pi+d1Ys=; b=lCV5GKFnUixDG22hRP91SB+xnqmX/yATbU+vLmQAgNlThZSFBSspuZksp9jXyMsBiA drQQBhqVQSxxliFUYZBoAQPkqyfkZ6R/bvOxzCmpNx36XdfF+sLUM/VLNqeeQp7vO5rL //fMJNwSZX5suaiLrOxIEe0nRux/COubZYJ/tJ8ArpxIMdUMRBU61FBqjulLlpMhh267 ZvTJF+4tRiurQoeEQ/nDWfjLwa80Dd3jS4pLLWev06flpDOC6Fs3kegrF4ACL0kCibAt Ww+CxNUzDyV6Mju+wWUo/jh+caqhxqoC39RMd4/rQvaW/Bh3Ro0cJDYtTFGWaQeXpH1q VU4Q== 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: AGRZ1gKBc9YPogXlnMueefpEdPPDX4aIcg3GIRuCfseYf6IlhQ4fOTEA +n/8if7tOFKyXl0Fk5YlaLJlogNyHOy7UzidK8hZ27ctkqbw4qmnjVhCKyWtUiXES2/bll76fuu tkyKXgG4qhMLgeR6JtuLdK6ZBgpbsVdM5uu4MNEgfGTMgi1fkx9hqP5IZamDL0+6tiw== X-Received: by 2002:aed:31c5:: with SMTP id 63mr23794122qth.385.1543198743813; Sun, 25 Nov 2018 18:19:03 -0800 (PST) X-Google-Smtp-Source: AJdET5ezlVBRusFfxFUK/KyMc52+1xwd4zybQP1XIZl+Zgq8ZMl8U5n6kc/ZUSuz8Hx1xUEQ2Gxs X-Received: by 2002:aed:31c5:: with SMTP id 63mr23794107qth.385.1543198743016; Sun, 25 Nov 2018 18:19:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543198742; cv=none; d=google.com; s=arc-20160816; b=v6tdvC48U2zvs37pExJd3QE9myKfvGghGNrEOm5cQzdT/jUjWilEcU3FOW5jKhd0PY fVW8995PTmcZN9GtHb5ioRuOJsp0D3n9p5jeW2ONRB1TzAqxAAW1ZqPcWuqSVJoLtK/X 0YkM8HTG6+SKPi8dWfn2D5XGaRVC/J61x/FXhIRExUZxuBuhwv2fZ/W4aLuQkPfZu4/h nQ5a3ZFFMnDpkL8zI0KGEUNn+fo6t+CCYvntk/gUM5DobOZA+xCP03R7EEwASrO4UrKz GvTG+YeSR4cwbZtUPbRo59XoWJhRpqaWPpNKcqAHshKZ9Z5B4KcM7Gmr4qGO1suf3bZ1 f+Ww== 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=lloQNHzy519wn2iu+Z2myWbbZPs4FDGIkPv0Pi+d1Ys=; b=UAMP9om3q0TdKgfoteP5H9ndygiqdMoOJIh5UefaiMFT+DM/TRzyXAM2MHUdF8vUgE fOIi2v/25487jfOdmL5oY3SbZnRlcgLp4zvF2JDWuYcbBfgR29HBuycrckl/M6BYcLHo Ibi6hW7G/qLKFyb9ZGaZKYfRJ2MUianXr4Lel4OlYpxw3M4n+v63qFJQgw4ycb4sC6U8 HbNKcOYrnVZr1kmbu9dJukj9wClkGzzh5cYL8oIul4SKOVCDqAFZ3CCUuUyENyil9RSe 9VLykodwdli9sCPlx0xBCWzJcNgeL+M2ZoK7j++YBWslfDHFr1c+Ahv4whS895RPnIRz p/fA== 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 j80si7842494qkh.96.2018.11.25.18.19.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Nov 2018 18:19:02 -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 D235A8535D; Mon, 26 Nov 2018 02:19:01 +0000 (UTC) Received: from localhost (ovpn-8-19.pek2.redhat.com [10.72.8.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AEF82D1E3; Mon, 26 Nov 2018 02:18:50 +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 V12 07/20] block: introduce multi-page bvec helpers Date: Mon, 26 Nov 2018 10:17:07 +0800 Message-Id: <20181126021720.19471-8-ming.lei@redhat.com> In-Reply-To: <20181126021720.19471-1-ming.lei@redhat.com> References: <20181126021720.19471-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.25]); Mon, 26 Nov 2018 02:19:02 +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 'bvec_iter_*' for multi-page 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 Reviewed-by: Christoph Hellwig --- include/linux/bvec.h | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 716a87b26a6a..babc6316c117 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,32 @@ struct bvec_iter { */ #define __bvec_iter_bvec(bvec, iter) (&(bvec)[(iter).bi_idx]) -#define segment_iter_page(bvec, iter) \ +/* multi-page (segment) helpers */ +#define bvec_iter_page(bvec, iter) \ (__bvec_iter_bvec((bvec), (iter))->bv_page) -#define segment_iter_len(bvec, iter) \ +#define bvec_iter_len(bvec, iter) \ min((iter).bi_size, \ __bvec_iter_bvec((bvec), (iter))->bv_len - (iter).bi_bvec_done) -#define segment_iter_offset(bvec, iter) \ +#define bvec_iter_offset(bvec, iter) \ (__bvec_iter_bvec((bvec), (iter))->bv_offset + (iter).bi_bvec_done) +#define bvec_iter_page_idx(bvec, iter) \ + (bvec_iter_offset((bvec), (iter)) / PAGE_SIZE) + +/* For building single-page bvec(segment) in flight */ + #define segment_iter_offset(bvec, iter) \ + (bvec_iter_offset((bvec), (iter)) % PAGE_SIZE) + +#define segment_iter_len(bvec, iter) \ + min_t(unsigned, bvec_iter_len((bvec), (iter)), \ + PAGE_SIZE - segment_iter_offset((bvec), (iter))) + +#define segment_iter_page(bvec, iter) \ + nth_page(bvec_iter_page((bvec), (iter)), \ + bvec_iter_page_idx((bvec), (iter))) + #define segment_iter_bvec(bvec, iter) \ ((struct bio_vec) { \ .bv_page = segment_iter_page((bvec), (iter)), \ @@ -67,8 +84,6 @@ struct bvec_iter { .bv_offset = segment_iter_offset((bvec), (iter)), \ }) -#define bvec_iter_len segment_iter_len - static inline bool bvec_iter_advance(const struct bio_vec *bv, struct bvec_iter *iter, unsigned bytes) {