From patchwork Sat Oct 29 08:08:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9403337 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 903F860587 for ; Sat, 29 Oct 2016 08:24:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C0902A13D for ; Sat, 29 Oct 2016 08:24:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FFEC2A5F2; Sat, 29 Oct 2016 08:24:00 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29BB62A13D for ; Sat, 29 Oct 2016 08:24:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034314AbcJ2IPC (ORCPT ); Sat, 29 Oct 2016 04:15:02 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36788 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751824AbcJ2IO4 (ORCPT ); Sat, 29 Oct 2016 04:14:56 -0400 Received: by mail-pf0-f194.google.com with SMTP id n85so3388963pfi.3; Sat, 29 Oct 2016 01:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BcydbFpFWitBk1FQrTT5c1aiEvJk6S9Ndq0YM5H+2qg=; b=EDZoC+9wgMFvT/GoPZPsy+5zGGkATc1HoHHWGqTvLmnrM/gOIkJtHojWfXuIoH7gn6 ZDH3bjCFFT3nClnCX4iI+wVnirsZN9hjQZgH8tU7GL9nv/9OG+8qQND10d9EK6YzPARM yPnwYCNFoDVWBAKe5DBtbZN9674sVNNvqW5fwumtYijVoNkKBLpz0ZNGotzf5rA8rP90 4Aqmrfg1YjePQBhuvCcbtTsUrYPB3i3o2jxFc7vvlCr0uomeI1AB+u/oKd7ae/oh3smX 5GjbNuWR046zbPSlDgn7IrypnSeJ3m3V6+LXuLUZxGtoCcYLgCMCyz54diLZHNAaEOgX Khsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BcydbFpFWitBk1FQrTT5c1aiEvJk6S9Ndq0YM5H+2qg=; b=MSMbe4M6tIVIGp9O566eA2VahIzFF91zJ4yJcWzFSlcD+sSYDwktKxuC3GcX3xaa08 OOLC3iuNJKUNpHGiGK6GdW8Tlr6siph7oMihw+Ev1fL0/j/F4ibWRXq0dXzQmRt+sjY9 BIv5vWSfok3wiU6TKB33HAmvxPVQBGeGPQkWAnhk4gIcTw3VzCEG4wydWOktoWWtRIaI /ijgBhtBkqAIsfjigI4kBO9kQoTyf4ko/nTGvytLvGrwT/mQgCvBburhcER1bY72SMiq 8q3E6LsVextHibgif4J64qlmquorZqiObuRkq7cDlSlqc4hjLKd9xtic/qv5dlAjObqK 9YUg== X-Gm-Message-State: ABUngvebnxW2E1+A4ch5DsTpe0fQec+eiJCOjzMu90dQoCSMMyBXh4r1dreW3JtEv2yi4w== X-Received: by 10.99.64.132 with SMTP id n126mr25923009pga.87.1477728895454; Sat, 29 Oct 2016 01:14:55 -0700 (PDT) Received: from localhost ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id w85sm11565282pfk.57.2016.10.29.01.14.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Oct 2016 01:14:54 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig , "Kirill A . Shutemov" , Ming Lei , Jens Axboe Subject: [PATCH 38/60] block: bounce: convert multipage bvecs into singlepage Date: Sat, 29 Oct 2016 16:08:37 +0800 Message-Id: <1477728600-12938-39-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477728600-12938-1-git-send-email-tom.leiming@gmail.com> References: <1477728600-12938-1-git-send-email-tom.leiming@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch trys to split the incoming multipage bvecs bio, so that the splitted bio can be held into one singlepage bvecs bio. Signed-off-by: Ming Lei --- block/bounce.c | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/block/bounce.c b/block/bounce.c index a42f7b98b7e6..da240d1de809 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -187,22 +187,38 @@ static void bounce_end_io_read_isa(struct bio *bio) __bounce_end_io_read(bio, isa_page_pool); } +static inline bool need_split(struct request_queue *q, struct bio *bio) +{ + return bio_sectors(bio) > BIO_SP_MAX_SECTORS; +} + +static inline bool need_bounce(struct request_queue *q, struct bio *bio) +{ + struct bvec_iter iter; + struct bio_vec bv; + + bio_for_each_segment_mp(bv, bio, iter) { + unsigned nr = (bv.bv_offset + bv.bv_len - 1) >> + PAGE_SHIFT; + + if (page_to_pfn(bv.bv_page) + nr > queue_bounce_pfn(q)) + return true; + } + return false; +} + static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, mempool_t *pool) { struct bio *bio; int rw = bio_data_dir(*bio_orig); - struct bio_vec *to, from; - struct bvec_iter iter; + struct bio_vec *to; unsigned i; - bio_for_each_segment(from, *bio_orig, iter) - if (page_to_pfn(from.bv_page) > queue_bounce_pfn(q)) - goto bounce; + if (!need_bounce(q, *bio_orig)) + return; - return; -bounce: - bio = bio_clone_bioset(*bio_orig, GFP_NOIO, fs_bio_set); + bio = bio_clone_bioset_sp(*bio_orig, GFP_NOIO, fs_bio_set); bio_for_each_segment_all(to, bio, i) { struct page *page = to->bv_page; @@ -267,9 +283,23 @@ void blk_queue_bounce(struct request_queue *q, struct bio **bio_orig) pool = isa_page_pool; } + if (!need_bounce(q, *bio_orig)) + return; + /* * slow path + * + * REQ_PC bio won't reach splitting because multipage bvecs + * isn't enabled for REQ_PC. */ + if (need_split(q, *bio_orig)) { + struct bio *split = bio_split(*bio_orig, + BIO_SP_MAX_SECTORS, + GFP_NOIO, q->bio_split); + bio_chain(split, *bio_orig); + generic_make_request(*bio_orig); + *bio_orig = split; + } __blk_queue_bounce(q, bio_orig, pool); }