From patchwork Fri Jan 11 11:01:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10757683 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 4F4061515 for ; Fri, 11 Jan 2019 11:03:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4031129C3B for ; Fri, 11 Jan 2019 11:03:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3353B29C53; Fri, 11 Jan 2019 11:03:13 +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 AD6EA29C4D for ; Fri, 11 Jan 2019 11:03:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C28368E0007; Fri, 11 Jan 2019 06:03:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BD7078E0001; Fri, 11 Jan 2019 06:03:11 -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 AC61B8E0007; Fri, 11 Jan 2019 06:03:11 -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 847FB8E0001 for ; Fri, 11 Jan 2019 06:03:11 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id u32so16313724qte.1 for ; Fri, 11 Jan 2019 03:03:11 -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=G8vlK5fTgPdKG8GwH3WjVGRyxTzVLYwFzbdjiyTWY4A=; b=JHoojOMhq/OyzWetR1mJb4AsPXOQlVGBsO5fJfZqdbEj1Yx3V9T3UjMUcWhd3l2AJL QUh6qY7zqS8pzVpXh88JxgDfXuLo6l8Tc36QHfOt5dq3v7qW05B8PVCFSykPgBXk0paU Wj/jma8r5CLAhfk1kl910ZBwNaSFSIQ3ae3OOd6FV0PVY2HI6JNtIZgC2Z0E2OtzBmhz vJ4MKPjijmQonTrA92wbIc+K0tdXqp0Ixa/aYDQCTkBY8eh6/mkNs3Q6igJbSRpuyLUu XCwQ+3UC22uPextJ7oR1jkwgpaxeNQQ7ksxZuWs7sxRly/29QTOpeTgEoB+1e3FOM30h K9tw== 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: AJcUukeABkX9WSUfAqcq1biey4tdfdnX6JaKUo313SzaqGcjil6vgQoV 4EQwt/n5Wt01b8+skrh+5Abpl/E8gQPB0y7Vci+AH5b0TJGIuhKZ+Nm1KsHHuFhQd3LKtQ6JtA2 oD0ebsQhEYuiDeRqjFp9xZUFBXuzPyymd0T6P/3TUS7Ad6Mb93RnXvnBKBGMfG2e5XA== X-Received: by 2002:ac8:1a08:: with SMTP id v8mr12790649qtj.362.1547204591312; Fri, 11 Jan 2019 03:03:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN4BCTZBnnup2DhYwToUA1axIKJwy8MlkWbMY9JHGpGeypELcJGAegvnw2qQ4oRcVxD64uSI X-Received: by 2002:ac8:1a08:: with SMTP id v8mr12790617qtj.362.1547204590697; Fri, 11 Jan 2019 03:03:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547204590; cv=none; d=google.com; s=arc-20160816; b=NksN8AwkoFUlWEvroiM4EFa9O4JHbavroVMxcBkhYDYjNClhjqwC2K4TdDafLSrpIm 6wmHXj6iD7LnO09EPzyfudfmUKaZcCVGZ/oBj/KwkypJsaznIqNDVjTRFJrEFkOOtk0F +VSQFn3Hc9qSekGL1zI48SivzyeDLseg6kM7jjHY6nnoUvqovuwO01LmI4Ii/HU3Zj0D YUlNwjhNqLzRi+C5fjnWLlATUO5N399Y0/I/J4FEn86/3gTmGPP7YMeGIHrRKGJ5Xr0K FgrP8DOo4hFCWzPvooTC2lnQFJOZD8LhOBBO0CgCMVGnal7v1IavGvLr+47vW8nM9q/A aYAw== 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=G8vlK5fTgPdKG8GwH3WjVGRyxTzVLYwFzbdjiyTWY4A=; b=smDX7zr60aK7RU2hKb+rTZLsVjJsUtIKyzKUsHAp9CgecG1OGtESmmlR0zo1DJUBFj TAPHSzesc3LhV/jCBNLhkxC27zObYxMKj+3ZHnRtX+puSTAxKZk4uSEFz7zR/0ZxLIt+ oESOqPnbPZvkQJY2VKH94LkZFMH34dnTTPpl5CnHHEqiL3OXhBKsfkdMxtntgP0kAcpO SXAzQQNCutfrNVi9iaw93gb/sdIfoxDpwd0GzkNWMCojSwPMtjsyeR4U5kNlW7DP6eEa UtF5HIO+TB4UEkQqGAL3P6hP+fJP+scYPO3f3LPzFKgo1XUZ8lSAYdTebuItdNHj+tuW 0ckw== 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 z2si8779353qtf.343.2019.01.11.03.03.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 03:03:10 -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-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F9972D7E0; Fri, 11 Jan 2019 11:03:09 +0000 (UTC) Received: from localhost (ovpn-8-28.pek2.redhat.com [10.72.8.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E06717DFE; Fri, 11 Jan 2019 11:02:53 +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, 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 V13 05/19] block: introduce multi-page bvec helpers Date: Fri, 11 Jan 2019 19:01:13 +0800 Message-Id: <20190111110127.21664-6-ming.lei@redhat.com> In-Reply-To: <20190111110127.21664-1-ming.lei@redhat.com> References: <20190111110127.21664-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 11 Jan 2019 11:03:09 +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: Christoph Hellwig Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- 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) {