Skip to content

Commit

Permalink
btrfs: subpage: introduce btrfs_subpage_bitmap_info
Browse files Browse the repository at this point in the history
Currently we use fixed size u16 bitmap for subpage bitmap.  This is fine
for 4K sectorsize with 64K page size.

But for 4K sectorsize and larger page size, the bitmap is too small,
while for smaller page size like 16K, u16 bitmaps waste too much space.

Here we introduce a new helper structure, btrfs_subpage_bitmap_info, to
record the proper bitmap size, and where each bitmap should start at.

By this, we can later compact all subpage bitmaps into one u32 bitmap.
This patch is the first step.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Qu Wenruo authored and David Sterba committed Oct 25, 2021
1 parent 651fb41 commit 8481dd8
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ struct btrfs_fs_info {
struct btrfs_workqueue *scrub_workers;
struct btrfs_workqueue *scrub_wr_completion_workers;
struct btrfs_workqueue *scrub_parity_workers;
struct btrfs_subpage_info *subpage_info;

struct btrfs_discard_ctl discard_ctl;

Expand Down
12 changes: 9 additions & 3 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
btrfs_extent_buffer_leak_debug_check(fs_info);
kfree(fs_info->super_copy);
kfree(fs_info->super_for_commit);
kfree(fs_info->subpage_info);
kvfree(fs_info);
}

Expand Down Expand Up @@ -3392,12 +3393,12 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
goto fail_alloc;
}

if (sectorsize != PAGE_SIZE) {
if (sectorsize < PAGE_SIZE) {
struct btrfs_subpage_info *subpage_info;

btrfs_warn(fs_info,
"read-write for sector size %u with page size %lu is experimental",
sectorsize, PAGE_SIZE);
}
if (sectorsize != PAGE_SIZE) {
if (btrfs_super_incompat_flags(fs_info->super_copy) &
BTRFS_FEATURE_INCOMPAT_RAID56) {
btrfs_err(fs_info,
Expand All @@ -3406,6 +3407,11 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
err = -EINVAL;
goto fail_alloc;
}
subpage_info = kzalloc(sizeof(*subpage_info), GFP_KERNEL);
if (!subpage_info)
goto fail_alloc;
btrfs_init_subpage_info(subpage_info, sectorsize);
fs_info->subpage_info = subpage_info;
}

ret = btrfs_init_workqueues(fs_info, fs_devices);
Expand Down
28 changes: 28 additions & 0 deletions fs/btrfs/subpage.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@
* This means a slightly higher tree locking latency.
*/

void btrfs_init_subpage_info(struct btrfs_subpage_info *subpage_info, u32 sectorsize)
{
unsigned int cur = 0;
unsigned int nr_bits;

ASSERT(IS_ALIGNED(PAGE_SIZE, sectorsize));

nr_bits = PAGE_SIZE / sectorsize;
subpage_info->bitmap_nr_bits = nr_bits;

subpage_info->uptodate_offset = cur;
cur += nr_bits;

subpage_info->error_offset = cur;
cur += nr_bits;

subpage_info->dirty_offset = cur;
cur += nr_bits;

subpage_info->writeback_offset = cur;
cur += nr_bits;

subpage_info->ordered_offset = cur;
cur += nr_bits;

subpage_info->total_nr_bits = cur;
}

int btrfs_attach_subpage(const struct btrfs_fs_info *fs_info,
struct page *page, enum btrfs_subpage_type type)
{
Expand Down
34 changes: 34 additions & 0 deletions fs/btrfs/subpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@
*/
#define BTRFS_SUBPAGE_BITMAP_SIZE 16

/*
* Extra info for subpapge bitmap.
*
* For subpage we pack all uptodate/error/dirty/writeback/ordered bitmaps into
* one larger bitmap.
*
* This structure records how they are organized in the bitmap:
*
* /- uptodate_offset /- error_offset /- dirty_offset
* | | |
* v v v
* |u|u|u|u|........|u|u|e|e|.......|e|e| ... |o|o|
* |<- bitmap_nr_bits ->|
* |<--------------- total_nr_bits ---------------->|
*/
struct btrfs_subpage_info {
/* Number of bits for each bitmap */
unsigned int bitmap_nr_bits;

/* Total number of bits for the whole bitmap */
unsigned int total_nr_bits;

/*
* *_start indicates where the bitmap starts, the length is always
* @bitmap_size, which is calculated from PAGE_SIZE / sectorsize.
*/
unsigned int uptodate_offset;
unsigned int error_offset;
unsigned int dirty_offset;
unsigned int writeback_offset;
unsigned int ordered_offset;
};

/*
* Structure to trace status of each sector inside a page, attached to
* page::private for both data and metadata inodes.
Expand Down Expand Up @@ -53,6 +86,7 @@ enum btrfs_subpage_type {
BTRFS_SUBPAGE_DATA,
};

void btrfs_init_subpage_info(struct btrfs_subpage_info *subpage_info, u32 sectorsize);
int btrfs_attach_subpage(const struct btrfs_fs_info *fs_info,
struct page *page, enum btrfs_subpage_type type);
void btrfs_detach_subpage(const struct btrfs_fs_info *fs_info,
Expand Down

0 comments on commit 8481dd8

Please sign in to comment.