From patchwork Fri Mar 15 14:59:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10854953 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 83EEB15AC for ; Fri, 15 Mar 2019 14:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71F9C2A9C8 for ; Fri, 15 Mar 2019 14:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6580F2AA9A; Fri, 15 Mar 2019 14:59:47 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 0F9552A9C8 for ; Fri, 15 Mar 2019 14:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729320AbfCOO7q (ORCPT ); Fri, 15 Mar 2019 10:59:46 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38836 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729318AbfCOO7p (ORCPT ); Fri, 15 Mar 2019 10:59:45 -0400 Received: by mail-pg1-f196.google.com with SMTP id v1so1941544pgi.5 for ; Fri, 15 Mar 2019 07:59:44 -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; bh=BPF7HYIndwYCravUgyQt5YZcBBFvcmqnVAdETebox5w=; b=WvisMBKbDsB+smLauX/MDEbJ1706Y11py46IH0eerWwAvAJ9bTtJ1oEdgPbWtGq7nu k/g8LcJ/CTUL7e1Rj3cfytt4llW3XQ1SME8m5rQD4ZR15RHrQ1pUlloJoO2NqBWp+2KE bYID6HOR1QW7sfq2WdPtDyWu8DxziePduW4buoGqSg4ep/uOXEREDkwsVgT3kgwVwkHF /p4oJoo2PjHsMqqQag3AvV7Bg/MFq4ztQ22xhMGs5zzLus1/hR9RwSQ7sQy1po4PeIFo JAkLH3/q9iAe95/Ma1cehtfMlDYysX4hZgQXLChGkfPvB3zBmyNXNnL/tzirIbQBATk6 U6hQ== 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=BPF7HYIndwYCravUgyQt5YZcBBFvcmqnVAdETebox5w=; b=lJN4W9JlfCGJnLX5c6Y3aQ5KLwydo0115czzITCVADDXaSt+98WAjsdEUPXfU+CYl6 lFAWuiQA7Cx3PWfujaE9E7DdbLQwaHFy3U33ozFbCU5mMFwZbPHdYziCQuZLy11FZB7H 8FJEzEWFT6gTxzZMbHjfyASLnj9/2y9odgVcP21cMVXoDZjbJwL1ONUz1x25Gk6qs29k 0qP4G5JV+fh72iXN6DyQgeiHnZvuRaSy2cjtLK0Onp7qx9yYjKZUWep6cORS06qx2dcI s/ICVAmwCKut3i1toR5SBmpr1M2p8jglfseUwIT9B7ytP49x+ErOnoDq6mN99EHWygzw KmyA== X-Gm-Message-State: APjAAAUY4bqW6YXCF6JAoQXnmtKX8iDEe/FFUh0IS0QQfX0tM2f74O0m 1t4x9FQBvk82oRtj3wcyd7HxhGIiz8qcZQ== X-Google-Smtp-Source: APXvYqxXg87XrVTeTdWlDT7n6CgdvY8C2ocObXBjDXmAHzsUahS75D6fLAfOEDtnRjyxH7JcKzK6sA== X-Received: by 2002:a62:3890:: with SMTP id f138mr4568373pfa.148.1552661984006; Fri, 15 Mar 2019 07:59:44 -0700 (PDT) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id f28sm4287179pfh.178.2019.03.15.07.59.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Mar 2019 07:59:43 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: viro@ZenIV.linux.org.uk, Jens Axboe Subject: [PATCH 1/3] iov_iter: add ITER_BVEC_FLAG_NO_REF flag Date: Fri, 15 Mar 2019 08:59:36 -0600 Message-Id: <20190315145938.21516-2-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190315145938.21516-1-axboe@kernel.dk> References: <20190315145938.21516-1-axboe@kernel.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For ITER_BVEC, if we're holding on to kernel pages, the caller doesn't need to grab a reference to the bvec pages, and drop that same reference on IO completion. This is essentially safe for any ITER_BVEC, but some use cases end up reusing pages and uncondtionally dropping a page reference on completion. And example of that is sendfile(2), that ends up being a splice_in + splice_out on the pipe pages. Add a flag that tells us it's fine to not grab a page reference to the bvec pages, since that caller knows not to drop a reference when it's done with the pages. Signed-off-by: Jens Axboe --- fs/io_uring.c | 3 +++ include/linux/uio.h | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 5be6e4f99a9e..f66a4a5daf35 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -862,6 +862,9 @@ static int io_import_fixed(struct io_ring_ctx *ctx, int rw, iov_iter_bvec(iter, rw, imu->bvec, imu->nr_bvecs, offset + len); if (offset) iov_iter_advance(iter, offset); + + /* don't drop a reference to these pages */ + iter->type |= ITER_BVEC_FLAG_NO_REF; return 0; } diff --git a/include/linux/uio.h b/include/linux/uio.h index ecf584f6b82d..4e926641fa80 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -23,14 +23,23 @@ struct kvec { }; enum iter_type { - ITER_IOVEC = 0, - ITER_KVEC = 2, - ITER_BVEC = 4, - ITER_PIPE = 8, - ITER_DISCARD = 16, + /* set if ITER_BVEC doesn't hold a bv_page ref */ + ITER_BVEC_FLAG_NO_REF = 2, + + /* iter types */ + ITER_IOVEC = 4, + ITER_KVEC = 8, + ITER_BVEC = 16, + ITER_PIPE = 32, + ITER_DISCARD = 64, }; struct iov_iter { + /* + * Bit 0 is the read/write bit, set if we're writing. + * Bit 1 is the BVEC_FLAG_NO_REF bit, set if type is a bvec and + * the caller isn't expecting to drop a page reference when done. + */ unsigned int type; size_t iov_offset; size_t count; @@ -84,6 +93,11 @@ static inline unsigned char iov_iter_rw(const struct iov_iter *i) return i->type & (READ | WRITE); } +static inline bool iov_iter_bvec_no_ref(const struct iov_iter *i) +{ + return (i->type & ITER_BVEC_FLAG_NO_REF) != 0; +} + /* * Total number of bytes covered by an iovec. * From patchwork Fri Mar 15 14:59:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10854959 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 4F43B1515 for ; Fri, 15 Mar 2019 14:59:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DCB62A9CF for ; Fri, 15 Mar 2019 14:59:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3239B2AA8F; Fri, 15 Mar 2019 14:59:49 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 A9ADE2A9CF for ; Fri, 15 Mar 2019 14:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729323AbfCOO7r (ORCPT ); Fri, 15 Mar 2019 10:59:47 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34411 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729318AbfCOO7r (ORCPT ); Fri, 15 Mar 2019 10:59:47 -0400 Received: by mail-pf1-f193.google.com with SMTP id v64so6541802pfb.1 for ; Fri, 15 Mar 2019 07:59:46 -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; bh=gN840LcjsGueYPKzT8V5G3GCmhFsVue5RDrc94TYwF8=; b=GADRatcyflI3JLA+fAlSFzNggKbxdEjh7utJpMSLA/UZhm3FxdWo2UuQf/awWMsYDg GpKT0j8MX6uEJtIBQ3I0KQXOxSe+tEMHZoygrCeNCyCutItiCFrziFws1WLh+lMb6s9C YTcmNb4M2+jtqXKJWdEArNtxyfp+xfSp1MTlc+FRn29ErpIqBWvL2MrwhRxLgsreeUBT p84ULoh8UpycuEvfxFxP9/0AUt7oZTSwEsuEPqiSLCV+22j6eNTDUa6fGPe/ZA4HwEW8 PO4yOcIWDR/zBzfYW+z6pG1vQtZx+V+CPu0AtuSUPbCRPbgUXkB/0mFBYVCUF1HIWbIc nRgg== 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=gN840LcjsGueYPKzT8V5G3GCmhFsVue5RDrc94TYwF8=; b=DCBdJZJ2xSZVX9MTj+YDJkhMwpm5sJbS0IPntGHlXi7tXlTLrXTKeikeBQGx8UNsEm IwlVLIStL5n2YZMFqenz0SOdlBbiQgU94rjQVNPnCHg98SjAPBr3uMJ9Kss/DRK3q5lZ 2wJC+sR1keN6GYDCBaRqtB2Z5KiN9CihBi372JgWCh5Esq4u9q0HuaGeIrJM15jm3JD1 xgDJsuN9OzuLJ0gtwhGa+z+gGqqUoZ3EAcINUocUkTv1W0C+1oAIKHzVRl4fYayjYmTT bmTpoXJj9ckaTaRmy8XYI8J4dLJ3qLvgKWmE4VVZsmnIldlOIWYkkFRJTD7nwBbwWZDL fTbA== X-Gm-Message-State: APjAAAUbJOvPXGsaoXbYKdaKPTrO8j9K/WYxQ1yP3e6z5fLx6bcCodyO H1evzFNBc8X68Sb0rdN9E9LUVAbzpkXa6g== X-Google-Smtp-Source: APXvYqwwFlggkhwQah0MuKz/v8ZXkkmsqeEzwefABNWSBEsKD8LlreAv6Ae+uUFW93atDghsfGntAA== X-Received: by 2002:a63:f853:: with SMTP id v19mr3873502pgj.391.1552661985887; Fri, 15 Mar 2019 07:59:45 -0700 (PDT) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id f28sm4287179pfh.178.2019.03.15.07.59.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Mar 2019 07:59:44 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: viro@ZenIV.linux.org.uk, Jens Axboe Subject: [PATCH 2/3] block: add BIO_NO_PAGE_REF flag Date: Fri, 15 Mar 2019 08:59:37 -0600 Message-Id: <20190315145938.21516-3-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190315145938.21516-1-axboe@kernel.dk> References: <20190315145938.21516-1-axboe@kernel.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If bio_iov_iter_get_pages() is called on an iov_iter that is flagged with NO_REF, then we don't need to add a page reference for the pages that we add. Add BIO_NO_PAGE_REF to track this in the bio, so IO completion knows not to drop a reference to these pages. Signed-off-by: Jens Axboe --- block/bio.c | 43 ++++++++++++++++++++++----------------- fs/block_dev.c | 12 ++++++----- fs/iomap.c | 12 ++++++----- include/linux/blk_types.h | 1 + 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/block/bio.c b/block/bio.c index 71a78d9fb8b7..b64cedc7f87c 100644 --- a/block/bio.c +++ b/block/bio.c @@ -849,20 +849,14 @@ static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter) size = bio_add_page(bio, bv->bv_page, len, bv->bv_offset + iter->iov_offset); if (size == len) { - struct page *page; - int i; + if (!bio_flagged(bio, BIO_NO_PAGE_REF)) { + struct page *page; + int i; + + mp_bvec_for_each_page(page, bv, i) + get_page(page); + } - /* - * For the normal O_DIRECT case, we could skip grabbing this - * reference and then not have to put them again when IO - * completes. But this breaks some in-kernel users, like - * splicing to/from a loop device, where we release the pipe - * pages unconditionally. If we can fix that case, we can - * get rid of the get here and the need to call - * bio_release_pages() at IO completion time. - */ - mp_bvec_for_each_page(page, bv, i) - get_page(page); iov_iter_advance(iter, size); return 0; } @@ -925,10 +919,12 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) * This takes either an iterator pointing to user memory, or one pointing to * kernel pages (BVEC iterator). If we're adding user pages, we pin them and * map them into the kernel. On IO completion, the caller should put those - * pages. For now, when adding kernel pages, we still grab a reference to the - * page. This isn't strictly needed for the common case, but some call paths - * end up releasing pages from eg a pipe and we can't easily control these. - * See comment in __bio_iov_bvec_add_pages(). + * pages. If we're adding kernel pages, and the caller told us it's safe to + * do so, we just have to add the pages to the bio directly. We don't grab an + * extra reference to those pages (the user should already have that), and we + * don't put the page on IO completion. The caller needs to check if the bio is + * flagged BIO_NO_PAGE_REF on IO completion. If it isn't, then pages should be + * released. * * The function tries, but does not guarantee, to pin as many pages as * fit into the bio, or are requested in *iter, whatever is smaller. If @@ -940,6 +936,13 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) const bool is_bvec = iov_iter_is_bvec(iter); unsigned short orig_vcnt = bio->bi_vcnt; + /* + * If this is a BVEC iter, then the pages are kernel pages. Don't + * release them on IO completion, if the caller asked us to. + */ + if (is_bvec && iov_iter_bvec_no_ref(iter)) + bio_set_flag(bio, BIO_NO_PAGE_REF); + do { int ret; @@ -1696,7 +1699,8 @@ static void bio_dirty_fn(struct work_struct *work) next = bio->bi_private; bio_set_pages_dirty(bio); - bio_release_pages(bio); + if (!bio_flagged(bio, BIO_NO_PAGE_REF)) + bio_release_pages(bio); bio_put(bio); } } @@ -1713,7 +1717,8 @@ void bio_check_pages_dirty(struct bio *bio) goto defer; } - bio_release_pages(bio); + if (!bio_flagged(bio, BIO_NO_PAGE_REF)) + bio_release_pages(bio); bio_put(bio); return; defer: diff --git a/fs/block_dev.c b/fs/block_dev.c index e9faa52bb489..78d3257435c0 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -336,12 +336,14 @@ static void blkdev_bio_end_io(struct bio *bio) if (should_dirty) { bio_check_pages_dirty(bio); } else { - struct bio_vec *bvec; - int i; - struct bvec_iter_all iter_all; + if (!bio_flagged(bio, BIO_NO_PAGE_REF)) { + struct bvec_iter_all iter_all; + struct bio_vec *bvec; + int i; - bio_for_each_segment_all(bvec, bio, i, iter_all) - put_page(bvec->bv_page); + bio_for_each_segment_all(bvec, bio, i, iter_all) + put_page(bvec->bv_page); + } bio_put(bio); } } diff --git a/fs/iomap.c b/fs/iomap.c index 97cb9d486a7d..abdd18e404f8 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -1589,12 +1589,14 @@ static void iomap_dio_bio_end_io(struct bio *bio) if (should_dirty) { bio_check_pages_dirty(bio); } else { - struct bio_vec *bvec; - int i; - struct bvec_iter_all iter_all; + if (!bio_flagged(bio, BIO_NO_PAGE_REF)) { + struct bvec_iter_all iter_all; + struct bio_vec *bvec; + int i; - bio_for_each_segment_all(bvec, bio, i, iter_all) - put_page(bvec->bv_page); + bio_for_each_segment_all(bvec, bio, i, iter_all) + put_page(bvec->bv_page); + } bio_put(bio); } } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index d66bf5f32610..791fee35df88 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -215,6 +215,7 @@ struct bio { /* * bio flags */ +#define BIO_NO_PAGE_REF 0 /* don't put release vec pages */ #define BIO_SEG_VALID 1 /* bi_phys_segments valid */ #define BIO_CLONED 2 /* doesn't own data */ #define BIO_BOUNCED 3 /* bio is a bounce bio */ From patchwork Fri Mar 15 14:59:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10854963 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 5B91F6C2 for ; Fri, 15 Mar 2019 14:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49FAA2A9CF for ; Fri, 15 Mar 2019 14:59:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E3302AA8F; Fri, 15 Mar 2019 14:59:50 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E8F4E2A9CF for ; Fri, 15 Mar 2019 14:59:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729325AbfCOO7t (ORCPT ); Fri, 15 Mar 2019 10:59:49 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33835 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729318AbfCOO7t (ORCPT ); Fri, 15 Mar 2019 10:59:49 -0400 Received: by mail-pg1-f194.google.com with SMTP id v12so6683687pgq.1 for ; Fri, 15 Mar 2019 07:59:48 -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; bh=iP0RIMIP0Dhv0Z3VwimEl1gZSo5mPCskMpjat/g+ZWI=; b=Q5B2XIA3o13t9GSzsQbK8sE651mnRmz0FDF04NOuh0sqpEH7gMaXegRLvfuDuulYDe mRKiRP+DEBaYzjjo3wArP3GZQ0bGCEuFChN4YEKgJQaU1WtFM2SQkJynmQWYD3Fzj8I8 gwR6ExlEVWAjvCmWBt6xDVHQtSA4SPYp6cunpok9yTdip8WhdAeB2W8PtyQc4BdZp3vC Inyun33YXY3iAbaem/JIHpqcLxekLGghmMYaADq2JV7EvZHhFXkUTOctlbbZ2tEwk6x3 GEj/h/Riz26DKvA30dmbr5VecNcorRCqqfYT69XsKkbPLidrw1uGLoHXdqRy71um9+BX ES3w== 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=iP0RIMIP0Dhv0Z3VwimEl1gZSo5mPCskMpjat/g+ZWI=; b=a5cuwiiS17ddfiCeqb+tSjzSJ+w2GU70AVI439vyyKrbmKMn8J8pWk8J/H151yRfIx e8CixEaZ0MbOss4yyz168QZwGWs9pPiJbsML05plEaGOHB8vj0INcOL7oZiqbLVnyOS4 iDw8k0jCdt1UzDeR86pv2yVvxb3FSXdfHGe0J8r6bRNl773pJ/WIjQf4Runj0mlKJxh/ JGQBEPiC5aBSGlrKnO0ERyxjAfJ3EnDdBR/HIkMJcsZcHOGiebEZnmgPIMCCtZuFJ/4/ zT7M5VUhwi3sj2GUMh5QHeE+S4FQ03Q4jO8en3OG4P9KXreW9PI44Dnvnj22jxNxDY6j 1wvQ== X-Gm-Message-State: APjAAAVLvuajTrS5Jd2e9YPB1fuMBJ6YCzvNkB+WYTEboCBA33erI/kV ly1YNTNMtXEN8aJ+KBFYa0OYhMnIpKN4dg== X-Google-Smtp-Source: APXvYqys/fbXqgURwR1PbWrDiThPOX1HA8pdaQ59Q3iqAm147y+KQTuhOCcF7kRmF6ppefgBEartMw== X-Received: by 2002:a62:1d8c:: with SMTP id d134mr4453958pfd.185.1552661987812; Fri, 15 Mar 2019 07:59:47 -0700 (PDT) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id f28sm4287179pfh.178.2019.03.15.07.59.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Mar 2019 07:59:46 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: viro@ZenIV.linux.org.uk, Jens Axboe Subject: [PATCH 3/3] io_uring: add io_uring_event cache hit information Date: Fri, 15 Mar 2019 08:59:38 -0600 Message-Id: <20190315145938.21516-4-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190315145938.21516-1-axboe@kernel.dk> References: <20190315145938.21516-1-axboe@kernel.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add hint on whether a read was served out of the page cache, or if it hit media. This is useful for buffered async IO, O_DIRECT reads would never have this set (for obvious reasons). If the read hit page cache, cqe->flags will have IOCQE_FLAG_CACHEHIT set. Signed-off-by: Jens Axboe --- fs/io_uring.c | 6 +++++- include/uapi/linux/io_uring.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index f66a4a5daf35..513df722702e 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -635,10 +635,14 @@ static void kiocb_end_write(struct kiocb *kiocb) static void io_complete_rw(struct kiocb *kiocb, long res, long res2) { struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw); + unsigned ev_flags = 0; kiocb_end_write(kiocb); - io_cqring_add_event(req->ctx, req->user_data, res, 0); + if (res > 0 && (req->flags & REQ_F_FORCE_NONBLOCK)) + ev_flags = IOCQE_FLAG_CACHEHIT; + + io_cqring_add_event(req->ctx, req->user_data, res, ev_flags); io_put_req(req); } diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index e23408692118..24906e99fdc7 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -69,6 +69,11 @@ struct io_uring_cqe { __u32 flags; }; +/* + * io_uring_event->flags + */ +#define IOCQE_FLAG_CACHEHIT (1U << 0) /* IO did not hit media */ + /* * Magic offsets for the application to mmap the data it needs */