mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-28 14:44:10 +08:00
btrfs: subpage: introduce btrfs_subpage_bitmap_info
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>
This commit is contained in:
parent
651fb41927
commit
8481dd80ab
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@ -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,
|
||||
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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.
|
||||
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user