From: Christoph Hellwig <hch@infradead.org>
To: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>, Jens Axboe <axboe@kernel.dk>,
Jan Kara <jack@suse.cz>, Christoph Hellwig <hch@lst.de>,
Matthew Wilcox <willy@infradead.org>,
Logan Gunthorpe <logang@deltatee.com>,
linux-block@vger.kernel.org,
Christoph Hellwig <hch@infradead.org>,
Jeff Layton <jlayton@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 8/9] iov_iter, block: Make bio structs pin pages rather than ref'ing if appropriate
Date: Wed, 11 Jan 2023 23:44:33 -0800 [thread overview]
Message-ID: <Y7+6YVkhZsvdW+Hr@infradead.org> (raw)
In-Reply-To: <167344731521.2425628.5403113335062567245.stgit@warthog.procyon.org.uk>
On Wed, Jan 11, 2023 at 02:28:35PM +0000, David Howells wrote:
> [!] Note that this is tested a bit with ext4, but nothing else.
You probably want to also at least test it with block device I/O
as that is a slightly different I/O path from iomap. More file systems
also never hurt, but aren't quite as important.
> +/*
> + * Clean up a page appropriately, where the page may be pinned, may have a
> + * ref taken on it or neither.
> + */
> +static void bio_release_page(struct bio *bio, struct page *page)
> +{
> + if (bio_flagged(bio, BIO_PAGE_PINNED))
> + unpin_user_page(page);
> + if (bio_flagged(bio, BIO_PAGE_REFFED))
> + put_page(page);
> +}
> +
> void __bio_release_pages(struct bio *bio, bool mark_dirty)
> {
> struct bvec_iter_all iter_all;
> @@ -1183,7 +1197,7 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty)
> bio_for_each_segment_all(bvec, bio, iter_all) {
> if (mark_dirty && !PageCompound(bvec->bv_page))
> set_page_dirty_lock(bvec->bv_page);
> - put_page(bvec->bv_page);
> + bio_release_page(bio, bvec->bv_page);
So this does look correc an sensible, but given that the new pin/unpin
path has a significantly higher overhead I wonder if this might be a
good time to switch to folios here as soon as possible in a follow on
patch.
> + size = iov_iter_extract_pages(iter, &pages,
> + UINT_MAX - bio->bi_iter.bi_size,
> + nr_pages, gup_flags,
> + &offset, &cleanup_mode);
> if (unlikely(size <= 0))
> return size ? size : -EFAULT;
>
> + bio_clear_flag(bio, BIO_PAGE_REFFED);
> + bio_clear_flag(bio, BIO_PAGE_PINNED);
> + if (cleanup_mode & FOLL_GET)
> + bio_set_flag(bio, BIO_PAGE_REFFED);
> + if (cleanup_mode & FOLL_PIN)
> + bio_set_flag(bio, BIO_PAGE_PINNED);
The flags here must not change from one invocation to another, so
clearing and resetting them on every iteration seems dangerous.
This should probably be a:
if (cleanup_mode & FOLL_GET) {
WARN_ON_ONCE(bio_test_flag(bio, BIO_PAGE_PINNED));
bio_set_flag(bio, BIO_PAGE_REFFED);
}
if (cleanup_mode & FOLL_PIN) {
WARN_ON_ONCE(bio_test_flag(bio, BIO_PAGE_REFFED));
bio_set_flag(bio, BIO_PAGE_PINNED);
}
next prev parent reply other threads:[~2023-01-12 7:45 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 14:27 [PATCH v5 0/9] iov_iter: Add extraction helpers David Howells
2023-01-11 14:27 ` [PATCH v5 1/9] iov_iter: Change the direction macros into an enum David Howells
2023-01-11 14:27 ` [PATCH v5 2/9] iov_iter: Use the direction in the iterator functions David Howells
2023-01-11 14:27 ` [PATCH v5 3/9] iov_iter: Use IOCB/IOMAP_WRITE if available rather than iterator direction David Howells
2023-01-12 7:54 ` Christoph Hellwig
2023-01-12 10:31 ` David Howells
2023-01-12 14:08 ` Christoph Hellwig
2023-01-12 17:37 ` Al Viro
2023-01-12 21:49 ` Bart Van Assche
2023-01-13 5:32 ` Christoph Hellwig
2023-01-14 1:33 ` Martin K. Petersen
2023-01-14 1:34 ` Martin K. Petersen
2023-01-14 1:58 ` Al Viro
2023-01-13 5:30 ` Christoph Hellwig
2023-01-12 21:56 ` Al Viro
2023-01-13 5:33 ` Christoph Hellwig
2023-01-11 14:28 ` [PATCH v5 4/9] iov_iter: Add a function to extract a page list from an iterator David Howells
2023-01-12 7:55 ` Christoph Hellwig
2023-01-12 21:15 ` Al Viro
2023-01-12 21:36 ` Al Viro
2023-01-13 5:26 ` Christoph Hellwig
2023-01-11 14:28 ` [PATCH v5 5/9] netfs: Add a function to extract a UBUF or IOVEC into a BVEC iterator David Howells
2023-01-11 14:28 ` [PATCH v5 6/9] netfs: Add a function to extract an iterator into a scatterlist David Howells
2023-01-11 14:28 ` [PATCH v5 7/9] bio: Rename BIO_NO_PAGE_REF to BIO_PAGE_REFFED and invert the meaning David Howells
2023-01-12 7:32 ` Christoph Hellwig
2023-01-11 14:28 ` [PATCH v5 8/9] iov_iter, block: Make bio structs pin pages rather than ref'ing if appropriate David Howells
2023-01-12 7:44 ` Christoph Hellwig [this message]
2023-01-12 10:28 ` David Howells
2023-01-12 14:09 ` Christoph Hellwig
2023-01-12 14:17 ` Christoph Hellwig
2023-01-12 14:58 ` David Howells
2023-01-12 15:02 ` Christoph Hellwig
2023-01-11 14:28 ` [PATCH v5 9/9] bio: Fix bio_flagged() so that it can be combined David Howells
2023-01-12 7:33 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7+6YVkhZsvdW+Hr@infradead.org \
--to=hch@infradead.org \
--cc=axboe@kernel.dk \
--cc=dhowells@redhat.com \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®