From patchwork Mon Aug 9 21:24:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12427293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 304F2C43214 for ; Mon, 9 Aug 2021 21:24:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1589160EB9 for ; Mon, 9 Aug 2021 21:24:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234687AbhHIVYf (ORCPT ); Mon, 9 Aug 2021 17:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236419AbhHIVYf (ORCPT ); Mon, 9 Aug 2021 17:24:35 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58DFEC0613D3 for ; Mon, 9 Aug 2021 14:24:12 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id a20so18107539plm.0 for ; Mon, 09 Aug 2021 14:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dyOLwIAyn5igot9fdJEMYSDMYL7Dq8yEvViQYaBuv5Q=; b=IgN38Ju83GTulvCvZYlk1tCmOLuq05ZnrXLyiM9cJpOx72VXo8vLggCiEjPzdjwgyD mMK7Lct7hKsJ/9DeBUZkREk9FHfFpCUr77ggNxRruqvvZ4qbGG6Bt5NbSI/8AvjN+lsD 7DlNNRZMiSIZboSKJdB46Lk6VuIvJ8D/yY1x6ajWlTDv1lyKY0e52sAZDh9GjmZn5d9X S2zhHWdkcPKHSIdk8OT/QtCUFD4xvU3VyyZhgnonWJv2jzZEX6KXZYTft+GnfFxn4mCi 2hIadd1fFXCXYRljE3GILzNYvjMtdV6g6PhSoJG9kDpUkJFogd08mLnucB5oubB0dmNE nG+g== 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:mime-version:content-transfer-encoding; bh=dyOLwIAyn5igot9fdJEMYSDMYL7Dq8yEvViQYaBuv5Q=; b=cuujV7fHHWYPf7Y5PZguUoBiIKdOromIpZhj3+fs3NNpTnVOtf4rgdfqyIyRMsLewR cbL75NkjhALeXweREfX9Ui9F2eQWL4571dJprofAT2GOvVOZGpKB5j03cwo6sgoNQ7fE lCRK8NC9nQuuA0KR0jdQXCxMO6zNARLd49CWJE15JOL2Pu7qF17zFSxKV7nx3OsbAVlJ E3vKqWct/cTInBD8yVJy0AIRosag32VihFV2QE/l+8w7gpwhz1Tw2c/6ILCuoRb7BDsL ssOIfh6t9ybUYu23vl5883MentkwkKY5NhqHzTWTudPSl5NAUw3KhsMl7S5NXDAGoXND uAbw== X-Gm-Message-State: AOAM531tXSKj7Zm+vjF0xnK2xAgPStnC5F1O111q3dyHAaFfEeGkFZj0 +TFUT1TcCRJQDFyoOj145jf+pzqDIuCsJ4dp X-Google-Smtp-Source: ABdhPJwsQKrvh7BBLMHgl6EZA+imD4LOvABq2HSlJV/q66inXi4kN9VHm6P7KHtJsfNePIQmLfyH3A== X-Received: by 2002:a17:90a:6541:: with SMTP id f1mr1114982pjs.184.1628544251710; Mon, 09 Aug 2021 14:24:11 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.61]) by smtp.gmail.com with ESMTPSA id m16sm439885pjz.30.2021.08.09.14.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 14:24:11 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 4/4] block: enable use of bio allocation cache Date: Mon, 9 Aug 2021 15:24:01 -0600 Message-Id: <20210809212401.19807-5-axboe@kernel.dk> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210809212401.19807-1-axboe@kernel.dk> References: <20210809212401.19807-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org If a kiocb is marked as being valid for bio caching, then use that to allocate a (and free) new bio if possible. Signed-off-by: Jens Axboe --- fs/block_dev.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 9ef4f1fc2cb0..36a3d53326c0 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -327,6 +327,14 @@ static int blkdev_iopoll(struct kiocb *kiocb, bool wait) return blk_poll(q, READ_ONCE(kiocb->ki_cookie), wait); } +static void dio_bio_put(struct blkdev_dio *dio) +{ + if (!dio->is_sync && (dio->iocb->ki_flags & IOCB_ALLOC_CACHE)) + bio_cache_put(&dio->bio); + else + bio_put(&dio->bio); +} + static void blkdev_bio_end_io(struct bio *bio) { struct blkdev_dio *dio = bio->bi_private; @@ -362,7 +370,7 @@ static void blkdev_bio_end_io(struct bio *bio) bio_check_pages_dirty(bio); } else { bio_release_pages(bio, false); - bio_put(bio); + dio_bio_put(dio); } } @@ -385,7 +393,14 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, (bdev_logical_block_size(bdev) - 1)) return -EINVAL; - bio = bio_alloc_bioset(GFP_KERNEL, nr_pages, &blkdev_dio_pool); + bio = NULL; + if (iocb->ki_flags & IOCB_ALLOC_CACHE) { + bio = bio_cache_get(GFP_KERNEL, nr_pages, &blkdev_dio_pool); + if (!bio) + iocb->ki_flags &= ~IOCB_ALLOC_CACHE; + } + if (!bio) + bio = bio_alloc_bioset(GFP_KERNEL, nr_pages, &blkdev_dio_pool); dio = container_of(bio, struct blkdev_dio, bio); dio->is_sync = is_sync = is_sync_kiocb(iocb); @@ -467,7 +482,14 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, } submit_bio(bio); - bio = bio_alloc(GFP_KERNEL, nr_pages); + bio = NULL; + if (iocb->ki_flags & IOCB_ALLOC_CACHE) { + bio = bio_cache_get(GFP_KERNEL, nr_pages, &fs_bio_set); + if (!bio) + iocb->ki_flags &= ~IOCB_ALLOC_CACHE; + } + if (!bio) + bio = bio_alloc(GFP_KERNEL, nr_pages); } if (!is_poll) @@ -492,7 +514,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, if (likely(!ret)) ret = dio->size; - bio_put(&dio->bio); + dio_bio_put(dio); return ret; }