Skip to content

Commit 6383f23

Browse files
fdmananakdave
authored andcommitted
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> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a6e9553 commit 6383f23

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

fs/btrfs/tree-mod-log.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,29 @@ struct tree_mod_elem {
2727
/* This is used for BTRFS_MOD_LOG_KEY* and BTRFS_MOD_LOG_ROOT_REPLACE. */
2828
u64 generation;
2929

30-
/* Those are used for op == BTRFS_MOD_LOG_KEY_{REPLACE,REMOVE}. */
31-
struct btrfs_disk_key key;
32-
u64 blockptr;
33-
34-
/* This is used for op == BTRFS_MOD_LOG_MOVE_KEYS. */
35-
struct {
36-
int dst_slot;
37-
int nr_items;
38-
} move;
39-
40-
/* This is used for op == BTRFS_MOD_LOG_ROOT_REPLACE. */
41-
struct tree_mod_root old_root;
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;
43+
44+
/* This is used for op == BTRFS_MOD_LOG_MOVE_KEYS. */
45+
struct {
46+
int dst_slot;
47+
int nr_items;
48+
} move;
49+
50+
/* This is used for op == BTRFS_MOD_LOG_ROOT_REPLACE. */
51+
struct tree_mod_root old_root;
52+
};
4253
};
4354

4455
/*
@@ -228,15 +239,17 @@ static struct tree_mod_elem *alloc_tree_mod_elem(const struct extent_buffer *eb,
228239
{
229240
struct tree_mod_elem *tm;
230241

242+
/* Can't be one of these types, due to union in struct tree_mod_elem. */
243+
ASSERT(op != BTRFS_MOD_LOG_MOVE_KEYS);
244+
ASSERT(op != BTRFS_MOD_LOG_ROOT_REPLACE);
245+
231246
tm = kzalloc(sizeof(*tm), GFP_NOFS);
232247
if (!tm)
233248
return NULL;
234249

235250
tm->logical = eb->start;
236-
if (op != BTRFS_MOD_LOG_KEY_ADD) {
237-
btrfs_node_key(eb, &tm->key, slot);
238-
tm->blockptr = btrfs_node_blockptr(eb, slot);
239-
}
251+
btrfs_node_key(eb, &tm->slot_change.key, slot);
252+
tm->slot_change.blockptr = btrfs_node_blockptr(eb, slot);
240253
tm->op = op;
241254
tm->slot = slot;
242255
tm->generation = btrfs_node_ptr_generation(eb, slot);
@@ -854,8 +867,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
854867
fallthrough;
855868
case BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING:
856869
case BTRFS_MOD_LOG_KEY_REMOVE:
857-
btrfs_set_node_key(eb, &tm->key, tm->slot);
858-
btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr);
870+
btrfs_set_node_key(eb, &tm->slot_change.key, tm->slot);
871+
btrfs_set_node_blockptr(eb, tm->slot, tm->slot_change.blockptr);
859872
btrfs_set_node_ptr_generation(eb, tm->slot,
860873
tm->generation);
861874
n++;
@@ -864,8 +877,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
864877
break;
865878
case BTRFS_MOD_LOG_KEY_REPLACE:
866879
BUG_ON(tm->slot >= n);
867-
btrfs_set_node_key(eb, &tm->key, tm->slot);
868-
btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr);
880+
btrfs_set_node_key(eb, &tm->slot_change.key, tm->slot);
881+
btrfs_set_node_blockptr(eb, tm->slot, tm->slot_change.blockptr);
869882
btrfs_set_node_ptr_generation(eb, tm->slot,
870883
tm->generation);
871884
break;

0 commit comments

Comments
 (0)