Linux-Fsdevel Archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Mike Marshall <hubcap@omnibond.com>
Cc: dhowells@redhat.com, Matthew Wilcox <willy@infradead.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [RFC PATCH v2] implement orangefs_readahead
Date: Wed, 24 Mar 2021 11:10:10 +0000	[thread overview]
Message-ID: <2884397.1616584210@warthog.procyon.org.uk> (raw)
In-Reply-To: <CAOg9mSSEVE3PGs2E9ya5_B6dQkoH6n2wGAEW_wWSEvw0LurWuQ@mail.gmail.com>

Mike Marshall <hubcap@omnibond.com> wrote:

> /* allocate an array of bio_vecs. */
> bvs = kzalloc(npages * (sizeof(struct bio_vec)), GFP_KERNEL);
>

Better to use kcalloc() here as it has overflow checking.

> /* hook the bio_vecs to the pages. */
> for (i = 0; i < npages; i++) {
> bvs[i].bv_page = pages[i];
> bvs[i].bv_len = PAGE_SIZE;
> bvs[i].bv_offset = 0;
> }
> 
> iov_iter_bvec(&iter, READ, bvs, npages, npages * PAGE_SIZE);
> 
> /* read in the pages. */
> ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, &offset, &iter,
> npages * PAGE_SIZE, inode->i_size, NULL, NULL, file);
> 
> /* clean up. */
> for (i = 0; i < npages; i++) {
> SetPageUptodate(bvs[i].bv_page);
> unlock_page(bvs[i].bv_page);
> put_page(bvs[i].bv_page);
> }
> kfree(pages);
> kfree(bvs);
> }

Could you try ITER_XARRAY instead of ITER_BVEC:

	https://lore.kernel.org/linux-fsdevel/161653786033.2770958.14154191921867463240.stgit@warthog.procyon.org.uk/T/#u

Setting the iterator looks like:

	iov_iter_xarray(&iter, READ, &mapping->i_pages,
			offset, npages * PAGE_SIZE);

The xarray iterator will handle THPs, but I'm not sure if bvecs will.

Cleanup afterwards would look something like:

	static void afs_file_read_done(struct afs_read *req)
	{
		struct afs_vnode *vnode = req->vnode;
		struct page *page;
		pgoff_t index = req->pos >> PAGE_SHIFT;
		pgoff_t last = index + req->nr_pages - 1;

		XA_STATE(xas, &vnode->vfs_inode.i_mapping->i_pages, index);

		if (iov_iter_count(req->iter) > 0) {
			/* The read was short - clear the excess buffer. */
			_debug("afterclear %zx %zx %llx/%llx",
			       req->iter->iov_offset,
			       iov_iter_count(req->iter),
			       req->actual_len, req->len);
			iov_iter_zero(iov_iter_count(req->iter), req->iter);
		}

		rcu_read_lock();
		xas_for_each(&xas, page, last) {
			page_endio(page, false, 0);
			put_page(page);
		}
		rcu_read_unlock();

		task_io_account_read(req->len);
		req->cleanup = NULL;
	}

David


  parent reply	other threads:[~2021-03-24 11:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-31 22:25 [RFC PATCH] implement orangefs_readahead Mike Marshall
2021-02-01 13:08 ` Matthew Wilcox
2021-02-02  3:32   ` Mike Marshall
2021-03-13 15:31     ` [RFC PATCH v2] " Mike Marshall
2021-03-17  3:04       ` Mike Marshall
2021-03-24 11:10     ` David Howells [this message]
2021-03-27  2:55       ` Mike Marshall
2021-03-27  3:50         ` Matthew Wilcox
2021-03-27  8:31         ` David Howells
2021-03-27 13:56           ` Matthew Wilcox
2021-03-27 15:40             ` Mike Marshall
2021-03-27 15:56               ` Matthew Wilcox
2021-03-28  3:04                 ` Mike Marshall
2021-03-29  1:51                   ` Mike Marshall
2021-03-29  9:37                   ` David Howells
2021-03-29 23:25                     ` Mike Marshall
     [not found]                       ` <3726695.1617284551@warthog.procyon.org.uk >
2021-04-13 15:08                         ` David Howells
2021-04-16 14:36                           ` Mike Marshall
2021-04-16 15:14                             ` Matthew Wilcox
2021-04-25  1:51                               ` Mike Marshall
2021-04-16 15:41                           ` David Howells
2021-04-25  1:43                             ` Mike Marshall
2021-04-25  7:49                             ` David Howells
2021-04-26 14:53                               ` Mike Marshall
2021-04-26 19:01                                 ` Mike Marshall
2021-04-26 20:01                                 ` David Howells
2021-04-26  8:37                             ` David Howells
2021-04-01 13:42                     ` David Howells
2021-04-08 20:39                       ` Mike Marshall

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=2884397.1616584210@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=hubcap@omnibond.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).