Btrfs: remove unneeded field / smaller extent_map structure
authorFilipe Manana <fdmanana@gmail.com>
Tue, 25 Feb 2014 14:15:12 +0000 (14:15 +0000)
committerJosef Bacik <jbacik@fb.com>
Mon, 10 Mar 2014 19:16:56 +0000 (15:16 -0400)
We don't need to have an unsigned int field in the extent_map struct
to tell us whether the extent map is in the inode's extent_map tree or
not. We can use the rb_node struct field and the RB_CLEAR_NODE and
RB_EMPTY_NODE macros to achieve the same task.

This reduces sizeof(struct extent_map) from 152 bytes to 144 bytes (on a
64 bits system).

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Josef Bacik <jbacik@fb.com>
fs/btrfs/extent_io.c
fs/btrfs/extent_map.c
fs/btrfs/extent_map.h

index fbe501d3bd014804ca2bf20958f147c11c975c62..2c9fbe3b6eec34195360aabc581681f47eb0ec85 100644 (file)
@@ -2763,7 +2763,7 @@ __get_extent_map(struct inode *inode, struct page *page, size_t pg_offset,
 
        if (em_cached && *em_cached) {
                em = *em_cached;
-               if (em->in_tree && start >= em->start &&
+               if (extent_map_in_tree(em) && start >= em->start &&
                    start < extent_map_end(em)) {
                        atomic_inc(&em->refs);
                        return em;
index 996ad56b57db64bbc0516f4674d8ad3fd2d43976..64d08f94485dc84c957ebd1eb81cc40c8f20ef0f 100644 (file)
@@ -51,7 +51,7 @@ struct extent_map *alloc_extent_map(void)
        em = kmem_cache_zalloc(extent_map_cache, GFP_NOFS);
        if (!em)
                return NULL;
-       em->in_tree = 0;
+       RB_CLEAR_NODE(&em->rb_node);
        em->flags = 0;
        em->compress_type = BTRFS_COMPRESS_NONE;
        em->generation = 0;
@@ -73,7 +73,7 @@ void free_extent_map(struct extent_map *em)
                return;
        WARN_ON(atomic_read(&em->refs) == 0);
        if (atomic_dec_and_test(&em->refs)) {
-               WARN_ON(em->in_tree);
+               WARN_ON(extent_map_in_tree(em));
                WARN_ON(!list_empty(&em->list));
                kmem_cache_free(extent_map_cache, em);
        }
@@ -99,8 +99,6 @@ static int tree_insert(struct rb_root *root, struct extent_map *em)
                parent = *p;
                entry = rb_entry(parent, struct extent_map, rb_node);
 
-               WARN_ON(!entry->in_tree);
-
                if (em->start < entry->start)
                        p = &(*p)->rb_left;
                else if (em->start >= extent_map_end(entry))
@@ -128,7 +126,6 @@ static int tree_insert(struct rb_root *root, struct extent_map *em)
                if (end > entry->start && em->start < extent_map_end(entry))
                        return -EEXIST;
 
-       em->in_tree = 1;
        rb_link_node(&em->rb_node, orig_parent, p);
        rb_insert_color(&em->rb_node, root);
        return 0;
@@ -153,8 +150,6 @@ static struct rb_node *__tree_search(struct rb_root *root, u64 offset,
                prev = n;
                prev_entry = entry;
 
-               WARN_ON(!entry->in_tree);
-
                if (offset < entry->start)
                        n = n->rb_left;
                else if (offset >= extent_map_end(entry))
@@ -240,12 +235,12 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em)
                        em->len += merge->len;
                        em->block_len += merge->block_len;
                        em->block_start = merge->block_start;
-                       merge->in_tree = 0;
                        em->mod_len = (em->mod_len + em->mod_start) - merge->mod_start;
                        em->mod_start = merge->mod_start;
                        em->generation = max(em->generation, merge->generation);
 
                        rb_erase(&merge->rb_node, &tree->map);
+                       RB_CLEAR_NODE(&merge->rb_node);
                        free_extent_map(merge);
                }
        }
@@ -257,7 +252,7 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em)
                em->len += merge->len;
                em->block_len += merge->block_len;
                rb_erase(&merge->rb_node, &tree->map);
-               merge->in_tree = 0;
+               RB_CLEAR_NODE(&merge->rb_node);
                em->mod_len = (merge->mod_start + merge->mod_len) - em->mod_start;
                em->generation = max(em->generation, merge->generation);
                free_extent_map(merge);
@@ -319,7 +314,7 @@ out:
 void clear_em_logging(struct extent_map_tree *tree, struct extent_map *em)
 {
        clear_bit(EXTENT_FLAG_LOGGING, &em->flags);
-       if (em->in_tree)
+       if (extent_map_in_tree(em))
                try_merge_map(tree, em);
 }
 
@@ -434,6 +429,6 @@ int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em)
        rb_erase(&em->rb_node, &tree->map);
        if (!test_bit(EXTENT_FLAG_LOGGING, &em->flags))
                list_del_init(&em->list);
-       em->in_tree = 0;
+       RB_CLEAR_NODE(&em->rb_node);
        return ret;
 }
index 93fba716d7f82f517ad082a65354611d1afecdd2..f0a645a14d6e83a5e2b04dcf8ba71d69725ecc32 100644 (file)
@@ -33,7 +33,6 @@ struct extent_map {
        unsigned long flags;
        struct block_device *bdev;
        atomic_t refs;
-       unsigned int in_tree;
        unsigned int compress_type;
        struct list_head list;
 };
@@ -44,6 +43,11 @@ struct extent_map_tree {
        rwlock_t lock;
 };
 
+static inline int extent_map_in_tree(const struct extent_map *em)
+{
+       return !RB_EMPTY_NODE(&em->rb_node);
+}
+
 static inline u64 extent_map_end(struct extent_map *em)
 {
        if (em->start + em->len < em->start)