2021-01-26 16:33:47 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
|
|
|
|
#ifndef BTRFS_SUBPAGE_H
|
|
|
|
#define BTRFS_SUBPAGE_H
|
|
|
|
|
|
|
|
#include <linux/spinlock.h>
|
2024-01-27 03:19:56 +01:00
|
|
|
#include <linux/atomic.h>
|
2024-08-05 15:02:54 +09:30
|
|
|
#include <linux/sizes.h>
|
2024-01-27 03:19:56 +01:00
|
|
|
|
|
|
|
struct address_space;
|
|
|
|
struct folio;
|
|
|
|
struct btrfs_fs_info;
|
2021-01-26 16:33:47 +08:00
|
|
|
|
2021-08-17 17:38:51 +08:00
|
|
|
/*
|
|
|
|
* Extra info for subpapge bitmap.
|
|
|
|
*
|
2023-05-31 08:04:57 +02:00
|
|
|
* For subpage we pack all uptodate/dirty/writeback/ordered bitmaps into
|
2021-08-17 17:38:51 +08:00
|
|
|
* one larger bitmap.
|
|
|
|
*
|
|
|
|
* This structure records how they are organized in the bitmap:
|
|
|
|
*
|
2024-08-26 15:44:50 +09:30
|
|
|
* /- uptodate /- dirty /- ordered
|
2021-08-17 17:38:51 +08:00
|
|
|
* | | |
|
|
|
|
* v v v
|
2023-05-31 08:04:57 +02:00
|
|
|
* |u|u|u|u|........|u|u|d|d|.......|d|d|o|o|.......|o|o|
|
2024-08-26 15:44:50 +09:30
|
|
|
* |< sectors_per_page >|
|
|
|
|
*
|
|
|
|
* Unlike regular macro-like enums, here we do not go upper-case names, as
|
|
|
|
* these names will be utilized in various macros to define function names.
|
2021-08-17 17:38:51 +08:00
|
|
|
*/
|
2024-08-26 15:44:50 +09:30
|
|
|
enum {
|
|
|
|
btrfs_bitmap_nr_uptodate = 0,
|
|
|
|
btrfs_bitmap_nr_dirty,
|
|
|
|
btrfs_bitmap_nr_writeback,
|
|
|
|
btrfs_bitmap_nr_ordered,
|
|
|
|
btrfs_bitmap_nr_checked,
|
|
|
|
btrfs_bitmap_nr_locked,
|
|
|
|
btrfs_bitmap_nr_max
|
2021-08-17 17:38:51 +08:00
|
|
|
};
|
|
|
|
|
2021-01-26 16:33:47 +08:00
|
|
|
/*
|
|
|
|
* Structure to trace status of each sector inside a page, attached to
|
|
|
|
* page::private for both data and metadata inodes.
|
|
|
|
*/
|
|
|
|
struct btrfs_subpage {
|
|
|
|
/* Common members for both data and metadata pages */
|
|
|
|
spinlock_t lock;
|
btrfs: subpage: fix a rare race between metadata endio and eb freeing
[BUG]
There is a very rare ASSERT() triggering during full fstests run for
subpage rw support.
No other reproducer so far.
The ASSERT() gets triggered for metadata read in
btrfs_page_set_uptodate() inside end_page_read().
[CAUSE]
There is still a small race window for metadata only, the race could
happen like this:
T1 | T2
------------------------------------+-----------------------------
end_bio_extent_readpage() |
|- btrfs_validate_metadata_buffer() |
| |- free_extent_buffer() |
| Still have 2 refs |
|- end_page_read() |
|- if (unlikely(PagePrivate()) |
| The page still has Private |
| | free_extent_buffer()
| | | Only one ref 1, will be
| | | released
| | |- detach_extent_buffer_page()
| | |- btrfs_detach_subpage()
|- btrfs_set_page_uptodate() |
The page no longer has Private|
>>> ASSERT() triggered <<< |
This race window is super small, thus pretty hard to hit, even with so
many runs of fstests.
But the race window is still there, we have to go another way to solve
it other than relying on random PagePrivate() check.
Data path is not affected, as it will lock the page before reading,
while unlocking the page after the last read has finished, thus no race
window.
[FIX]
This patch will fix the bug by repurposing btrfs_subpage::readers.
Now btrfs_subpage::readers will be a member shared by both metadata and
data.
For metadata path, we don't do the page unlock as metadata only relies
on extent locking.
At the same time, teach page_range_has_eb() to take
btrfs_subpage::readers into consideration.
So that even if the last eb of a page gets freed, page::private won't be
detached as long as there still are pending end_page_read() calls.
By this we eliminate the race window, this will slight increase the
metadata memory usage, as the page may not be released as frequently as
usual. But it should not be a big deal.
The code got introduced in ("btrfs: submit read time repair only for
each corrupted sector"), but the fix is in a separate patch to keep the
problem description and the crash is rare so it should not hurt
bisectability.
Signed-off-by: Qu Wegruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-07 17:02:58 +08:00
|
|
|
/*
|
|
|
|
* Both data and metadata needs to track how many readers are for the
|
|
|
|
* page.
|
|
|
|
* Data relies on @readers to unlock the page when last reader finished.
|
|
|
|
* While metadata doesn't need page unlock, it needs to prevent
|
|
|
|
* page::private get cleared before the last end_page_read().
|
|
|
|
*/
|
|
|
|
atomic_t readers;
|
2021-01-26 16:33:48 +08:00
|
|
|
union {
|
btrfs: support subpage for extent buffer page release
In btrfs_release_extent_buffer_pages(), we need to add extra handling
for subpage.
Introduce a helper, detach_extent_buffer_page(), to do different
handling for regular and subpage cases.
For subpage case, handle detaching page private.
For unmapped (dummy or cloned) ebs, we can detach the page private
immediately as the page can only be attached to one unmapped eb.
For mapped ebs, we have to ensure there are no eb in the page range
before we delete it, as page->private is shared between all ebs in the
same page.
But there is a subpage specific race, where we can race with extent
buffer allocation, and clear the page private while new eb is still
being utilized, like this:
Extent buffer A is the new extent buffer which will be allocated,
while extent buffer B is the last existing extent buffer of the page.
T1 (eb A) | T2 (eb B)
-------------------------------+------------------------------
alloc_extent_buffer() | btrfs_release_extent_buffer_pages()
|- p = find_or_create_page() | |
|- attach_extent_buffer_page() | |
| | |- detach_extent_buffer_page()
| | |- if (!page_range_has_eb())
| | | No new eb in the page range yet
| | | As new eb A hasn't yet been
| | | inserted into radix tree.
| | |- btrfs_detach_subpage()
| | |- detach_page_private();
|- radix_tree_insert() |
Then we have a metadata eb whose page has no private bit.
To avoid such race, we introduce a subpage metadata-specific member,
btrfs_subpage::eb_refs.
In alloc_extent_buffer() we increase eb_refs in the critical section of
private_lock. Then page_range_has_eb() will return true for
detach_extent_buffer_page(), and will not detach page private.
The section is marked by:
- btrfs_page_inc_eb_refs()
- btrfs_page_dec_eb_refs()
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-26 16:33:50 +08:00
|
|
|
/*
|
|
|
|
* Structures only used by metadata
|
|
|
|
*
|
|
|
|
* @eb_refs should only be operated under private_lock, as it
|
|
|
|
* manages whether the subpage can be detached.
|
|
|
|
*/
|
|
|
|
atomic_t eb_refs;
|
2021-05-31 16:50:45 +08:00
|
|
|
|
2021-08-17 17:38:52 +08:00
|
|
|
/* Structures only used by data */
|
|
|
|
atomic_t writers;
|
2021-01-26 16:33:48 +08:00
|
|
|
};
|
2021-08-17 17:38:52 +08:00
|
|
|
unsigned long bitmaps[];
|
2021-01-26 16:33:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum btrfs_subpage_type {
|
|
|
|
BTRFS_SUBPAGE_METADATA,
|
|
|
|
BTRFS_SUBPAGE_DATA,
|
|
|
|
};
|
|
|
|
|
2024-08-05 15:02:54 +09:30
|
|
|
#if PAGE_SIZE > SZ_4K
|
2023-12-07 09:39:28 +10:30
|
|
|
bool btrfs_is_subpage(const struct btrfs_fs_info *fs_info, struct address_space *mapping);
|
2024-08-05 15:02:54 +09:30
|
|
|
#else
|
|
|
|
static inline bool btrfs_is_subpage(const struct btrfs_fs_info *fs_info,
|
|
|
|
struct address_space *mapping)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
btrfs: make nodesize >= PAGE_SIZE case to reuse the non-subpage routine
The reason why we only support 64K page size for subpage is, for 64K
page size we can ensure no matter what the nodesize is, we can fit it
into one page.
When other page size come, especially like 16K, the limitation is a bit
limiting.
To remove such limitation, we allow nodesize >= PAGE_SIZE case to go the
non-subpage routine. By this, we can allow 4K sectorsize on 16K page
size.
Although this introduces another smaller limitation, the metadata can
not cross page boundary, which is already met by most recent mkfs.
Another small improvement is, we can avoid the overhead for metadata if
nodesize >= PAGE_SIZE.
For 4K sector size and 64K page size/node size, or 4K sector size and
16K page size/node size, we don't need to allocate extra memory for the
metadata pages.
Please note that, this patch will not yet enable other page size support
yet.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-01-13 13:22:09 +08:00
|
|
|
|
2021-01-26 16:33:47 +08:00
|
|
|
int btrfs_attach_subpage(const struct btrfs_fs_info *fs_info,
|
2023-12-12 12:58:37 +10:30
|
|
|
struct folio *folio, enum btrfs_subpage_type type);
|
|
|
|
void btrfs_detach_subpage(const struct btrfs_fs_info *fs_info, struct folio *folio);
|
2021-01-26 16:33:47 +08:00
|
|
|
|
2021-01-26 16:33:48 +08:00
|
|
|
/* Allocate additional data where page represents more than one sector */
|
2021-08-17 17:38:50 +08:00
|
|
|
struct btrfs_subpage *btrfs_alloc_subpage(const struct btrfs_fs_info *fs_info,
|
|
|
|
enum btrfs_subpage_type type);
|
2021-01-26 16:33:48 +08:00
|
|
|
void btrfs_free_subpage(struct btrfs_subpage *subpage);
|
|
|
|
|
2023-12-07 09:39:28 +10:30
|
|
|
void btrfs_folio_inc_eb_refs(const struct btrfs_fs_info *fs_info, struct folio *folio);
|
|
|
|
void btrfs_folio_dec_eb_refs(const struct btrfs_fs_info *fs_info, struct folio *folio);
|
btrfs: support subpage for extent buffer page release
In btrfs_release_extent_buffer_pages(), we need to add extra handling
for subpage.
Introduce a helper, detach_extent_buffer_page(), to do different
handling for regular and subpage cases.
For subpage case, handle detaching page private.
For unmapped (dummy or cloned) ebs, we can detach the page private
immediately as the page can only be attached to one unmapped eb.
For mapped ebs, we have to ensure there are no eb in the page range
before we delete it, as page->private is shared between all ebs in the
same page.
But there is a subpage specific race, where we can race with extent
buffer allocation, and clear the page private while new eb is still
being utilized, like this:
Extent buffer A is the new extent buffer which will be allocated,
while extent buffer B is the last existing extent buffer of the page.
T1 (eb A) | T2 (eb B)
-------------------------------+------------------------------
alloc_extent_buffer() | btrfs_release_extent_buffer_pages()
|- p = find_or_create_page() | |
|- attach_extent_buffer_page() | |
| | |- detach_extent_buffer_page()
| | |- if (!page_range_has_eb())
| | | No new eb in the page range yet
| | | As new eb A hasn't yet been
| | | inserted into radix tree.
| | |- btrfs_detach_subpage()
| | |- detach_page_private();
|- radix_tree_insert() |
Then we have a metadata eb whose page has no private bit.
To avoid such race, we introduce a subpage metadata-specific member,
btrfs_subpage::eb_refs.
In alloc_extent_buffer() we increase eb_refs in the critical section of
private_lock. Then page_range_has_eb() will return true for
detach_extent_buffer_page(), and will not detach page private.
The section is marked by:
- btrfs_page_inc_eb_refs()
- btrfs_page_dec_eb_refs()
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-26 16:33:50 +08:00
|
|
|
|
btrfs: integrate page status update for data read path into begin/end_page_read
In btrfs data page read path, the page status update are handled in two
different locations:
btrfs_do_read_page()
{
while (cur <= end) {
/* No need to read from disk */
if (HOLE/PREALLOC/INLINE){
memset();
set_extent_uptodate();
continue;
}
/* Read from disk */
ret = submit_extent_page(end_bio_extent_readpage);
}
end_bio_extent_readpage()
{
endio_readpage_uptodate_page_status();
}
This is fine for sectorsize == PAGE_SIZE case, as for above loop we
should only hit one branch and then exit.
But for subpage, there is more work to be done in page status update:
- Page Unlock condition
Unlike regular page size == sectorsize case, we can no longer just
unlock a page.
Only the last reader of the page can unlock the page.
This means, we can unlock the page either in the while() loop, or in
the endio function.
- Page uptodate condition
Since we have multiple sectors to read for a page, we can only mark
the full page uptodate if all sectors are uptodate.
To handle both subpage and regular cases, introduce a pair of functions
to help handling page status update:
- begin_page_read()
For regular case, it does nothing.
For subpage case, it updates the reader counters so that later
end_page_read() can know who is the last one to unlock the page.
- end_page_read()
This is just endio_readpage_uptodate_page_status() renamed.
The original name is a little too long and too specific for endio.
The new thing added is the condition for page unlock.
Now for subpage data, we unlock the page if we're the last reader.
This does not only provide the basis for subpage data read, but also
hide the special handling of page read from the main read loop.
Also, since we're changing how the page lock is handled, there are two
existing error paths where we need to manually unlock the page before
calling begin_page_read().
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-02 10:28:36 +08:00
|
|
|
void btrfs_subpage_start_reader(const struct btrfs_fs_info *fs_info,
|
2023-12-12 12:58:37 +10:30
|
|
|
struct folio *folio, u64 start, u32 len);
|
btrfs: integrate page status update for data read path into begin/end_page_read
In btrfs data page read path, the page status update are handled in two
different locations:
btrfs_do_read_page()
{
while (cur <= end) {
/* No need to read from disk */
if (HOLE/PREALLOC/INLINE){
memset();
set_extent_uptodate();
continue;
}
/* Read from disk */
ret = submit_extent_page(end_bio_extent_readpage);
}
end_bio_extent_readpage()
{
endio_readpage_uptodate_page_status();
}
This is fine for sectorsize == PAGE_SIZE case, as for above loop we
should only hit one branch and then exit.
But for subpage, there is more work to be done in page status update:
- Page Unlock condition
Unlike regular page size == sectorsize case, we can no longer just
unlock a page.
Only the last reader of the page can unlock the page.
This means, we can unlock the page either in the while() loop, or in
the endio function.
- Page uptodate condition
Since we have multiple sectors to read for a page, we can only mark
the full page uptodate if all sectors are uptodate.
To handle both subpage and regular cases, introduce a pair of functions
to help handling page status update:
- begin_page_read()
For regular case, it does nothing.
For subpage case, it updates the reader counters so that later
end_page_read() can know who is the last one to unlock the page.
- end_page_read()
This is just endio_readpage_uptodate_page_status() renamed.
The original name is a little too long and too specific for endio.
The new thing added is the condition for page unlock.
Now for subpage data, we unlock the page if we're the last reader.
This does not only provide the basis for subpage data read, but also
hide the special handling of page read from the main read loop.
Also, since we're changing how the page lock is handled, there are two
existing error paths where we need to manually unlock the page before
calling begin_page_read().
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-02 10:28:36 +08:00
|
|
|
void btrfs_subpage_end_reader(const struct btrfs_fs_info *fs_info,
|
2023-12-12 12:58:37 +10:30
|
|
|
struct folio *folio, u64 start, u32 len);
|
btrfs: integrate page status update for data read path into begin/end_page_read
In btrfs data page read path, the page status update are handled in two
different locations:
btrfs_do_read_page()
{
while (cur <= end) {
/* No need to read from disk */
if (HOLE/PREALLOC/INLINE){
memset();
set_extent_uptodate();
continue;
}
/* Read from disk */
ret = submit_extent_page(end_bio_extent_readpage);
}
end_bio_extent_readpage()
{
endio_readpage_uptodate_page_status();
}
This is fine for sectorsize == PAGE_SIZE case, as for above loop we
should only hit one branch and then exit.
But for subpage, there is more work to be done in page status update:
- Page Unlock condition
Unlike regular page size == sectorsize case, we can no longer just
unlock a page.
Only the last reader of the page can unlock the page.
This means, we can unlock the page either in the while() loop, or in
the endio function.
- Page uptodate condition
Since we have multiple sectors to read for a page, we can only mark
the full page uptodate if all sectors are uptodate.
To handle both subpage and regular cases, introduce a pair of functions
to help handling page status update:
- begin_page_read()
For regular case, it does nothing.
For subpage case, it updates the reader counters so that later
end_page_read() can know who is the last one to unlock the page.
- end_page_read()
This is just endio_readpage_uptodate_page_status() renamed.
The original name is a little too long and too specific for endio.
The new thing added is the condition for page unlock.
Now for subpage data, we unlock the page if we're the last reader.
This does not only provide the basis for subpage data read, but also
hide the special handling of page read from the main read loop.
Also, since we're changing how the page lock is handled, there are two
existing error paths where we need to manually unlock the page before
calling begin_page_read().
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-02 10:28:36 +08:00
|
|
|
|
2023-12-12 12:58:37 +10:30
|
|
|
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);
|
2024-02-19 13:13:24 +10:30
|
|
|
void btrfs_folio_set_writer_lock(const struct btrfs_fs_info *fs_info,
|
|
|
|
struct folio *folio, u64 start, u32 len);
|
btrfs: only unlock the to-be-submitted ranges inside a folio
[SUBPAGE COMPRESSION LIMITS]
Currently inside writepage_delalloc(), if a delalloc range is going to
be submitted asynchronously (inline or compression, the page
dirty/writeback/unlock are all handled in at different time, not at the
submission time), then we return 1 and extent_writepage() will skip the
submission.
This is fine if every sector matches page size, but if a sector is
smaller than page size (aka, subpage case), then it can be very
problematic, for example for the following 64K page:
0 16K 32K 48K 64K
|/| |///////| |/|
| |
4K 52K
Where |/| is the dirty range we need to submit.
In the above case, we need the following different handling for the 3
ranges:
- [0, 4K) needs to be submitted for regular write
A single sector cannot be compressed.
- [16K, 32K) needs to be submitted for compressed write
- [48K, 52K) needs to be submitted for regular write.
Above, if we try to submit [16K, 32K) for compressed write, we will
return 1 and immediately, and without submitting the remaining
[48K, 52K) range.
Furthermore, since extent_writepage() will exit without unlocking any
sectors, the submitted range [0, 4K) will not have sector unlocked.
That's the reason why for now subpage is only allowed for full page
range.
[ENHANCEMENT]
- Introduce a submission bitmap at btrfs_bio_ctrl::submit_bitmap
This records which sectors will be submitted by extent_writepage_io().
This allows us to track which sectors needs to be submitted thus later
to be properly unlocked.
For asynchronously submitted range (inline/compression), the
corresponding bits will be cleared from that bitmap.
- Only return 1 if no sector needs to be submitted in
writepage_delalloc()
- Only submit sectors marked by submission bitmap inside
extent_writepage_io()
So we won't touch the asynchronously submitted part.
- Introduce btrfs_folio_end_writer_lock_bitmap() helper
This will only unlock the involved sectors specified by @bitmap
parameter, to avoid touching the range asynchronously submitted.
Please note that, since subpage compression is still limited to page
aligned range, this change is only a preparation for future sector
perfect compression support for subpage.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-02 14:29:06 +09:30
|
|
|
void btrfs_folio_end_writer_lock_bitmap(const struct btrfs_fs_info *fs_info,
|
|
|
|
struct folio *folio, unsigned long bitmap);
|
2024-02-19 13:13:24 +10:30
|
|
|
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);
|
2021-05-31 16:50:44 +08:00
|
|
|
|
2021-01-26 16:33:52 +08:00
|
|
|
/*
|
|
|
|
* Template for subpage related operations.
|
|
|
|
*
|
2023-12-12 12:58:37 +10:30
|
|
|
* btrfs_subpage_*() are for call sites where the folio has subpage attached and
|
|
|
|
* the range is ensured to be inside the folio's single page.
|
2021-01-26 16:33:52 +08:00
|
|
|
*
|
2023-12-12 12:58:37 +10:30
|
|
|
* btrfs_folio_*() are for call sites where the page can either be subpage
|
|
|
|
* specific or regular folios. The function will handle both cases.
|
|
|
|
* But the range still needs to be inside one single page.
|
2021-05-31 16:50:39 +08:00
|
|
|
*
|
2023-12-12 12:58:37 +10:30
|
|
|
* btrfs_folio_clamp_*() are similar to btrfs_folio_*(), except the range doesn't
|
2021-05-31 16:50:39 +08:00
|
|
|
* need to be inside the page. Those functions will truncate the range
|
|
|
|
* automatically.
|
2021-01-26 16:33:52 +08:00
|
|
|
*/
|
|
|
|
#define DECLARE_BTRFS_SUBPAGE_OPS(name) \
|
|
|
|
void btrfs_subpage_set_##name(const struct btrfs_fs_info *fs_info, \
|
2023-12-12 12:58:37 +10:30
|
|
|
struct folio *folio, u64 start, u32 len); \
|
2021-01-26 16:33:52 +08:00
|
|
|
void btrfs_subpage_clear_##name(const struct btrfs_fs_info *fs_info, \
|
2023-12-12 12:58:37 +10:30
|
|
|
struct folio *folio, u64 start, u32 len); \
|
2021-01-26 16:33:52 +08:00
|
|
|
bool btrfs_subpage_test_##name(const struct btrfs_fs_info *fs_info, \
|
2023-12-12 12:58:37 +10:30
|
|
|
struct folio *folio, u64 start, u32 len); \
|
|
|
|
void btrfs_folio_set_##name(const struct btrfs_fs_info *fs_info, \
|
|
|
|
struct folio *folio, u64 start, u32 len); \
|
|
|
|
void btrfs_folio_clear_##name(const struct btrfs_fs_info *fs_info, \
|
|
|
|
struct folio *folio, u64 start, u32 len); \
|
|
|
|
bool btrfs_folio_test_##name(const struct btrfs_fs_info *fs_info, \
|
|
|
|
struct folio *folio, u64 start, u32 len); \
|
|
|
|
void btrfs_folio_clamp_set_##name(const struct btrfs_fs_info *fs_info, \
|
|
|
|
struct folio *folio, u64 start, u32 len); \
|
|
|
|
void btrfs_folio_clamp_clear_##name(const struct btrfs_fs_info *fs_info, \
|
|
|
|
struct folio *folio, u64 start, u32 len); \
|
|
|
|
bool btrfs_folio_clamp_test_##name(const struct btrfs_fs_info *fs_info, \
|
|
|
|
struct folio *folio, u64 start, u32 len);
|
2021-01-26 16:33:52 +08:00
|
|
|
|
|
|
|
DECLARE_BTRFS_SUBPAGE_OPS(uptodate);
|
2021-03-25 15:14:37 +08:00
|
|
|
DECLARE_BTRFS_SUBPAGE_OPS(dirty);
|
2021-03-25 15:14:38 +08:00
|
|
|
DECLARE_BTRFS_SUBPAGE_OPS(writeback);
|
2021-05-31 16:50:45 +08:00
|
|
|
DECLARE_BTRFS_SUBPAGE_OPS(ordered);
|
2021-09-27 15:21:49 +08:00
|
|
|
DECLARE_BTRFS_SUBPAGE_OPS(checked);
|
2021-03-25 15:14:37 +08:00
|
|
|
|
|
|
|
bool btrfs_subpage_clear_and_test_dirty(const struct btrfs_fs_info *fs_info,
|
2023-12-12 12:58:37 +10:30
|
|
|
struct folio *folio, u64 start, u32 len);
|
2021-01-26 16:33:52 +08:00
|
|
|
|
btrfs: make __extent_writepage_io() to write specified range only
Function __extent_writepage_io() is designed to find all dirty ranges of
a page, and add the dirty ranges to the bio_ctrl for submission.
It requires all the dirtied ranges to be covered by an ordered extent.
It gets called in two locations, but one call site is not subpage aware:
- __extent_writepage()
It gets called when writepage_delalloc() returned 0, which means
writepage_delalloc() has handled delalloc for all subpage sectors
inside the page.
So this call site is OK.
- extent_write_locked_range()
This call site is utilized by zoned support, and in this case, we may
only run delalloc range for a subset of the page, like this: (64K page
size)
0 16K 32K 48K 64K
|/////| |///////| |
In the above case, if extent_write_locked_range() is only triggered for
range [0, 16K), __extent_writepage_io() would still try to submit
the dirty range of [32K, 48K), then it would not find any ordered
extent for it and triggers various ASSERT()s.
Fix this problem by:
- Introducing @start and @len parameters to specify the range
For the first call site, we just pass the whole page, and the behavior
is not touched, since run_delalloc_range() for the page should have
created all ordered extents for the page.
For the second call site, we avoid touching anything beyond the
range, thus avoiding the dirty range which is not yet covered by any
delalloc range.
- Making btrfs_folio_assert_not_dirty() subpage aware
The only caller is inside __extent_writepage_io(), and since that
caller now accepts a subpage range, we should also check the subpage
range other than the whole page.
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-02-16 14:33:41 +10:30
|
|
|
void btrfs_folio_assert_not_dirty(const struct btrfs_fs_info *fs_info,
|
|
|
|
struct folio *folio, u64 start, u32 len);
|
btrfs: refactor __extent_writepage_io() to do sector-by-sector submission
Unlike the bitmap usage inside raid56, for __extent_writepage_io() we
handle the subpage submission not sector-by-sector, but for each dirty
range we found.
This is not a big deal normally, as the subpage complex code is already
mostly optimized out by the compiler for x86_64.
However for the sake of consistency and for the future of subpage
sector-perfect compression support, this patch does:
- Extract the sector submission code into submit_one_sector()
- Add the needed code to extract the dirty bitmap for subpage case
There is a small pitfall for non-subpage case, as we cleared page
dirty before starting writeback, so we have to manually set
the default dirty_bitmap to 1 for such case.
- Use bitmap_and() to calculate the target sectors we need to submit
This is done for both subpage and non-subpage cases, and will later
be expanded to skip inline/compression ranges.
For x86_64, the dirty bitmap will be fixed to 1, with the length of 1,
so we're still doing the same workload per sector.
For larger page sizes, the overhead will be a little larger, as previous
we only need to do one extent_map lookup per-dirty-range, but now it
will be one extent_map lookup per-sector.
But that is the same frequency as x86_64, so we're just aligning the
behavior to x86_64.
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-08-07 14:31:54 +09:30
|
|
|
void btrfs_get_subpage_dirty_bitmap(struct btrfs_fs_info *fs_info,
|
|
|
|
struct folio *folio,
|
|
|
|
unsigned long *ret_bitmap);
|
2023-05-26 20:30:53 +08:00
|
|
|
void __cold btrfs_subpage_dump_bitmap(const struct btrfs_fs_info *fs_info,
|
2023-12-12 12:58:37 +10:30
|
|
|
struct folio *folio, u64 start, u32 len);
|
btrfs: subpage: fix writeback which does not have ordered extent
[BUG]
When running fsstress with subpage RW support, there are random
BUG_ON()s triggered with the following trace:
kernel BUG at fs/btrfs/file-item.c:667!
Internal error: Oops - BUG: 0 [#1] SMP
CPU: 1 PID: 3486 Comm: kworker/u13:2 5.11.0-rc4-custom+ #43
Hardware name: Radxa ROCK Pi 4B (DT)
Workqueue: btrfs-worker-high btrfs_work_helper [btrfs]
pstate: 60000005 (nZCv daif -PAN -UAO -TCO BTYPE=--)
pc : btrfs_csum_one_bio+0x420/0x4e0 [btrfs]
lr : btrfs_csum_one_bio+0x400/0x4e0 [btrfs]
Call trace:
btrfs_csum_one_bio+0x420/0x4e0 [btrfs]
btrfs_submit_bio_start+0x20/0x30 [btrfs]
run_one_async_start+0x28/0x44 [btrfs]
btrfs_work_helper+0x128/0x1b4 [btrfs]
process_one_work+0x22c/0x430
worker_thread+0x70/0x3a0
kthread+0x13c/0x140
ret_from_fork+0x10/0x30
[CAUSE]
Above BUG_ON() means there is some bio range which doesn't have ordered
extent, which indeed is worth a BUG_ON().
Unlike regular sectorsize == PAGE_SIZE case, in subpage we have extra
subpage dirty bitmap to record which range is dirty and should be
written back.
This means, if we submit bio for a subpage range, we do not only need to
clear page dirty, but also need to clear subpage dirty bits.
In __extent_writepage_io(), we will call btrfs_page_clear_dirty() for
any range we submit a bio.
But there is loophole, if we hit a range which is beyond i_size, we just
call btrfs_writepage_endio_finish_ordered() to finish the ordered io,
then break out, without clearing the subpage dirty.
This means, if we hit above branch, the subpage dirty bits are still
there, if other range of the page get dirtied and we need to writeback
that page again, we will submit bio for the old range, leaving a wild
bio range which doesn't have ordered extent.
[FIX]
Fix it by always calling btrfs_page_clear_dirty() in
__extent_writepage_io().
Also to avoid such problem from happening again, add a new assert,
btrfs_page_assert_not_dirty(), to make sure both page dirty and subpage
dirty bits are cleared before exiting __extent_writepage_io().
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-26 14:34:58 +08:00
|
|
|
|
2021-01-26 16:33:47 +08:00
|
|
|
#endif
|