From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Naohiro Aota <Naohiro.Aota@wdc.com>, Qu Wenruo <wqu@suse.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
"josef@toxicpanda.com" <josef@toxicpanda.com>
Subject: Re: [PATCH v5 2/5] btrfs: subpage: introduce helpers to handle subpage delalloc locking
Date: Tue, 21 May 2024 17:27:40 +0930 [thread overview]
Message-ID: <a879b8e6-b5e1-4328-b05b-6040564f301a@gmx.com> (raw)
In-Reply-To: <5faun6sbhn3x37b2kwudtnuumquuiyi4oyferavknmxgoofwgk@tubvkvthpwog>
在 2024/5/21 17:20, Naohiro Aota 写道:
[...]
>> +void btrfs_folio_set_writer_lock(const struct btrfs_fs_info *fs_info,
>> + struct folio *folio, u64 start, u32 len)
>> +{
>> + struct btrfs_subpage *subpage;
>> + unsigned long flags;
>> + int start_bit;
>> + int nbits;
>
> May want to use unsigned int for a consistency...
>
I can definitely change all the int to "unsigned int" to be consistent
during pushing to for-next branch.
[...]
>> + found = true;
>> + *found_start_ret = folio_pos(folio) +
>> + ((first_set - locked_bitmap_start) << fs_info->sectorsize_bits);
>
> It's a bit fearful to see an "int" value is shifted and added into u64
> value. But, I guess sectorsize is within 32-bit range, right?
In fact, (first_set - locked_bitmap_start) is never going to be larger
than (PAGE_SIZE / sectorsize).
I can add extra ASSERT() to be extra safe for that too.
Thanks,
Qu
>
>> +
>> + first_zero = find_next_zero_bit(subpage->bitmaps,
>> + locked_bitmap_end, first_set);
>> + *found_len_ret = (first_zero - first_set) << fs_info->sectorsize_bits;
>> +out:
>> + spin_unlock_irqrestore(&subpage->lock, flags);
>> + return found;
>> +}
>> +
>> +/*
>> + * Unlike btrfs_folio_end_writer_lock() which unlock a specified subpage range,
>> + * this would end all writer locked ranges of a page.
>> + *
>> + * This is for the locked page of __extent_writepage(), as the locked page
>> + * can contain several locked subpage ranges.
>> + */
>> +void btrfs_folio_end_all_writers(const struct btrfs_fs_info *fs_info,
>> + struct folio *folio)
>> +{
>> + u64 folio_start = folio_pos(folio);
>> + u64 cur = folio_start;
>> +
>> + ASSERT(folio_test_locked(folio));
>> + if (!btrfs_is_subpage(fs_info, folio->mapping)) {
>> + folio_unlock(folio);
>> + return;
>> + }
>> +
>> + while (cur < folio_start + PAGE_SIZE) {
>> + u64 found_start;
>> + u32 found_len;
>> + bool found;
>> + bool last;
>> +
>> + found = btrfs_subpage_find_writer_locked(fs_info, folio, cur,
>> + &found_start, &found_len);
>> + if (!found)
>> + break;
>> + last = btrfs_subpage_end_and_test_writer(fs_info, folio,
>> + found_start, found_len);
>> + if (last) {
>> + folio_unlock(folio);
>> + break;
>> + }
>> + cur = found_start + found_len;
>> + }
>> +}
>> +
>> #define GET_SUBPAGE_BITMAP(subpage, subpage_info, name, dst) \
>> bitmap_cut(dst, subpage->bitmaps, 0, \
>> subpage_info->name##_offset, subpage_info->bitmap_nr_bits)
>> diff --git a/fs/btrfs/subpage.h b/fs/btrfs/subpage.h
>> index 4b363d9453af..9f19850d59f2 100644
>> --- a/fs/btrfs/subpage.h
>> +++ b/fs/btrfs/subpage.h
>> @@ -112,6 +112,13 @@ int btrfs_folio_start_writer_lock(const struct btrfs_fs_info *fs_info,
>> struct folio *folio, u64 start, u32 len);
>> void btrfs_folio_end_writer_lock(const struct btrfs_fs_info *fs_info,
>> struct folio *folio, u64 start, u32 len);
>> +void btrfs_folio_set_writer_lock(const struct btrfs_fs_info *fs_info,
>> + struct folio *folio, u64 start, u32 len);
>> +bool btrfs_subpage_find_writer_locked(const struct btrfs_fs_info *fs_info,
>> + struct folio *folio, u64 search_start,
>> + u64 *found_start_ret, u32 *found_len_ret);
>> +void btrfs_folio_end_all_writers(const struct btrfs_fs_info *fs_info,
>> + struct folio *folio);
>>
>> /*
>> * Template for subpage related operations.
>> --
>> 2.45.0
>>
next prev parent reply other threads:[~2024-05-21 7:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-18 5:07 [PATCH v5 0/5] btrfs: subpage + zoned fixes Qu Wenruo
2024-05-18 5:07 ` [PATCH v5 1/5] btrfs: make __extent_writepage_io() to write specified range only Qu Wenruo
2024-05-21 7:23 ` Naohiro Aota
2024-05-18 5:07 ` [PATCH v5 2/5] btrfs: subpage: introduce helpers to handle subpage delalloc locking Qu Wenruo
2024-05-21 7:50 ` Naohiro Aota
2024-05-21 7:57 ` Qu Wenruo [this message]
2024-05-18 5:07 ` [PATCH v5 3/5] btrfs: lock subpage ranges in one go for writepage_delalloc() Qu Wenruo
2024-05-21 8:11 ` Naohiro Aota
2024-05-21 8:45 ` Qu Wenruo
2024-05-21 11:54 ` Naohiro Aota
2024-05-21 22:16 ` Qu Wenruo
2024-05-22 1:10 ` Naohiro Aota
2024-05-18 5:07 ` [PATCH v5 4/5] btrfs: do not clear page dirty inside extent_write_locked_range() Qu Wenruo
2024-05-18 5:07 ` [PATCH v5 5/5] btrfs: make extent_write_locked_range() to handle subpage writeback correctly Qu Wenruo
2024-05-21 7:13 ` Naohiro Aota
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=a879b8e6-b5e1-4328-b05b-6040564f301a@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=Johannes.Thumshirn@wdc.com \
--cc=Naohiro.Aota@wdc.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/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