Skip to content

Commit cb3c11d

Browse files
adam900710kdave
authored andcommitted
btrfs: add a size parameter to btrfs_alloc_subpage()
Since we can no longer assume page sized folio for data filemap folios, allow btrfs_alloc_subpage() to accept a new parameter, @fsize, indicating the folio size. This doesn't follow the regular behavior of passing a folio directly, because this function is shared by both data and metadata folios, and for metadata folios we have extra allocation policy to ensure no large folios whose sizes are larger than nodesize (unless it's page sized). Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 4c14d5c commit cb3c11d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

fs/btrfs/extent_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3256,7 +3256,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
32563256
* manually if we exit earlier.
32573257
*/
32583258
if (btrfs_meta_is_subpage(fs_info)) {
3259-
prealloc = btrfs_alloc_subpage(fs_info, BTRFS_SUBPAGE_METADATA);
3259+
prealloc = btrfs_alloc_subpage(fs_info, PAGE_SIZE, BTRFS_SUBPAGE_METADATA);
32603260
if (IS_ERR(prealloc)) {
32613261
ret = PTR_ERR(prealloc);
32623262
goto out;

fs/btrfs/subpage.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int btrfs_attach_subpage(const struct btrfs_fs_info *fs_info,
8686
if (type == BTRFS_SUBPAGE_DATA && !btrfs_is_subpage(fs_info, folio))
8787
return 0;
8888

89-
subpage = btrfs_alloc_subpage(fs_info, type);
89+
subpage = btrfs_alloc_subpage(fs_info, folio_size(folio), type);
9090
if (IS_ERR(subpage))
9191
return PTR_ERR(subpage);
9292

@@ -113,16 +113,16 @@ void btrfs_detach_subpage(const struct btrfs_fs_info *fs_info, struct folio *fol
113113
}
114114

115115
struct btrfs_subpage *btrfs_alloc_subpage(const struct btrfs_fs_info *fs_info,
116-
enum btrfs_subpage_type type)
116+
size_t fsize, enum btrfs_subpage_type type)
117117
{
118118
struct btrfs_subpage *ret;
119119
unsigned int real_size;
120120

121-
ASSERT(fs_info->sectorsize < PAGE_SIZE);
121+
ASSERT(fs_info->sectorsize < fsize);
122122

123123
real_size = struct_size(ret, bitmaps,
124124
BITS_TO_LONGS(btrfs_bitmap_nr_max *
125-
(PAGE_SIZE >> fs_info->sectorsize_bits)));
125+
(fsize >> fs_info->sectorsize_bits)));
126126
ret = kzalloc(real_size, GFP_NOFS);
127127
if (!ret)
128128
return ERR_PTR(-ENOMEM);

fs/btrfs/subpage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void btrfs_detach_subpage(const struct btrfs_fs_info *fs_info, struct folio *fol
112112

113113
/* Allocate additional data where page represents more than one sector */
114114
struct btrfs_subpage *btrfs_alloc_subpage(const struct btrfs_fs_info *fs_info,
115-
enum btrfs_subpage_type type);
115+
size_t fsize, enum btrfs_subpage_type type);
116116
void btrfs_free_subpage(struct btrfs_subpage *subpage);
117117

118118
void btrfs_folio_inc_eb_refs(const struct btrfs_fs_info *fs_info, struct folio *folio);

0 commit comments

Comments
 (0)