Commit aee10fe4 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba
Browse files

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: default avatarBoris Burkov <boris@bur.io>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent d30b236a
Loading
Loading
Loading
Loading
+33 −20
Original line number Diff line number Diff line
@@ -27,9 +27,19 @@ struct tree_mod_elem {
	/* This is used for BTRFS_MOD_LOG_KEY* and BTRFS_MOD_LOG_ROOT_REPLACE. */
	u64 generation;

	/* Those are used for op == BTRFS_MOD_LOG_KEY_{REPLACE,REMOVE}. */
	union {
		/*
		 * This is used for the following op types:
		 *
		 *    BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING
		 *    BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING
		 *    BTRFS_MOD_LOG_KEY_REMOVE
		 *    BTRFS_MOD_LOG_KEY_REPLACE
		 */
		struct {
			struct btrfs_disk_key key;
			u64 blockptr;
		} slot_change;

		/* This is used for op == BTRFS_MOD_LOG_MOVE_KEYS. */
		struct {
@@ -40,6 +50,7 @@ struct tree_mod_elem {
		/* This is used for op == BTRFS_MOD_LOG_ROOT_REPLACE. */
		struct tree_mod_root old_root;
	};
};

/*
 * Pull a new tree mod seq number for our operation.
@@ -228,15 +239,17 @@ static struct tree_mod_elem *alloc_tree_mod_elem(const struct extent_buffer *eb,
{
	struct tree_mod_elem *tm;

	/* Can't be one of these types, due to union in struct tree_mod_elem. */
	ASSERT(op != BTRFS_MOD_LOG_MOVE_KEYS);
	ASSERT(op != BTRFS_MOD_LOG_ROOT_REPLACE);

	tm = kzalloc(sizeof(*tm), GFP_NOFS);
	if (!tm)
		return NULL;

	tm->logical = eb->start;
	if (op != BTRFS_MOD_LOG_KEY_ADD) {
		btrfs_node_key(eb, &tm->key, slot);
		tm->blockptr = btrfs_node_blockptr(eb, slot);
	}
	btrfs_node_key(eb, &tm->slot_change.key, slot);
	tm->slot_change.blockptr = btrfs_node_blockptr(eb, slot);
	tm->op = op;
	tm->slot = slot;
	tm->generation = btrfs_node_ptr_generation(eb, slot);
@@ -854,8 +867,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
			fallthrough;
		case BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING:
		case BTRFS_MOD_LOG_KEY_REMOVE:
			btrfs_set_node_key(eb, &tm->key, tm->slot);
			btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr);
			btrfs_set_node_key(eb, &tm->slot_change.key, tm->slot);
			btrfs_set_node_blockptr(eb, tm->slot, tm->slot_change.blockptr);
			btrfs_set_node_ptr_generation(eb, tm->slot,
						      tm->generation);
			n++;
@@ -864,8 +877,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
			break;
		case BTRFS_MOD_LOG_KEY_REPLACE:
			BUG_ON(tm->slot >= n);
			btrfs_set_node_key(eb, &tm->key, tm->slot);
			btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr);
			btrfs_set_node_key(eb, &tm->slot_change.key, tm->slot);
			btrfs_set_node_blockptr(eb, tm->slot, tm->slot_change.blockptr);
			btrfs_set_node_ptr_generation(eb, tm->slot,
						      tm->generation);
			break;