linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Filipe Manana <fdmanana@gmail.com>
To: Josef Bacik <josef@toxicpanda.com>
Cc: linux-btrfs <linux-btrfs@vger.kernel.org>, kernel-team@fb.com
Subject: Re: [PATCH 02/14] btrfs: cleanup extent buffer readahead
Date: Fri, 6 Nov 2020 11:51:15 +0000	[thread overview]
Message-ID: <CAL3q7H4zxBmBAeFsMKvnCuQbRydMvjyGSYmTEJ-ydppPOkqm=w@mail.gmail.com> (raw)
In-Reply-To: <c064bd10eca6d335160fa3ab838816fbc87de7c1.1604591048.git.josef@toxicpanda.com>

On Thu, Nov 5, 2020 at 3:47 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> I'm going to need to start passing around a lot more information when we
> allocate extent buffers, in order to make that cleaner we need to
> cleanup how we do readahead.  Most of the callers have the parent node
> that we're getting our blockptr from, with the sole exception of
> relocation which simply has the bytenr it wants to read.  Add a helper
> that takes the current arguments that we need (bytenr and gen), and add
> another helper for simply reading the slot out of a node.  In followup
> patches the helper that takes all the extra arguments will be expanded,
> and the simpler helper won't need to have it's arguments adjusted.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

I couldn't get anymore the lockdep splat I reported before (after
applying the whole patchset of course), it used to happen very often
with btrfs/033.

Looks good, thanks.

> ---
>  fs/btrfs/ctree.c       | 45 ++++++++--------------------------------
>  fs/btrfs/disk-io.c     | 16 --------------
>  fs/btrfs/disk-io.h     |  1 -
>  fs/btrfs/extent-tree.c |  2 +-
>  fs/btrfs/extent_io.c   | 47 ++++++++++++++++++++++++++++++++++++++++++
>  fs/btrfs/extent_io.h   |  3 +++
>  fs/btrfs/relocation.c  |  3 ++-
>  fs/btrfs/volumes.c     |  8 ++-----
>  8 files changed, 64 insertions(+), 61 deletions(-)
>
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index d2d5854d51a7..0ff866328a4f 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -2226,7 +2226,7 @@ static void reada_for_search(struct btrfs_fs_info *fs_info,
>                 search = btrfs_node_blockptr(node, nr);
>                 if ((search <= target && target - search <= 65536) ||
>                     (search > target && search - target <= 65536)) {
> -                       readahead_tree_block(fs_info, search);
> +                       btrfs_readahead_node_child(node, nr);
>                         nread += blocksize;
>                 }
>                 nscan++;
> @@ -2235,16 +2235,11 @@ static void reada_for_search(struct btrfs_fs_info *fs_info,
>         }
>  }
>
> -static noinline void reada_for_balance(struct btrfs_fs_info *fs_info,
> -                                      struct btrfs_path *path, int level)
> +static noinline void reada_for_balance(struct btrfs_path *path, int level)
>  {
> +       struct extent_buffer *parent;
>         int slot;
>         int nritems;
> -       struct extent_buffer *parent;
> -       struct extent_buffer *eb;
> -       u64 gen;
> -       u64 block1 = 0;
> -       u64 block2 = 0;
>
>         parent = path->nodes[level + 1];
>         if (!parent)
> @@ -2253,32 +2248,10 @@ static noinline void reada_for_balance(struct btrfs_fs_info *fs_info,
>         nritems = btrfs_header_nritems(parent);
>         slot = path->slots[level + 1];
>
> -       if (slot > 0) {
> -               block1 = btrfs_node_blockptr(parent, slot - 1);
> -               gen = btrfs_node_ptr_generation(parent, slot - 1);
> -               eb = find_extent_buffer(fs_info, block1);
> -               /*
> -                * if we get -eagain from btrfs_buffer_uptodate, we
> -                * don't want to return eagain here.  That will loop
> -                * forever
> -                */
> -               if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0)
> -                       block1 = 0;
> -               free_extent_buffer(eb);
> -       }
> -       if (slot + 1 < nritems) {
> -               block2 = btrfs_node_blockptr(parent, slot + 1);
> -               gen = btrfs_node_ptr_generation(parent, slot + 1);
> -               eb = find_extent_buffer(fs_info, block2);
> -               if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0)
> -                       block2 = 0;
> -               free_extent_buffer(eb);
> -       }
> -
> -       if (block1)
> -               readahead_tree_block(fs_info, block1);
> -       if (block2)
> -               readahead_tree_block(fs_info, block2);
> +       if (slot > 0)
> +               btrfs_readahead_node_child(parent, slot - 1);
> +       if (slot + 1 < nritems)
> +               btrfs_readahead_node_child(parent, slot + 1);
>  }
>
>
> @@ -2454,7 +2427,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans,
>                         goto again;
>                 }
>
> -               reada_for_balance(fs_info, p, level);
> +               reada_for_balance(p, level);
>                 sret = split_node(trans, root, p, level);
>
>                 BUG_ON(sret > 0);
> @@ -2473,7 +2446,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans,
>                         goto again;
>                 }
>
> -               reada_for_balance(fs_info, p, level);
> +               reada_for_balance(p, level);
>                 sret = balance_level(trans, root, p, level);
>
>                 if (sret) {
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 35b16fe3b05f..ec64e087520e 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -945,22 +945,6 @@ static const struct address_space_operations btree_aops = {
>         .set_page_dirty = btree_set_page_dirty,
>  };
>
> -void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr)
> -{
> -       struct extent_buffer *buf = NULL;
> -       int ret;
> -
> -       buf = btrfs_find_create_tree_block(fs_info, bytenr);
> -       if (IS_ERR(buf))
> -               return;
> -
> -       ret = read_extent_buffer_pages(buf, WAIT_NONE, 0);
> -       if (ret < 0)
> -               free_extent_buffer_stale(buf);
> -       else
> -               free_extent_buffer(buf);
> -}
> -
>  struct extent_buffer *btrfs_find_create_tree_block(
>                                                 struct btrfs_fs_info *fs_info,
>                                                 u64 bytenr)
> diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
> index 238b45223f2e..009f505d6c97 100644
> --- a/fs/btrfs/disk-io.h
> +++ b/fs/btrfs/disk-io.h
> @@ -45,7 +45,6 @@ int btrfs_verify_level_key(struct extent_buffer *eb, int level,
>  struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
>                                       u64 parent_transid, int level,
>                                       struct btrfs_key *first_key);
> -void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr);
>  struct extent_buffer *btrfs_find_create_tree_block(
>                                                 struct btrfs_fs_info *fs_info,
>                                                 u64 bytenr);
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index d7a68203cda0..bf2f0af24e91 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -4854,7 +4854,7 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans,
>                                 continue;
>                 }
>  reada:
> -               readahead_tree_block(fs_info, bytenr);
> +               btrfs_readahead_node_child(eb, slot);
>                 nread++;
>         }
>         wc->reada_slot = slot;
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 119ced4a501b..c9d652b0770a 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -6114,3 +6114,50 @@ int try_release_extent_buffer(struct page *page)
>
>         return release_extent_buffer(eb);
>  }
> +
> +/**
> + * btrfs_readahead_tree_block - attempt to readahead a child block.
> + * @fs_info - the fs_info for the fs.
> + * @bytenr - the bytenr to read.
> + * @gen - the generation for the uptodate check, can be 0.
> + *
> + * Attempt to readahead a tree block at @bytenr.  If @gen is 0 then we do a
> + * normal uptodate check of the eb, without checking the generation.  If we have
> + * to read the block we will not block on anything.
> + */
> +void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info,
> +                               u64 bytenr, u64 gen)
> +{
> +       struct extent_buffer *eb;
> +       int ret;
> +
> +       eb = btrfs_find_create_tree_block(fs_info, bytenr);
> +       if (IS_ERR(eb))
> +               return;
> +
> +       if (btrfs_buffer_uptodate(eb, gen, 1)) {
> +               free_extent_buffer(eb);
> +               return;
> +       }
> +
> +       ret = read_extent_buffer_pages(eb, WAIT_NONE, 0);
> +       if (ret < 0)
> +               free_extent_buffer_stale(eb);
> +       else
> +               free_extent_buffer(eb);
> +}
> +
> +/**
> + * btrfs_readahead_node_child - readahead a node's child block.
> + * @node - the parent node we're reading from.
> + * @slot - the slot in the parent node for the child we want to read.
> + *
> + * A helper for btrfs_readahead_tree_block, we simply read the bytenr pointed at
> + * the slot in the node provided.
> + */
> +void btrfs_readahead_node_child(struct extent_buffer *node, int slot)
> +{
> +       btrfs_readahead_tree_block(node->fs_info,
> +                                  btrfs_node_blockptr(node, slot),
> +                                  btrfs_node_ptr_generation(node, slot));
> +}
> diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
> index 3c2bf21c54eb..a211e90292f8 100644
> --- a/fs/btrfs/extent_io.h
> +++ b/fs/btrfs/extent_io.h
> @@ -198,6 +198,9 @@ void free_extent_buffer_stale(struct extent_buffer *eb);
>  int read_extent_buffer_pages(struct extent_buffer *eb, int wait,
>                              int mirror_num);
>  void wait_on_extent_buffer_writeback(struct extent_buffer *eb);
> +void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info,
> +                               u64 bytenr, u64 gen);
> +void btrfs_readahead_node_child(struct extent_buffer *node, int slot);
>
>  static inline int num_extent_pages(const struct extent_buffer *eb)
>  {
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 0b3ccf464c3d..0e2dd7cf87f6 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -2542,7 +2542,8 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
>         /* Kick in readahead for tree blocks with missing keys */
>         rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
>                 if (!block->key_ready)
> -                       readahead_tree_block(fs_info, block->bytenr);
> +                       btrfs_readahead_tree_block(fs_info,
> +                                                  block->bytenr, 0);
>         }
>
>         /* Get first keys */
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index c927dc597550..8beb91d3cd88 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -7065,12 +7065,8 @@ static void readahead_tree_node_children(struct extent_buffer *node)
>         int i;
>         const int nr_items = btrfs_header_nritems(node);
>
> -       for (i = 0; i < nr_items; i++) {
> -               u64 start;
> -
> -               start = btrfs_node_blockptr(node, i);
> -               readahead_tree_block(node->fs_info, start);
> -       }
> +       for (i = 0; i < nr_items; i++)
> +               btrfs_readahead_node_child(node, i);
>  }
>
>  int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
> --
> 2.26.2
>


-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

  reply	other threads:[~2020-11-06 11:51 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05 15:45 [PATCH 00/14][REBASED] Set the lockdep class on eb's at allocation time Josef Bacik
2020-11-05 15:45 ` [PATCH 01/14] btrfs: remove lockdep classes for the fs tree Josef Bacik
2020-11-06 11:50   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 02/14] btrfs: cleanup extent buffer readahead Josef Bacik
2020-11-06 11:51   ` Filipe Manana [this message]
2020-11-09 15:09   ` David Sterba
2020-11-05 15:45 ` [PATCH 03/14] btrfs: use btrfs_read_node_slot in btrfs_realloc_node Josef Bacik
2020-11-06 11:51   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 04/14] btrfs: use btrfs_read_node_slot in walk_down_reloc_tree Josef Bacik
2020-11-06 11:52   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 05/14] btrfs: use btrfs_read_node_slot in do_relocation Josef Bacik
2020-11-06 11:52   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 06/14] btrfs: use btrfs_read_node_slot in replace_path Josef Bacik
2020-11-06 11:53   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 07/14] btrfs: use btrfs_read_node_slot in walk_down_tree Josef Bacik
2020-11-06 11:53   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 08/14] btrfs: use btrfs_read_node_slot in qgroup_trace_extent_swap Josef Bacik
2020-11-06 11:53   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 09/14] btrfs: use btrfs_read_node_slot in qgroup_trace_new_subtree_blocks Josef Bacik
2020-11-06 11:54   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 10/14] btrfs: use btrfs_read_node_slot in btrfs_qgroup_trace_subtree Josef Bacik
2020-11-06 11:55   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 11/14] btrfs: pass root owner to read_tree_block Josef Bacik
2020-11-06 11:55   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 12/14] btrfs: pass the root owner and level around for reada Josef Bacik
2020-11-06 11:56   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 13/14] btrfs: pass the owner_root and level to alloc_extent_buffer Josef Bacik
2020-11-06 11:54   ` Filipe Manana
2020-11-05 15:45 ` [PATCH 14/14] btrfs: set the lockdep class for ebs on creation Josef Bacik
2020-11-06 11:58   ` Filipe Manana
2020-11-09 16:50 ` [PATCH 00/14][REBASED] Set the lockdep class on eb's at allocation time David Sterba
  -- strict thread matches above, loose matches on Subject: below --
2020-10-30 21:02 [PATCH 00/14] " Josef Bacik
2020-10-30 21:02 ` [PATCH 02/14] btrfs: cleanup extent buffer readahead Josef Bacik

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='CAL3q7H4zxBmBAeFsMKvnCuQbRydMvjyGSYmTEJ-ydppPOkqm=w@mail.gmail.com' \
    --to=fdmanana@gmail.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.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 NNTP newsgroup(s).