Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: reduce size of struct tree_mod_elem

Several members are used for specific types of tree mod log operations so
they can be placed in a union in order to reduce the structure's size.

This reduces the structure size from 112 bytes to 88 bytes on x86_64,
so we can now use the kmalloc-96 slab instead of the kmalloc-128 slab.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Filipe Manana and committed by
David Sterba
aee10fe4 d30b236a

+31 -18
+31 -18
fs/btrfs/tree-mod-log.c
··· 27 27 /* This is used for BTRFS_MOD_LOG_KEY* and BTRFS_MOD_LOG_ROOT_REPLACE. */ 28 28 u64 generation; 29 29 30 - /* Those are used for op == BTRFS_MOD_LOG_KEY_{REPLACE,REMOVE}. */ 31 - struct btrfs_disk_key key; 32 - u64 blockptr; 30 + union { 31 + /* 32 + * This is used for the following op types: 33 + * 34 + * BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING 35 + * BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING 36 + * BTRFS_MOD_LOG_KEY_REMOVE 37 + * BTRFS_MOD_LOG_KEY_REPLACE 38 + */ 39 + struct { 40 + struct btrfs_disk_key key; 41 + u64 blockptr; 42 + } slot_change; 33 43 34 - /* This is used for op == BTRFS_MOD_LOG_MOVE_KEYS. */ 35 - struct { 36 - int dst_slot; 37 - int nr_items; 38 - } move; 44 + /* This is used for op == BTRFS_MOD_LOG_MOVE_KEYS. */ 45 + struct { 46 + int dst_slot; 47 + int nr_items; 48 + } move; 39 49 40 - /* This is used for op == BTRFS_MOD_LOG_ROOT_REPLACE. */ 41 - struct tree_mod_root old_root; 50 + /* This is used for op == BTRFS_MOD_LOG_ROOT_REPLACE. */ 51 + struct tree_mod_root old_root; 52 + }; 42 53 }; 43 54 44 55 /* ··· 239 228 { 240 229 struct tree_mod_elem *tm; 241 230 231 + /* Can't be one of these types, due to union in struct tree_mod_elem. */ 232 + ASSERT(op != BTRFS_MOD_LOG_MOVE_KEYS); 233 + ASSERT(op != BTRFS_MOD_LOG_ROOT_REPLACE); 234 + 242 235 tm = kzalloc(sizeof(*tm), GFP_NOFS); 243 236 if (!tm) 244 237 return NULL; 245 238 246 239 tm->logical = eb->start; 247 - if (op != BTRFS_MOD_LOG_KEY_ADD) { 248 - btrfs_node_key(eb, &tm->key, slot); 249 - tm->blockptr = btrfs_node_blockptr(eb, slot); 250 - } 240 + btrfs_node_key(eb, &tm->slot_change.key, slot); 241 + tm->slot_change.blockptr = btrfs_node_blockptr(eb, slot); 251 242 tm->op = op; 252 243 tm->slot = slot; 253 244 tm->generation = btrfs_node_ptr_generation(eb, slot); ··· 867 854 fallthrough; 868 855 case BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING: 869 856 case BTRFS_MOD_LOG_KEY_REMOVE: 870 - btrfs_set_node_key(eb, &tm->key, tm->slot); 871 - btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr); 857 + btrfs_set_node_key(eb, &tm->slot_change.key, tm->slot); 858 + btrfs_set_node_blockptr(eb, tm->slot, tm->slot_change.blockptr); 872 859 btrfs_set_node_ptr_generation(eb, tm->slot, 873 860 tm->generation); 874 861 n++; ··· 877 864 break; 878 865 case BTRFS_MOD_LOG_KEY_REPLACE: 879 866 BUG_ON(tm->slot >= n); 880 - btrfs_set_node_key(eb, &tm->key, tm->slot); 881 - btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr); 867 + btrfs_set_node_key(eb, &tm->slot_change.key, tm->slot); 868 + btrfs_set_node_blockptr(eb, tm->slot, tm->slot_change.blockptr); 882 869 btrfs_set_node_ptr_generation(eb, tm->slot, 883 870 tm->generation); 884 871 break;