From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: continue readahead of siblings even if target node is in memory
Date: Wed, 21 Jul 2021 07:57:15 +0800 [thread overview]
Message-ID: <8fa1476b-e8fb-d4b2-d841-7add2abe2f4d@gmx.com> (raw)
In-Reply-To: <1589fffc3a30631b2268b4f64e55fcf9ce664fb6.1626792325.git.fdmanana@suse.com>
On 2021/7/20 下午11:03, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> At reada_for_search(), when attempting to readahead a node or leaf's
> siblings, we skip the readahead of the siblings if the node/leaf is
> already in memory. That is probably fine for the READA_FORWARD and
> READA_BACK readahead types, as they are used on contextes where we
> end up reading some consecutive leaves, but usually not the whole btree.
>
> However for a READA_FORWARD_ALWAYS mode, currently only used for full
> send operations, it does not make sense to skip the readahead if the
> target node or leaf is already loaded in memory, since we know the caller
> is visiting every node and leaf of the btree in ascending order.
>
> So change the behaviour to not skip the readahead when the target node is
> already in memory and the readahead mode is READA_FORWARD_ALWAYS.
>
> The following test script was used to measure the improvement on a box
> using an average, consumer grade, spinning disk, with 32GiB of RAM and
> using a non-debug kernel config (Debian's default config).
>
> $ cat test.sh
> #!/bin/bash
>
> DEV=/dev/sdj
> MNT=/mnt/sdj
> MKFS_OPTIONS="--nodesize 16384" # default, just to be explicit
> MOUNT_OPTIONS="-o max_inline=2048" # default, just to be explicit
>
> mkfs.btrfs -f $MKFS_OPTIONS $DEV > /dev/null
> mount $MOUNT_OPTIONS $DEV $MNT
>
> # Create files with inline data to make it easier and faster to create
> # large btrees.
> add_files()
> {
> local total=$1
> local start_offset=$2
> local number_jobs=$3
> local total_per_job=$(($total / $number_jobs))
>
> echo "Creating $total new files using $number_jobs jobs"
> for ((n = 0; n < $number_jobs; n++)); do
> (
> local start_num=$(($start_offset + $n * $total_per_job))
> for ((i = 1; i <= $total_per_job; i++)); do
> local file_num=$((start_num + $i))
> local file_path="$MNT/file_${file_num}"
> xfs_io -f -c "pwrite -S 0xab 0 2000" $file_path > /dev/null
> if [ $? -ne 0 ]; then
> echo "Failed creating file $file_path"
> break
> fi
> done
> ) &
> worker_pids[$n]=$!
> done
>
> wait ${worker_pids[@]}
>
> sync
> echo
> echo "btree node/leaf count: $(btrfs inspect-internal dump-tree -t 5 $DEV | egrep '^(node|leaf) ' | wc -l)"
> }
>
> file_count=2000000
> add_files $file_count 0 4
>
> echo
> echo "Creating snapshot..."
> btrfs subvolume snapshot -r $MNT $MNT/snap1
>
> umount $MNT
>
> echo 3 > /proc/sys/vm/drop_caches
> blockdev --flushbufs $DEV &> /dev/null
> hdparm -F $DEV &> /dev/null
>
> mount $MOUNT_OPTIONS $DEV $MNT
>
> echo
> echo "Testing full send..."
> start=$(date +%s)
> btrfs send $MNT/snap1 > /dev/null
> end=$(date +%s)
> echo
> echo "Full send took $((end - start)) seconds"
>
> umount $MNT
>
> The duration of the full send operations, in seconds, were the following:
>
> Before this change: 85 seconds
> After this change: 76 seconds (-11.2%)
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Just one off-topic idea inlined below:
> ---
> fs/btrfs/ctree.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index c212f1218fdd..63c026495193 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -1233,7 +1233,6 @@ static void reada_for_search(struct btrfs_fs_info *fs_info,
> u64 target;
> u64 nread = 0;
> u64 nread_max;
> - struct extent_buffer *eb;
> u32 nr;
> u32 blocksize;
> u32 nscan = 0;
> @@ -1262,10 +1261,14 @@ static void reada_for_search(struct btrfs_fs_info *fs_info,
>
> search = btrfs_node_blockptr(node, slot);
> blocksize = fs_info->nodesize;
> - eb = find_extent_buffer(fs_info, search);
> - if (eb) {
> - free_extent_buffer(eb);
> - return;
> + if (path->reada != READA_FORWARD_ALWAYS) {
Currently only send uses this flag, but could it be applied to more call
sites like full device scrub?
Thanks,
Qu
> + struct extent_buffer *eb;
> +
> + eb = find_extent_buffer(fs_info, search);
> + if (eb) {
> + free_extent_buffer(eb);
> + return;
> + }
> }
>
> target = search;
>
next prev parent reply other threads:[~2021-07-20 23:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-20 15:03 [PATCH] btrfs: continue readahead of siblings even if target node is in memory fdmanana
2021-07-20 23:57 ` Qu Wenruo [this message]
2021-07-21 15:16 ` David Sterba
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=8fa1476b-e8fb-d4b2-d841-7add2abe2f4d@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=fdmanana@kernel.org \
--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