From patchwork Thu Nov 15 08:52:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10683711 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 86ED914BA for ; Thu, 15 Nov 2018 08:53:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 789C128496 for ; Thu, 15 Nov 2018 08:53:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B35128505; Thu, 15 Nov 2018 08:53:53 +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 D597328496 for ; Thu, 15 Nov 2018 08:53:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 079996B026D; Thu, 15 Nov 2018 03:53:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 051356B026E; Thu, 15 Nov 2018 03:53:52 -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 EB4E06B026F; Thu, 15 Nov 2018 03:53:51 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id C2D386B026D for ; Thu, 15 Nov 2018 03:53:51 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id z126so43515600qka.10 for ; Thu, 15 Nov 2018 00:53:51 -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=boCV00+SsQK+T2rHZQwqNcLhuNoj2OH5hjO/svFBmcI=; b=Q1Ndl0wjSI7uulcQqSMgSy4+1uxpqiarbcWneJYZ8pIYLWshQV/QxiWocUnHiWEuQe njnhrVi4DXFgWqKsINcAHbKaa8Yj2c70TqGRdG1/dUo/CieLwvwkfYS3Pd87aiBvtQl3 pedWtqgi7neLQRuYbLfrf7Ri3tayOGFvPdFLQkMTTIHjDejA1ENDbphTDpH/9gt+zbNp f9+jrLw6VTp081B1XxHlOEq8b2R7hfrceOwmEoMoT/mS6WiDFitZCAWGcudbaGc9c7MJ uEc4vWTwSGsNX9JkbpJTwznivcKcnHULo6TUX34cF8HR4jQewdW1IAz8TPO6FKOkdixF uQSA== 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: AGRZ1gKVfmFyLUX83a3af8mg0He0mfLUT824uC2oudNqJJYe2zl18h1M M1QcucFZf7HhQGb2esAjzZfgPy3YkvaCuuJDwL5/qZ/H+mSiIsAUlq7CAStg9o6u1cFIKgXG5w4 Q6gNAT198/GCrnzdb4LMGgTEC1urXLYdkHwTftiVkbkDcyhci5BSNDgXOkI7eLWeRMQ== X-Received: by 2002:a0c:f9c3:: with SMTP id j3mr5432118qvo.107.1542272031559; Thu, 15 Nov 2018 00:53:51 -0800 (PST) X-Google-Smtp-Source: AJdET5f5arn828kzD5I3RZH4a/rMCsQkxL9OLLgVI5pa0ze1r6m9Cirz3oIfp1jL99taSJBTnme7 X-Received: by 2002:a0c:f9c3:: with SMTP id j3mr5432088qvo.107.1542272031022; Thu, 15 Nov 2018 00:53:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542272030; cv=none; d=google.com; s=arc-20160816; b=Qei18zPDUBWZS2GJRh0jQwtiBq5m75S35D2jTA9FOQD61WLbQyc8i7Jta2ZSlWNImv eWzaWPilHl7ujQ605bWAlvMPu3aVcsV32GxwA/C6vIy58NaRm4TQ6U5WWHQElbEfcP9A NpCY0M7xynNftfjgCGdz62DCM2GxtUzgN0BQuywAVM+gj8lY3bqBocjO1nWu/3/WJVd5 pPuBp8niJEkN+QL/dEG5/3RIZ9kGMtAnZ49aeeqNcj+TIKrT8z9Rt/HRZyHz4PdDY8EE ZZgOiayZKzU4FiLjGUpeNQJPZbLyr1dXUViXZEDgMt8McsZ3P0a00NC7vJmfsB1tG3dT 4rfQ== 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=boCV00+SsQK+T2rHZQwqNcLhuNoj2OH5hjO/svFBmcI=; b=V4H1Txz3wfa72lighS5Edfv22y/UuARHi2uHhlMimEQ2TJnQbeOGiWhsLIwk53y20b Wc5jPJBDYXCY6Qqd/K+Lxs8xB2z1UBoYV9nmYiIdTLe9tsHD0hgEOaiIQl8Lb9+JX5uD ziJnDsFNsj7bgcV5jT0RcCQSiODNDRn1WlW4OmmbwVlCYi2+va65xq3dSRNgv4ywFyKr UTvLg3w/ktGTFhePCcAfSy3cnWSBZyWO0qqi9t0mPPua5OnrkheGksVBhB5GErlyEg1k gFHtmr6QMBTOsiLJTfVdsOLU5he4+nH1FHdrZefSlS/WuiWljo//xQsKngmeCQj3WNkp hHjQ== 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 y65si14337989qtd.327.2018.11.15.00.53.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 00:53:50 -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-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C4F5307D992; Thu, 15 Nov 2018 08:53:49 +0000 (UTC) Received: from localhost (ovpn-8-23.pek2.redhat.com [10.72.8.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C21B15C220; Thu, 15 Nov 2018 08:53:36 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ming Lei , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, linux-erofs@lists.ozlabs.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , Theodore Ts'o , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com Subject: [PATCH V10 01/19] block: introduce multi-page page bvec helpers Date: Thu, 15 Nov 2018 16:52:48 +0800 Message-Id: <20181115085306.9910-2-ming.lei@redhat.com> In-Reply-To: <20181115085306.9910-1-ming.lei@redhat.com> References: <20181115085306.9910-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 15 Nov 2018 08:53:50 +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 'mp_bvec_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. Cc: Dave Chinner Cc: Kent Overstreet Cc: Mike Snitzer Cc: dm-devel@redhat.com Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: Shaohua Li Cc: linux-raid@vger.kernel.org Cc: linux-erofs@lists.ozlabs.org Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Cc: Darrick J. Wong Cc: linux-xfs@vger.kernel.org Cc: Gao Xiang Cc: Christoph Hellwig Cc: Theodore Ts'o Cc: linux-ext4@vger.kernel.org Cc: Coly Li Cc: linux-bcache@vger.kernel.org Cc: Boaz Harrosh Cc: Bob Peterson Cc: cluster-devel@redhat.com Signed-off-by: Ming Lei Reviewed-by: Omar Sandoval --- 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 02c73c6aa805..8ef904a50577 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -23,6 +23,44 @@ #include #include #include +#include + +/* + * What is multi-page bvecs? + * + * - bvecs stored in bio->bi_io_vec is always multi-page(mp) style + * + * - bvec(struct bio_vec) represents one physically contiguous I/O + * buffer, now the buffer may include more than one pages after + * multi-page(mp) bvec is supported, and all these pages represented + * by one bvec is physically contiguous. Before mp support, at most + * one page is included in one bvec, we call it single-page(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 single-page + * 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) single-page bvec is built in flight by bvec + * helpers from the stored multipage bvec + * + * - In case that some components(such as iov_iter) need to support + * multi-page 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 @@ -50,16 +88,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 single-page(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)), \