Skip to contentSkip to conversation

btrfs: make subpage reader/writer counter to be sector aware

PATCH Superseded Qu Wenruo 3 participants 8 messages Feb 14, 2024 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

cover btrfs: make subpage reader/writer counter to be sector aware

This can be fetched from github, and the branch would be utilized for all newer subpage delalloc update to support full sector sized compression and zoned:
https://github.com/adam900710/linux/tree/subpage_delalloc

Currently we just trace subpage reader/writer counter using an atomic.

It's fine for the current subpage usage, but for the future, we want to be aware of which subpage sector is locked inside a page, for proper compression (we only support full page compression for now) and zoned support.

So here we introduce a new bitmap, called locked bitmap, to trace which sector is locked for read/write.

And since reader/writer are both exclusive (to each other and to the same type of lock), we can safely use the same bitmap for both reader and writer.

In theory we can use the bitmap (the weight of the locked bitmap) to indicate how many bytes are under reader/write lock, but it's not possible yet:

- No weight support for bitmap range
The bitmap API only provides bitmap_weight(), which always starts at bit 0.

- Need to distinguish read/write lock

Thus we still keep the reader/writer atomic counter.

Qu Wenruo (3):
btrfs: unexport btrfs_subpage_start_writer() and
btrfs_subpage_end_and_test_writer()
btrfs: subpage: make reader lock to utilize bitmap
btrfs: subpage: make writer lock to utilize bitmap

 fs/btrfs/subpage.c | 70 ++++++++++++++++++++++++++++++++++++----------
 fs/btrfs/subpage.h | 16 +++++++----
 2 files changed, 66 insertions(+), 20 deletions(-)
Signature · 1 line
2.43.1
author
#1 lore raw

PATCH 1/3 btrfs: unexport btrfs_subpage_start_writer() and btrfs_subpage_end_and_test_writer()

Both functions are introduced in commit 1e1de38792e0 ("btrfs: make process_one_page() to handle subpage locking"), but they are never utilized out of subpage code.

So just unexport them.

Fixes 1e1de38792e0 ("btrfs: make process_one_page() to handle subpage locking")
---
 fs/btrfs/subpage.c | 8 ++++----
 fs/btrfs/subpage.h | 4 ----
 2 files changed, 4 insertions(+), 8 deletions(-)
fs/btrfs/subpage.c +4 -4
index 0e49dab8dad2..24f8be565a61 100644
@@ -290,8 +290,8 @@ static void btrfs_subpage_clamp_range(struct folio *folio, u64 *start, u32 *len)
 			     orig_start + orig_len) - *start;
 }
 
-void btrfs_subpage_start_writer(const struct btrfs_fs_info *fs_info,
-				struct folio *folio, u64 start, u32 len)
+static void btrfs_subpage_start_writer(const struct btrfs_fs_info *fs_info,
+				       struct folio *folio, u64 start, u32 len)
 {
 	struct btrfs_subpage *subpage = folio_get_private(folio);
 	const int nbits = (len >> fs_info->sectorsize_bits);
@@ -304,8 +304,8 @@ void btrfs_subpage_start_writer(const struct btrfs_fs_info *fs_info,
 	ASSERT(ret == nbits);
 }
 
-bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_info,
-				       struct folio *folio, u64 start, u32 len)
+static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_info,
+					      struct folio *folio, u64 start, u32 len)
 {
 	struct btrfs_subpage *subpage = folio_get_private(folio);
 	const int nbits = (len >> fs_info->sectorsize_bits);
fs/btrfs/subpage.h +0 -4
index 55fc42db707e..97ba2c100b0b 100644
@@ -98,10 +98,6 @@ void btrfs_subpage_start_reader(const struct btrfs_fs_info *fs_info,
 void btrfs_subpage_end_reader(const struct btrfs_fs_info *fs_info,
 			      struct folio *folio, u64 start, u32 len);
 
-void btrfs_subpage_start_writer(const struct btrfs_fs_info *fs_info,
-				struct folio *folio, u64 start, u32 len);
-bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_info,
-				       struct folio *folio, u64 start, u32 len);
 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,
Signature · 1 line
2.43.1
author
#2 lore raw

PATCH 2/3 btrfs: subpage: make reader lock to utilize bitmap

In reply to Qu Wenruo

Currently btrfs_subpage utilized its atomic member @reader to manage the reader counter.

However the reader counter is only utilized to prevent the page got released/unlocked when we still have reads underway.

In that use case, we don't really allow multiple readers on the same subpage sector.

So here we can introduce a new locked bitmap to represent exactly which subpage range is locked for read.

In theory we can remove btrfs_subpage::reader as it's just the set bits of the new locked bitmap.
But unfortunately bitmap doesn't provide such handy API yet, so we still keep the reader counter.

---
 fs/btrfs/subpage.c | 45 +++++++++++++++++++++++++++++++++++----------
 fs/btrfs/subpage.h | 12 +++++++++++-
 2 files changed, 46 insertions(+), 11 deletions(-)
fs/btrfs/subpage.c +35 -10
index 24f8be565a61..bd5c4993dcb9 100644
@@ -111,6 +111,9 @@ void btrfs_init_subpage_info(struct btrfs_subpage_info *subpage_info, u32 sector
 	subpage_info->checked_offset = cur;
 	cur += nr_bits;
 
+	subpage_info->locked_offset = cur;
+	cur += nr_bits;
+
 	subpage_info->total_nr_bits = cur;
 }
 
@@ -237,28 +240,59 @@ static void btrfs_subpage_assert(const struct btrfs_fs_info *fs_info,
 		       start + len <= folio_pos(folio) + PAGE_SIZE);
 }
 
+#define subpage_calc_start_bit(fs_info, folio, name, start, len)	\
+({									\
+	unsigned int start_bit;						\
+									\
+	btrfs_subpage_assert(fs_info, folio, start, len);		\
+	start_bit = offset_in_page(start) >> fs_info->sectorsize_bits;	\
+	start_bit += fs_info->subpage_info->name##_offset;		\
+	start_bit;							\
+})
+
 void btrfs_subpage_start_reader(const struct btrfs_fs_info *fs_info,
 				struct folio *folio, u64 start, u32 len)
 {
 	struct btrfs_subpage *subpage = folio_get_private(folio);
+	const int start_bit = subpage_calc_start_bit(fs_info, folio, locked, start, len);
 	const int nbits = len >> fs_info->sectorsize_bits;
+	unsigned long flags;
+
 
 	btrfs_subpage_assert(fs_info, folio, start, len);
 
+	spin_lock_irqsave(&subpage->lock, flags);
+	/*
+	 * Even it's just for reading the page, no one should have locked the subpage
+	 * range.
+	 */
+	ASSERT(bitmap_test_range_all_zero(subpage->bitmaps, start_bit, nbits));
+	bitmap_set(subpage->bitmaps, start_bit, nbits);
 	atomic_add(nbits, &subpage->readers);
+	spin_unlock_irqrestore(&subpage->lock, flags);
 }
 
 void btrfs_subpage_end_reader(const struct btrfs_fs_info *fs_info,
 			      struct folio *folio, u64 start, u32 len)
 {
 	struct btrfs_subpage *subpage = folio_get_private(folio);
+	const int start_bit = subpage_calc_start_bit(fs_info, folio, locked,
+						     start, len);
 	const int nbits = len >> fs_info->sectorsize_bits;
+	unsigned long flags;
 	bool is_data;
 	bool last;
 
 	btrfs_subpage_assert(fs_info, folio, start, len);
 	is_data = is_data_inode(folio->mapping->host);
+
+	spin_lock_irqsave(&subpage->lock, flags);
+
+	/* The range should have already be locked. */
+	ASSERT(bitmap_test_range_all_set(subpage->bitmaps, start_bit, nbits));
 	ASSERT(atomic_read(&subpage->readers) >= nbits);
+
+	bitmap_clear(subpage->bitmaps, start_bit, nbits);
 	last = atomic_sub_and_test(nbits, &subpage->readers);
 
 	/*
@@ -270,6 +304,7 @@ void btrfs_subpage_end_reader(const struct btrfs_fs_info *fs_info,
 	 */
 	if (is_data && last)
 		folio_unlock(folio);
+	spin_unlock_irqrestore(&subpage->lock, flags);
 }
 
 static void btrfs_subpage_clamp_range(struct folio *folio, u64 *start, u32 *len)
@@ -365,16 +400,6 @@ void btrfs_folio_end_writer_lock(const struct btrfs_fs_info *fs_info,
 		folio_unlock(folio);
 }
 
-#define subpage_calc_start_bit(fs_info, folio, name, start, len)	\
-({									\
-	unsigned int start_bit;						\
-									\
-	btrfs_subpage_assert(fs_info, folio, start, len);		\
-	start_bit = offset_in_page(start) >> fs_info->sectorsize_bits;	\
-	start_bit += fs_info->subpage_info->name##_offset;		\
-	start_bit;							\
-})
-
 #define subpage_test_bitmap_all_set(fs_info, subpage, name)		\
 	bitmap_test_range_all_set(subpage->bitmaps,			\
 			fs_info->subpage_info->name##_offset,		\
fs/btrfs/subpage.h +11 -1
index 97ba2c100b0b..b6dc013b0fdc 100644
@@ -33,7 +33,7 @@ struct btrfs_subpage_info {
 	unsigned int total_nr_bits;
 
 	/*
-	 * *_start indicates where the bitmap starts, the length is always
+	 * *_offset indicates where the bitmap starts, the length is always
 	 * @bitmap_size, which is calculated from PAGE_SIZE / sectorsize.
 	 */
 	unsigned int uptodate_offset;
@@ -41,6 +41,16 @@ struct btrfs_subpage_info {
 	unsigned int writeback_offset;
 	unsigned int ordered_offset;
 	unsigned int checked_offset;
+
+	/*
+	 * For locked bitmaps, normally it's subpage representation for folio
+	 * Locked flag, but metadata is different:
+	 *
+	 * - Metadata doesn't really lock the folio
+	 *   It's just to prevent page::private get cleared before the last
+	 *   end_page_read().
+	 */
+	unsigned int locked_offset;
 };
 
 /*
Signature · 1 line
2.43.1
author
#3 lore raw

PATCH 3/3 btrfs: subpage: make writer lock to utilize bitmap

In reply to Qu Wenruo

For the writer counter, it's pretty much the same as the reader counter, and they are exclusive.

So it's pretty reasonable to move them to the new locked bitmap.

---
 fs/btrfs/subpage.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
fs/btrfs/subpage.c +16 -1
index bd5c4993dcb9..5d99e8d1b5ac 100644
@@ -329,24 +329,35 @@ static void btrfs_subpage_start_writer(const struct btrfs_fs_info *fs_info,
 				       struct folio *folio, u64 start, u32 len)
 {
 	struct btrfs_subpage *subpage = folio_get_private(folio);
+	const int start_bit = subpage_calc_start_bit(fs_info, folio, locked,
+						     start, len);
 	const int nbits = (len >> fs_info->sectorsize_bits);
+	unsigned long flags;
 	int ret;
 
 	btrfs_subpage_assert(fs_info, folio, start, len);
 
+	spin_lock_irqsave(&subpage->lock, flags);
 	ASSERT(atomic_read(&subpage->readers) == 0);
+	ASSERT(bitmap_test_range_all_zero(subpage->bitmaps, start_bit, nbits));
 	ret = atomic_add_return(nbits, &subpage->writers);
 	ASSERT(ret == nbits);
+	spin_unlock_irqrestore(&subpage->lock, flags);
 }
 
 static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_info,
 					      struct folio *folio, u64 start, u32 len)
 {
 	struct btrfs_subpage *subpage = folio_get_private(folio);
+	const int start_bit = subpage_calc_start_bit(fs_info, folio, locked,
+						     start, len);
 	const int nbits = (len >> fs_info->sectorsize_bits);
+	unsigned long flags;
+	bool last;
 
 	btrfs_subpage_assert(fs_info, folio, start, len);
 
+	spin_lock_irqsave(&subpage->lock, flags);
 	/*
 	 * We have call sites passing @lock_page into
 	 * extent_clear_unlock_delalloc() for compression path.
@@ -358,7 +369,11 @@ static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_inf
 		return true;
 
 	ASSERT(atomic_read(&subpage->writers) >= nbits);
-	return atomic_sub_and_test(nbits, &subpage->writers);
+	/* The target range should have been locked. */
+	ASSERT(bitmap_test_range_all_set(subpage->bitmaps, start_bit, nbits));
+	last = atomic_sub_and_test(nbits, &subpage->writers);
+	spin_unlock_irqrestore(&subpage->lock, flags);
+	return last;
 }
 
 /*
Signature · 1 line
2.43.1
#4 lore raw
In reply to Qu Wenruo
Quoted 10 lines · Qu Wenruo

This can be fetched from github, and the branch would be utilized for all newer subpage delalloc update to support full sector sized compression and zoned:
https://github.com/adam900710/linux/tree/subpage_delalloc

Currently we just trace subpage reader/writer counter using an atomic.

It's fine for the current subpage usage, but for the future, we want to be aware of which subpage sector is locked inside a page, for proper compression (we only support full page compression for now) and zoned support.

The logic of the patches seems good and self-consistent to me, I don't see any issues.

However, I think it would be helpful to at least see the client code to motivate the bitmap a bit more for the ignorant :)

Also, from a semi-cursory inspection, it looks like this relies on extent locking to ensure that multiple threads don't collide on the subpage bitmap, is that correct? You should check with Josef that his plans with getting rid of the extent locking don't clash with this.

Thanks,
Boris

Quoted 33 lines

So here we introduce a new bitmap, called locked bitmap, to trace which sector is locked for read/write.

And since reader/writer are both exclusive (to each other and to the same type of lock), we can safely use the same bitmap for both reader and writer.

In theory we can use the bitmap (the weight of the locked bitmap) to indicate how many bytes are under reader/write lock, but it's not possible yet:

- No weight support for bitmap range
The bitmap API only provides bitmap_weight(), which always starts at bit 0.

- Need to distinguish read/write lock

Thus we still keep the reader/writer atomic counter.

Qu Wenruo (3):
btrfs: unexport btrfs_subpage_start_writer() and
btrfs_subpage_end_and_test_writer()
btrfs: subpage: make reader lock to utilize bitmap
btrfs: subpage: make writer lock to utilize bitmap

 fs/btrfs/subpage.c | 70 ++++++++++++++++++++++++++++++++++++----------
 fs/btrfs/subpage.h | 16 +++++++----
 2 files changed, 66 insertions(+), 20 deletions(-)
Signature · 1 line
2.43.1
#5 lore raw
Quoted 12 lines · Boris Burkov
Quoted 10 lines · Qu Wenruo

This can be fetched from github, and the branch would be utilized for all newer subpage delalloc update to support full sector sized compression and zoned:
https://github.com/adam900710/linux/tree/subpage_delalloc

Currently we just trace subpage reader/writer counter using an atomic.

It's fine for the current subpage usage, but for the future, we want to be aware of which subpage sector is locked inside a page, for proper compression (we only support full page compression for now) and zoned support.

Quoted 5 lines

The logic of the patches seems good and self-consistent to me, I don't see any issues.

However, I think it would be helpful to at least see the client code to motivate the bitmap a bit more for the ignorant :)

Sure, if needed I can include them into the incoming subpage delalloc patchset.

Quoted 4 lines

Also, from a semi-cursory inspection, it looks like this relies on extent locking to ensure that multiple threads don't collide on the subpage bitmap, is that correct?

The current plan is to make find_lock_delalloc_range() to always lock all the ranges inside the page, at least beyond the end of the page.

The main work flow would look like this:

find_lock_delalloc_range()

{
	int cur = page_offset(page);

	/*
	 * Subpage, already locked, just grab the next locked range
	 * using the locked bitmap.
	 */
	if (btrfs_is_subpage() && write_count > 0)
		return grab_the_next_locked_range();

	while (cur < page_end(page)) {
		/*
		 * The old find and lock code, including
		 * the extent locking
		 */
		cur = locked_range_end();
	}
	*start = the_first_locked_range_start;
	*end = the_first_locked_range_end;
}

So for non-subpage cases, it's the same.
For subpage cases, the page would be kept locked until all its subpage sectors are written.
(But would need extra cleanup if we hit some error during subpage sector write)

And the above workflow is still being coded, not yet tested to see if there is anything fundamentally wrong, thus it may change.

Quoted 2 lines

You should check with Josef that his
plans with getting rid of the extent locking don't clash with this.

It would still conflict, but the extent locking part would be the same as usual, so I believe the conflict can be easily resolved.

And I'm pretty happy to help solving the conflicts if needed.

Thanks,
Qu

Quoted 38 lines

Thanks,
Boris

Quoted 33 lines

So here we introduce a new bitmap, called locked bitmap, to trace which sector is locked for read/write.

And since reader/writer are both exclusive (to each other and to the same type of lock), we can safely use the same bitmap for both reader and writer.

In theory we can use the bitmap (the weight of the locked bitmap) to indicate how many bytes are under reader/write lock, but it's not possible yet:

- No weight support for bitmap range
The bitmap API only provides bitmap_weight(), which always starts at bit 0.

- Need to distinguish read/write lock

Thus we still keep the reader/writer atomic counter.

Qu Wenruo (3):
btrfs: unexport btrfs_subpage_start_writer() and
btrfs_subpage_end_and_test_writer()
btrfs: subpage: make reader lock to utilize bitmap
btrfs: subpage: make writer lock to utilize bitmap

  fs/btrfs/subpage.c | 70 ++++++++++++++++++++++++++++++++++++----------
  fs/btrfs/subpage.h | 16 +++++++----
  2 files changed, 66 insertions(+), 20 deletions(-)

--
2.43.1

#6 lore raw
Quoted 65 lines · Qu Wenruo
Quoted 12 lines · Boris Burkov
Quoted 10 lines · Qu Wenruo

This can be fetched from github, and the branch would be utilized for all newer subpage delalloc update to support full sector sized compression and zoned:
https://github.com/adam900710/linux/tree/subpage_delalloc

Currently we just trace subpage reader/writer counter using an atomic.

It's fine for the current subpage usage, but for the future, we want to be aware of which subpage sector is locked inside a page, for proper compression (we only support full page compression for now) and zoned support.

Quoted 5 lines

The logic of the patches seems good and self-consistent to me, I don't see any issues.

However, I think it would be helpful to at least see the client code to motivate the bitmap a bit more for the ignorant :)

Sure, if needed I can include them into the incoming subpage delalloc patchset.

Quoted 4 lines

Also, from a semi-cursory inspection, it looks like this relies on extent locking to ensure that multiple threads don't collide on the subpage bitmap, is that correct?

The current plan is to make find_lock_delalloc_range() to always lock all the ranges inside the page, at least beyond the end of the page.

The main work flow would look like this:

find_lock_delalloc_range()

{
	int cur = page_offset(page);

	/*
	 * Subpage, already locked, just grab the next locked range
	 * using the locked bitmap.
	 */
	if (btrfs_is_subpage() && write_count > 0)
		return grab_the_next_locked_range();

	while (cur < page_end(page)) {
		/*
		 * The old find and lock code, including
		 * the extent locking
		 */
		cur = locked_range_end();
	}
	*start = the_first_locked_range_start;
	*end = the_first_locked_range_end;
}

So for non-subpage cases, it's the same.
For subpage cases, the page would be kept locked until all its subpage sectors are written.
(But would need extra cleanup if we hit some error during subpage sector write)

And the above workflow is still being coded, not yet tested to see if there is anything fundamentally wrong, thus it may change.

Quoted 7 lines
Quoted 2 lines

You should check with Josef that his
plans with getting rid of the extent locking don't clash with this.

It would still conflict, but the extent locking part would be the same as usual, so I believe the conflict can be easily resolved.

And I'm pretty happy to help solving the conflicts if needed.

By conflict, I meant logically/conceptually, not in terms of git merge conflicts.

Right now, AFAICT, your code relies on the fact that the extent is locked to ensure that two reads don't trip on the bitmap. If Josef takes that out, does the assumption still hold? Page lock gets taken after modifying the bitmap, right?

Sorry if I am misunderstanding you.

Quoted 42 lines

Thanks,
Qu

Quoted 38 lines

Thanks,
Boris

Quoted 33 lines

So here we introduce a new bitmap, called locked bitmap, to trace which sector is locked for read/write.

And since reader/writer are both exclusive (to each other and to the same type of lock), we can safely use the same bitmap for both reader and writer.

In theory we can use the bitmap (the weight of the locked bitmap) to indicate how many bytes are under reader/write lock, but it's not possible yet:

- No weight support for bitmap range
The bitmap API only provides bitmap_weight(), which always starts at bit 0.

- Need to distinguish read/write lock

Thus we still keep the reader/writer atomic counter.

Qu Wenruo (3):
btrfs: unexport btrfs_subpage_start_writer() and
btrfs_subpage_end_and_test_writer()
btrfs: subpage: make reader lock to utilize bitmap
btrfs: subpage: make writer lock to utilize bitmap

  fs/btrfs/subpage.c | 70 ++++++++++++++++++++++++++++++++++++----------
  fs/btrfs/subpage.h | 16 +++++++----
  2 files changed, 66 insertions(+), 20 deletions(-)

--
2.43.1

#7 lore raw
Quoted 72 lines · Boris Burkov
Quoted 71 lines · Qu Wenruo
Quoted 12 lines · Boris Burkov
Quoted 10 lines · Qu Wenruo

This can be fetched from github, and the branch would be utilized for all newer subpage delalloc update to support full sector sized compression and zoned:
https://github.com/adam900710/linux/tree/subpage_delalloc

Currently we just trace subpage reader/writer counter using an atomic.

It's fine for the current subpage usage, but for the future, we want to be aware of which subpage sector is locked inside a page, for proper compression (we only support full page compression for now) and zoned support.

Quoted 5 lines

The logic of the patches seems good and self-consistent to me, I don't see any issues.

However, I think it would be helpful to at least see the client code to motivate the bitmap a bit more for the ignorant :)

Sure, if needed I can include them into the incoming subpage delalloc patchset.

Quoted 4 lines

Also, from a semi-cursory inspection, it looks like this relies on extent locking to ensure that multiple threads don't collide on the subpage bitmap, is that correct?

The current plan is to make find_lock_delalloc_range() to always lock all the ranges inside the page, at least beyond the end of the page.

The main work flow would look like this:

find_lock_delalloc_range()

{
	int cur = page_offset(page);

	/*
	 * Subpage, already locked, just grab the next locked range
	 * using the locked bitmap.
	 */
	if (btrfs_is_subpage() && write_count > 0)
		return grab_the_next_locked_range();

	while (cur < page_end(page)) {
		/*
		 * The old find and lock code, including
		 * the extent locking
		 */
		cur = locked_range_end();
	}
	*start = the_first_locked_range_start;
	*end = the_first_locked_range_end;
}

So for non-subpage cases, it's the same.
For subpage cases, the page would be kept locked until all its subpage sectors are written.
(But would need extra cleanup if we hit some error during subpage sector write)

And the above workflow is still being coded, not yet tested to see if there is anything fundamentally wrong, thus it may change.

Quoted 2 lines

You should check with Josef that his
plans with getting rid of the extent locking don't clash with this.

It would still conflict, but the extent locking part would be the same as usual, so I believe the conflict can be easily resolved.

Quoted 7 lines
Quoted 1 line

And I'm pretty happy to help solving the conflicts if needed.

By conflict, I meant logically/conceptually, not in terms of git merge conflicts.

Right now, AFAICT, your code relies on the fact that the extent is locked to ensure that two reads don't trip on the bitmap.

Read and write are ensured to not happen on the same page by page lock/writeback flags.

If Josef takes extent locking away, it's still fine.

Quoted 3 lines

If Josef takes
that out, does the assumption still hold? Page lock gets taken after modifying the bitmap, right?

The page is already locked before taking the bitmap.

The page is locked in extent_write_cache_pages(), while we take that locked page and update the bitmap in find_lock_delalloc_range().

extent_write_cache_pages()
|- folio_trylock() << Page locked
|- __extent_writepages()
|- writepage_delalloc()
|- find_lock_delalloc_range() << Update lock bitmap

The whole change is to address the page unlock part, so that the whole page can only be unlocked by the last delalloc range of the page.

Thanks,
Qu

Quoted 45 lines

Sorry if I am misunderstanding you.

Quoted 42 lines

Thanks,
Qu

Quoted 38 lines

Thanks,
Boris

Quoted 33 lines

So here we introduce a new bitmap, called locked bitmap, to trace which sector is locked for read/write.

And since reader/writer are both exclusive (to each other and to the same type of lock), we can safely use the same bitmap for both reader and writer.

In theory we can use the bitmap (the weight of the locked bitmap) to indicate how many bytes are under reader/write lock, but it's not possible yet:

- No weight support for bitmap range
The bitmap API only provides bitmap_weight(), which always starts at bit 0.

- Need to distinguish read/write lock

Thus we still keep the reader/writer atomic counter.

Qu Wenruo (3):
btrfs: unexport btrfs_subpage_start_writer() and
btrfs_subpage_end_and_test_writer()
btrfs: subpage: make reader lock to utilize bitmap
btrfs: subpage: make writer lock to utilize bitmap

   fs/btrfs/subpage.c | 70 ++++++++++++++++++++++++++++++++++++----------
   fs/btrfs/subpage.h | 16 +++++++----
   2 files changed, 66 insertions(+), 20 deletions(-)

--
2.43.1