Skip to content

Commit 5012542

Browse files
fdmananakdave
authored andcommitted
btrfs: remove redundant zero/NULL initializations in btrfs_alloc_root()
We have allocated the root with kzalloc() so all the memory is already zero initialized, therefore it's redundant to assign 0 and NULL to several of the root members. Remove all of them except the atomic initializations since atomic_t is an opaque type and it's not a good practice to assume its internals. This slightly reduces the binary size. With gcc 14.2.0-19 from Debian on x86_64, before this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1939404 162963 15592 2117959 205147 fs/btrfs/btrfs.ko After this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1939212 162963 15592 2117767 205087 fs/btrfs/btrfs.ko Reviewed-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent e539c07 commit 5012542

File tree

1 file changed

+0
-13
lines changed

1 file changed

+0
-13
lines changed

fs/btrfs/disk-io.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -652,20 +652,10 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
652652
if (!root)
653653
return NULL;
654654

655-
memset(&root->root_key, 0, sizeof(root->root_key));
656-
memset(&root->root_item, 0, sizeof(root->root_item));
657-
memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
658655
root->fs_info = fs_info;
659656
root->root_key.objectid = objectid;
660-
root->node = NULL;
661-
root->commit_root = NULL;
662-
root->state = 0;
663657
RB_CLEAR_NODE(&root->rb_node);
664658

665-
btrfs_set_root_last_trans(root, 0);
666-
root->free_objectid = 0;
667-
root->nr_delalloc_inodes = 0;
668-
root->nr_ordered_extents = 0;
669659
xa_init(&root->inodes);
670660
xa_init(&root->delayed_nodes);
671661

@@ -699,10 +689,7 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
699689
refcount_set(&root->refs, 1);
700690
atomic_set(&root->snapshot_force_cow, 0);
701691
atomic_set(&root->nr_swapfiles, 0);
702-
btrfs_set_root_log_transid(root, 0);
703692
root->log_transid_committed = -1;
704-
btrfs_set_root_last_log_commit(root, 0);
705-
root->anon_dev = 0;
706693
if (!btrfs_is_testing(fs_info)) {
707694
btrfs_extent_io_tree_init(fs_info, &root->dirty_log_pages,
708695
IO_TREE_ROOT_DIRTY_LOG_PAGES);

0 commit comments

Comments
 (0)