From patchwork Tue Dec 27 15:56:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9489421 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 E50C762AB0 for ; Tue, 27 Dec 2016 16:02:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D798A201BC for ; Tue, 27 Dec 2016 16:02:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCABE25D99; Tue, 27 Dec 2016 16:02:21 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 856032094F for ; Tue, 27 Dec 2016 16:02:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755838AbcL0QBl (ORCPT ); Tue, 27 Dec 2016 11:01:41 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34668 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755686AbcL0QB3 (ORCPT ); Tue, 27 Dec 2016 11:01:29 -0500 Received: by mail-pg0-f68.google.com with SMTP id b1so12793481pgc.1; Tue, 27 Dec 2016 08:00:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oxLPbIJmBEEcUR4RDio6043pIvKeWfivgKdu4z6NTfc=; b=Y9LsPaSsA43aj2v3vUEGLJqS2ga9rORt1pba0/QkX4yUGhphIaF4lw6yJPtnjEiG8t g86Jl5+jE7h8NlQ1XOKPU5ipuHfjXoj1l/LMoh8If4s9gCqjpdqrbtb7noMhT2K9JoUn hBK+KkY+JjgZvLESprcqx1gluMoYdEtdrrGu06XYxK3Ztf5HN+5quLw86TgHa6Vvl9e+ QYsJB98Rj3HshQGKN4NY8z4BHMbhZxM2dBCAwuarMZOvSAw4xlbnrHON+UM4QjJMfCjb UQ8gyoNtEWWqDf3i80HrwBbydIPO9VoygxTc2jP+DGZ4awG5prEhZoXP4HMpqmrzkld8 Z6Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oxLPbIJmBEEcUR4RDio6043pIvKeWfivgKdu4z6NTfc=; b=Z0Od2ylI3KRTpGFUjQH1x3/6Sli5meBr0HUCuncEKn5UYxsGx1ATuP1m+p4GHOXLdn uyvEo1tjgjwd5eAeHvYEn0lVgh5yHLivxPPbhLL3ZfAuRAVGuGtr7v3q38AVnogWdWuP epyRlbLcWnjM9bn3jbDrDW+IEwGHoCLM5gNsFyQlApFEDCcL9oI4109IsRsiEME4XAM7 XrdRnl3goMS8sYV1xGyhh4m6gNYhcluB87PX0C4wndY3ph85aadXw1dMrYVXoCThsAu0 5eq3qhkVgfael7hsIHLnu1Nn5DtLeu/l+otGQKHBoswOlqpBbBeFqttdufBBZdbDN6mK cviA== X-Gm-Message-State: AIkVDXIv2QEKO9HuIQiU5+6830bhriyAi9YYTM5HrIXrBswfVxZU1Y4fJ+uY12xkWt8uoA== X-Received: by 10.98.156.17 with SMTP id f17mr30112038pfe.63.1482854456315; Tue, 27 Dec 2016 08:00:56 -0800 (PST) Received: from localhost ([45.35.47.137]) by smtp.gmail.com with ESMTPSA id m12sm42475908pfg.92.2016.12.27.08.00.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Dec 2016 08:00:54 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Ming Lei , Jens Axboe Subject: [PATCH v1 22/54] block: bounce: convert multipage bvecs into singlepage Date: Tue, 27 Dec 2016 23:56:11 +0800 Message-Id: <1482854250-13481-23-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482854250-13481-1-git-send-email-tom.leiming@gmail.com> References: <1482854250-13481-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 | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/block/bounce.c b/block/bounce.c index a42f7b98b7e6..08841ed4cdae 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -187,22 +187,33 @@ static void bounce_end_io_read_isa(struct bio *bio) __bounce_end_io_read(bio, isa_page_pool); } +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; @@ -246,6 +257,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, void blk_queue_bounce(struct request_queue *q, struct bio **bio_orig) { mempool_t *pool; + unsigned sectors; /* * Data-less bio, nothing to bounce @@ -267,9 +279,22 @@ 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 bvec + * isn't enabled for REQ_PC. */ + if (!bio_can_convert_to_sp(*bio_orig, §ors)) { + struct bio *split = bio_split(*bio_orig, 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); }