From: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>
To: Filipe Manana <fdmanana@kernel.org>, Johannes Thumshirn <jth@kernel.org>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
Filipe Manana <fdmanana@suse.com>,
Naohiro Aota <Naohiro.Aota@wdc.com>
Subject: Re: [PATCH v4 1/2] btrfs: implement partial deletion of RAID stripe extents
Date: Tue, 22 Oct 2024 15:37:35 +0000 [thread overview]
Message-ID: <0e990104-19c5-4695-bbdb-4dbceba80490@wdc.com> (raw)
In-Reply-To: <CAL3q7H45VMP=NeU7itO4M-T4m0kA9XYEsTkLttODy5W4_m5OLw@mail.gmail.com>
On 22.10.24 15:53, Filipe Manana wrote:
> On Thu, Oct 17, 2024 at 10:04 AM Johannes Thumshirn <jth@kernel.org> wrote:
>>
>> From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>>
>> In our CI system, the RAID stripe tree configuration sometimes fails with
>> the following ASSERT():
>>
>> assertion failed: found_start >= start && found_end <= end, in fs/btrfs/raid-stripe-tree.c:64
>>
>> This ASSERT()ion triggers, because for the initial design of RAID
>> stripe-tree, I had the "one ordered-extent equals one bio" rule of zoned
>> btrfs in mind.
>>
>> But for a RAID stripe-tree based system, that is not hosted on a zoned
>> storage device, but on a regular device this rule doesn't apply.
>>
>> So in case the range we want to delete starts in the middle of the
>> previous item, grab the item and "truncate" it's length. That is, clone
>> the item, subtract the deleted portion from the key's offset, delete the
>> old item and insert the new one.
>>
>> In case the range to delete ends in the middle of an item, we have to
>> adjust both the item's key as well as the stripe extents and then
>> re-insert the modified clone into the tree after deleting the old stripe
>> extent.
>>
>> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>> ---
>> fs/btrfs/ctree.c | 1 +
>> fs/btrfs/raid-stripe-tree.c | 94 ++++++++++++++++++++++++++++++++++---
>> 2 files changed, 88 insertions(+), 7 deletions(-)
>>
>> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
>> index b11ec86102e3..3f320f6e7767 100644
>> --- a/fs/btrfs/ctree.c
>> +++ b/fs/btrfs/ctree.c
>> @@ -3863,6 +3863,7 @@ static noinline int setup_leaf_for_split(struct btrfs_trans_handle *trans,
>> btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
>>
>> BUG_ON(key.type != BTRFS_EXTENT_DATA_KEY &&
>> + key.type != BTRFS_RAID_STRIPE_KEY &&
>> key.type != BTRFS_EXTENT_CSUM_KEY);
>>
>> if (btrfs_leaf_free_space(leaf) >= ins_len)
>> diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c
>> index 41970bbdb05f..569273e42d85 100644
>> --- a/fs/btrfs/raid-stripe-tree.c
>> +++ b/fs/btrfs/raid-stripe-tree.c
>> @@ -13,6 +13,50 @@
>> #include "volumes.h"
>> #include "print-tree.h"
>>
>> +static int btrfs_partially_delete_raid_extent(struct btrfs_trans_handle *trans,
>> + struct btrfs_path *path,
>> + struct btrfs_key *oldkey,
>
> oldkey can be made const.
>
>> + u64 newlen, u64 frontpad)
>> +{
>> + struct btrfs_root *stripe_root = trans->fs_info->stripe_root;
>> + struct btrfs_stripe_extent *extent;
>> + struct extent_buffer *leaf;
>> + int slot;
>> + size_t item_size;
>> + int ret;
>> + struct btrfs_key newkey = {
>> + .objectid = oldkey->objectid + frontpad,
>> + .type = BTRFS_RAID_STRIPE_KEY,
>> + .offset = newlen,
>> + };
>> +
>> + ASSERT(oldkey->type == BTRFS_RAID_STRIPE_KEY);
>> + ret = btrfs_duplicate_item(trans, stripe_root, path, &newkey);
>> + if (ret)
>> + return ret;
>> +
>> + leaf = path->nodes[0];
>> + slot = path->slots[0];
>> + item_size = btrfs_item_size(leaf, slot);
>> + extent = btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent);
>> +
>> + for (int i = 0; i < btrfs_num_raid_stripes(item_size); i++) {
>> + struct btrfs_raid_stride *stride = &extent->strides[i];
>> + u64 phys;
>> +
>> + phys = btrfs_raid_stride_physical(leaf, stride);
>> + btrfs_set_raid_stride_physical(leaf, stride, phys + frontpad);
>> + }
>> +
>> + btrfs_mark_buffer_dirty(trans, leaf);
>
> This is redundant, it was already done by btrfs_duplicate_item(), by
> the btrfs_search_slot() call in the caller and done by
> btrfs_del_item() below as well.
>
>
>> +
>> + /* delete the old item, after we've inserted a new one. */
>> + path->slots[0]--;
>> + ret = btrfs_del_item(trans, stripe_root, path);
>
> So actually looking at this, we don't need btrfs_duplicate_item()
> plus btrfs_del_item(), this can be more lightweight and simpler by
> doing just:
>
> 1) Do the for loop as it is.
>
> 2) Then after, or before the for loop, the order doesn't really
> matter, just do: btrfs_set_item_key_safe(trans, path, &newkey).
>
> Less code and it avoids adding a new item and deleting another one,
> with the shiftings of data in the leaf, etc.
Oh I didn't know about btrfs_set_item_key_safe(), that sounds like a
good plan thanks :)
Can I still get rid of btrfs_mark_buffer_dirty then?
next prev parent reply other threads:[~2024-10-22 15:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 9:04 [PATCH v4 0/2] implement truncation for RAID stripe-extents Johannes Thumshirn
2024-10-17 9:04 ` [PATCH v4 1/2] btrfs: implement partial deletion of RAID stripe extents Johannes Thumshirn
2024-10-22 13:52 ` Filipe Manana
2024-10-22 15:37 ` Johannes Thumshirn [this message]
2024-10-22 15:41 ` Filipe Manana
2024-10-17 9:04 ` [PATCH v4 2/2] btrfs: implement self-tests for partial RAID srtipe-tree delete Johannes Thumshirn
2024-10-22 13:57 ` Filipe Manana
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=0e990104-19c5-4695-bbdb-4dbceba80490@wdc.com \
--to=johannes.thumshirn@wdc.com \
--cc=Naohiro.Aota@wdc.com \
--cc=dsterba@suse.com \
--cc=fdmanana@kernel.org \
--cc=fdmanana@suse.com \
--cc=josef@toxicpanda.com \
--cc=jth@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;
as well as URLs for NNTP newsgroup(s).