From patchwork Wed Jun 27 12:45:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10491389 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 0ED9B602B3 for ; Wed, 27 Jun 2018 12:48:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F390C28D7A for ; Wed, 27 Jun 2018 12:48:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E82F428D85; Wed, 27 Jun 2018 12:48:01 +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 6322128D7A for ; Wed, 27 Jun 2018 12:48:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63DB26B027B; Wed, 27 Jun 2018 08:48:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5ED686B027C; Wed, 27 Jun 2018 08:48:00 -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 4DD016B027D; Wed, 27 Jun 2018 08:48:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 202726B027B for ; Wed, 27 Jun 2018 08:48:00 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id z26-v6so1769287qto.17 for ; Wed, 27 Jun 2018 05:48:00 -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=8R7mW+cUxt4gaDwsAEyMoQxj9qsXWbG5uLnlyc8xr50=; b=Y6z30aiozAb+gE2q+shI4O+6bVAB8gwVBLTB2SYKUBayCayzbWsH9LFPOYCRdG1kDZ 09gTQvFxILO2LPHf6Tv8IWt4sdhErNgSyrFNxYps2w8LKDOIZ3wvfFvIU/GRq46JJ+LX 9V+es5TcHQ6gmZRvp1tfgZjQcxTbniHTNT6xGRIJ1ICftK+vbOzFGFKof/+gQUW0qCyi IhtCleMybz7sDMBAeQ8lSOajkDqag9MvcZYqQHBX8+vT3+w4G3SeoSaXTSgoVVFU+vpe G835m/MwTcCLyjBvxU3e0MX+1ZK7x3eY+mrmJr68824+pM81pMdKJ6fYRLEleSnr4ChM rHFg== 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: APt69E392pzXYnhulMi3t+88wKq8yCn/W8F/mengE06uTutByf1FX3uN 206UlmODDliQ2pl+c5+ZVZLzToOuWFuOMjZD9B+SoLCEUuslhW9xXxnx4UiCLJPDSaugD1IayvK g7cyXjvjwfV5auPdMkghxfivHG4tlB+K4FSSJGTbcPDEkko+OW9d3DI493RC+8IHgAQ== X-Received: by 2002:a37:204c:: with SMTP id g73-v6mr5098767qkg.164.1530103679902; Wed, 27 Jun 2018 05:47:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeprdbMz+jJpyKUwQd+mDvAH4gMQMau75CsE5zbZ+TP2hzQi3Jdd9TBlWLgAlWNI5BsgY/P X-Received: by 2002:a37:204c:: with SMTP id g73-v6mr5098727qkg.164.1530103679066; Wed, 27 Jun 2018 05:47:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530103679; cv=none; d=google.com; s=arc-20160816; b=mC9+RKIBTfow/K8+P5pcQGHLjbrg8TfP6LRZ8oS/4LFF078vw2MGMBYWXG5iApaWMk D8zNybaYcoxFGyHfnssM2X1uiHmBOFm+EgHZGNCUuyL5qpZRNbQETpmPcCnp9tub18ue LoH0kfDQrWq42ghY6SQ7QQlzib7NMb/GS9pirJJIN/YmIWZ7PshAWaE1ArP9NW7H4W45 tSMGh0Ud6EI2Imz30qCdFYdoTvPP2fodxzkaplbx7/pRQjlee/B7pXj8HFgCEfCqcyQZ 18cT4x4XNteVv0hus1+hkkEi9d7JbPDm59bweLH5v4nlmJSqyfyb/UY/NLqJLKr9FqWW fXaQ== 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=8R7mW+cUxt4gaDwsAEyMoQxj9qsXWbG5uLnlyc8xr50=; b=CS+I0h3zdbhNagY+mwnd4K8mL2DSaiojNAWn/RglzSi76xQt2hGLA1In9UVzFvejeS SORVtShXXJD+mwOOGOBrO/zdJijNJSkxDBZBkDwjEcXXawXJBjlNxxuHomfYtOwCHzdn oBNw3sMg7O9Q8T7ObM7/P4xBMLHwNgI46flRZS5852hE9lzPdwnW9MWR5kUT7hJ+3pBT 5aCufEFAwfTpqo/mfLm4PJD6RmhD1UDwrc8Dn4OoJbp7icIcSh2TAmTlepwDA1YPOrQA BRaOLet0QrjHeWOQOMpecTHD4or6THQ3yj4hb8Ysb9ICxUa2yCUxHtOoscdydNiMlIj0 5Q4w== 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 p79-v6si4027763qkl.154.2018.06.27.05.47.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 05:47:59 -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-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:'' 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 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)), \