]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
btrfs: subpage: only call btrfs_alloc_subpage() when sectorsize is smaller than PAGE_SIZE
authorQu Wenruo <wqu@suse.com>
Tue, 17 Aug 2021 09:38:49 +0000 (17:38 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 Oct 2021 19:17:16 +0000 (21:17 +0200)
There are two call sites of btrfs_alloc_subpage():

- btrfs_attach_subpage()
  We have ensured sectorsize is smaller than PAGE_SIZE

- alloc_extent_buffer()
  We call btrfs_alloc_subpage() unconditionally.

The alloc_extent_buffer() forces us to check the sectorsize size against
page size inside btrfs_alloc_subpage().

Since the function name, btrfs_alloc_subpage(), already indicates it
should only get called for subpage cases, do the check in
alloc_extent_buffer() and add an ASSERT() in btrfs_alloc_subpage().

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>
fs/btrfs/extent_io.c
fs/btrfs/subpage.c

index aaddd7225348191690e8a754c958a430bfe1a974..19889dbfcf154a8e2a68d6974cf159dc8c8b3d9c 100644 (file)
@@ -6137,13 +6137,15 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
                 * page, but it may change in the future for 16K page size
                 * support, so we still preallocate the memory in the loop.
                 */
-               ret = btrfs_alloc_subpage(fs_info, &prealloc,
-                                         BTRFS_SUBPAGE_METADATA);
-               if (ret < 0) {
-                       unlock_page(p);
-                       put_page(p);
-                       exists = ERR_PTR(ret);
-                       goto free_eb;
+               if (fs_info->sectorsize < PAGE_SIZE) {
+                       ret = btrfs_alloc_subpage(fs_info, &prealloc,
+                                                 BTRFS_SUBPAGE_METADATA);
+                       if (ret < 0) {
+                               unlock_page(p);
+                               put_page(p);
+                               exists = ERR_PTR(ret);
+                               goto free_eb;
+                       }
                }
 
                spin_lock(&mapping->private_lock);
index cb10e56ee31e185a3bfce77fae24b7029e7950e3..ff1c6ba34a4d0be2ab5308b719a14ed9cd46887c 100644 (file)
@@ -104,8 +104,7 @@ int btrfs_alloc_subpage(const struct btrfs_fs_info *fs_info,
                        struct btrfs_subpage **ret,
                        enum btrfs_subpage_type type)
 {
-       if (fs_info->sectorsize == PAGE_SIZE)
-               return 0;
+       ASSERT(fs_info->sectorsize < PAGE_SIZE);
 
        *ret = kzalloc(sizeof(struct btrfs_subpage), GFP_NOFS);
        if (!*ret)