Skip to contentSkip to conversation

btrfs: prepare raid56 and scrub to support bs > ps cases

PATCH In review Qu Wenruo 1 participant 4 messages Sep 12, 2025 – Sep 17, 2025 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

cover btrfs: prepare raid56 and scrub to support bs > ps cases

After the previous compression bs > ps preparation, this series focus on raid56 and scrub.

Both raid56 and scrub are using a page array storing their stripes.

Thankfully both are already using physical memory addresses for checksum calculation, thus there are no internal code to do the checksum handling.

Just convert the involved arraies (and some RAID56 internal page related members) to folio arraies will handle most thing properly.

Now the remaining code is mostly encoded write, which shares some infrastructure with send, which makes the conversion more complex than I thought.

Qu Wenruo (2):
btrfs: prepare raid56 to support bs > ps cases
btrfs: prepare scrub to support bs > ps cases

 fs/btrfs/misc.h   |   5 ++
 fs/btrfs/raid56.c | 180 +++++++++++++++++++++++-----------------------
 fs/btrfs/raid56.h |  26 ++++---
 fs/btrfs/scrub.c  |  51 +++++++------
 4 files changed, 142 insertions(+), 120 deletions(-)
Signature · 1 line
2.50.1
author
#2 lore raw

PATCH 2/2 btrfs: prepare scrub to support bs > ps cases

This involves:

- Migrate scrub_stripe::pages[] to folios[]

- Use btrfs_alloc_folio_array() and folio_put() to alloc above array.

- Migrate scrub_stripe_get_kaddr() and scrub_stripe_get_paddr() to use folio interfaces

- Migrate raid56_parity_cache_data_pages() to raid56_parity_cache_data_folios()
Since scrub is the only caller still using pages.

Since most scrub code is based on kaddr/paddr, the migration itself is pretty straightforward.

---
 fs/btrfs/raid56.c | 15 ++++----------
 fs/btrfs/raid56.h |  4 ++--
 fs/btrfs/scrub.c  | 51 +++++++++++++++++++++++++++--------------------
 3 files changed, 35 insertions(+), 35 deletions(-)
fs/btrfs/raid56.c +4 -11
index ac94335dd262..4074ff4ddb1d 100644
@@ -2842,11 +2842,11 @@ void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio)
  * This is for scrub call sites where we already have correct data contents.
  * This allows us to avoid reading data stripes again.
  *
- * Unfortunately here we have to do page copy, other than reusing the pages.
+ * Unfortunately here we have to do folio copy, other than reusing the pages.
  * This is due to the fact rbio has its own page management for its cache.
  */
-void raid56_parity_cache_data_pages(struct btrfs_raid_bio *rbio,
-				    struct page **data_pages, u64 data_logical)
+void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
+				     struct folio **data_folios, u64 data_logical)
 {
 	struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
 	const u64 offset_in_full_stripe = data_logical -
@@ -2855,12 +2855,6 @@ void raid56_parity_cache_data_pages(struct btrfs_raid_bio *rbio,
 	const u32 min_folio_shift = PAGE_SHIFT + fs_info->block_min_order;
 	int ret;
 
-	/*
-	 * The caller is not yet converted to follow min_folio_shift. So our
-	 * minimal folio order must be 0 for now.
-	 */
-	ASSERT(fs_info->block_min_order == 0);
-
 	/*
 	 * If we hit ENOMEM temporarily, but later at
 	 * raid56_parity_submit_scrub_rbio() time it succeeded, we just do
@@ -2880,8 +2874,7 @@ void raid56_parity_cache_data_pages(struct btrfs_raid_bio *rbio,
 	for (int cur = offset_in_full_stripe; cur < offset_in_full_stripe + BTRFS_STRIPE_LEN;
 	     cur += min_folio_size) {
 		struct folio *dest = rbio->stripe_folios[cur >> min_folio_shift];
-		struct folio *src = page_folio(data_pages[(cur - offset_in_full_stripe) >>
-							  min_folio_shift]);
+		struct folio *src = data_folios[(cur - offset_in_full_stripe) >> min_folio_shift];
 
 		ASSERT(dest);
 		ASSERT(src);
fs/btrfs/raid56.h +2 -2
index ddf6a7687eb6..5662a3a2f04b 100644
@@ -207,8 +207,8 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
 				unsigned long *dbitmap, int stripe_nsectors);
 void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio);
 
-void raid56_parity_cache_data_pages(struct btrfs_raid_bio *rbio,
-				    struct page **data_pages, u64 data_logical);
+void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
+				     struct folio **data_folios, u64 data_logical);
 
 int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
 void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
fs/btrfs/scrub.c +29 -22

113 lines not on this page · raw message

Signature · 1 line
2.50.1
author
#1 lore raw

PATCH 1/2 btrfs: prepare raid56 to support bs > ps cases

In reply to Qu Wenruo

This involves the following conversion:

- btrfs_raid_bio::nr_pages -> nr_folios
- btrfs_raid_bio::stripe_npages -> stripe_nfolios
- btrfs_raid_bio::stripe_pages[] -> stripe_folios[]
- Involved comments using "page"
- Remove the PAGE_SIZE alignment check against sectorsize

There is one exception, function raid56_parity_cache_data_pages() is utilized by scrub, and it doesn't support bs > ps yet.

So add an ASSERT() inside that function to make sure it's only called when bs <= ps.

---
 fs/btrfs/misc.h   |   5 ++
 fs/btrfs/raid56.c | 181 ++++++++++++++++++++++++----------------------
 fs/btrfs/raid56.h |  22 ++++--
 3 files changed, 115 insertions(+), 93 deletions(-)
fs/btrfs/misc.h +5 -0
index 60f9b000d644..3bedffbd51ba 100644
@@ -214,4 +214,9 @@ static inline u64 folio_end(struct folio *folio)
 	return folio_pos(folio) + folio_size(folio);
 }
 
+static inline phys_addr_t folio_to_phys(const struct folio *folio)
+{
+	return page_to_phys(folio_page(folio, 0));
+}
+
 #endif
fs/btrfs/raid56.c +96 -85

347 lines not on this page · raw message

fs/btrfs/raid56.h +14 -8
index 0d7b4c2fb6ae..ddf6a7687eb6 100644
@@ -64,8 +64,11 @@ struct btrfs_raid_bio {
 	 */
 	enum btrfs_rbio_ops operation;
 
-	/* How many pages there are for the full stripe including P/Q */
-	u16 nr_pages;
+	/*
+	 * How many folios there are for the full stripe including P/Q.
+	 * The folio size should be based on the fs_info::block_min_order.
+	 */
+	u16 nr_folios;
 
 	/* How many sectors there are for the full stripe including P/Q */
 	u16 nr_sectors;
@@ -76,8 +79,8 @@ struct btrfs_raid_bio {
 	/* Number of all stripes (including P/Q) */
 	u8 real_stripes;
 
-	/* How many pages there are for each stripe */
-	u8 stripe_npages;
+	/* How many folios there are for each stripe. */
+	u8 stripe_nfolios;
 
 	/* How many sectors there are for each stripe */
 	u8 stripe_nsectors;
@@ -110,17 +113,20 @@ struct btrfs_raid_bio {
 	 */
 
 	/*
-	 * Pointers to pages that we allocated for reading/writing stripes
+	 * Pointers to folios that we allocated for reading/writing stripes
 	 * directly from the disk (including P/Q).
+	 *
+	 * All folios are following fs_info::block_min_order, so that no block
+	 * will cross folio boundary.
 	 */
-	struct page **stripe_pages;
+	struct folio **stripe_folios;
 
 	/* Pointers to the sectors in the bio_list, for faster lookup */
 	struct sector_ptr *bio_sectors;
 
 	/*
-	 * For subpage support, we need to map each sector to above
-	 * stripe_pages.
+	 * For bs < ps support, we need to map each sector to above
+	 * stripe_folios.
 	 */
 	struct sector_ptr *stripe_sectors;
 
Signature · 1 line
2.50.1
author
#3 lore raw
In reply to Qu Wenruo
Quoted 9 lines · Qu Wenruo

After the previous compression bs > ps preparation, this series focus on raid56 and scrub.

Both raid56 and scrub are using a page array storing their stripes.

Thankfully both are already using physical memory addresses for checksum calculation, thus there are no internal code to do the checksum handling.

Quoted 6 lines

Just convert the involved arraies (and some RAID56 internal page related members) to folio arraies will handle most thing properly.

Now the remaining code is mostly encoded write, which shares some infrastructure with send, which makes the conversion more complex than I thought.

Please drop the series.

The scrub part is fine, but the RAID56 shouldn't migrate to the mandatory large folios.

Currently we're relying on minimal folio size for filemap, but in the future direct IO will pass folios that are not meeting our minimal order.

If we force RAID56 to use large folios, it will need to revert back to the current page based solution to support direct IO again.

For now, I'll just disable RAID56 for bs > ps support.

Thanks,
Qu

Quoted 11 lines

Qu Wenruo (2):
btrfs: prepare raid56 to support bs > ps cases
btrfs: prepare scrub to support bs > ps cases

  fs/btrfs/misc.h   |   5 ++
  fs/btrfs/raid56.c | 180 +++++++++++++++++++++++-----------------------
  fs/btrfs/raid56.h |  26 ++++---
  fs/btrfs/scrub.c  |  51 +++++++------
  4 files changed, 142 insertions(+), 120 deletions(-)