Skip to contentSkip to conversation

change how we account for free space

RFC PATCH New Josef Bacik 1 participant 1 message Aug 8, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 change how we account for free space

Hello,

This thing doesn't work, I'm mostly just throwing it out here to make sure I'm taking this in the right direction. I've replaced the extent io tree for free space with two rb trees that are indexed via bytenr and size. ATM the only thing that really matters is the bytenr rb tree, but I'm sure once this is completely done there will be some use for the size indexed rb tree. Again this is just what I have so far, to just make sure that I'm not making some big mistake. Thanks much,

Josef

Makefile +1 -1
diff -r 401378fbac2a Makefile
@@ -7,7 +7,7 @@ btrfs-y := super.o ctree.o extent-tree.o
 	   transaction.o bit-radix.o inode.o file.o tree-defrag.o \
 	   extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \
 	   extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \
-	   ref-cache.o
+	   ref-cache.o free-space-cache.o
 
 btrfs-$(CONFIG_FS_POSIX_ACL)	+= acl.o
 else
ctree.h +24 -1
diff -r 401378fbac2a ctree.h
@@ -485,10 +485,22 @@ struct btrfs_space_info {
 	struct list_head list;
 };
 
+struct btrfs_free_space {
+	struct rb_node size_index;
+	struct rb_node bytenr_index;
+	struct list_head list;
+	u64 bytenr;
+	u64 size;
+};
+
 struct btrfs_block_group_cache {
 	struct btrfs_key key;
 	struct btrfs_block_group_item item;
 	struct btrfs_space_info *space_info;
+	struct rb_root free_space_size;	/* free space indexed by size */
+	struct rb_root free_space_bytenr; /* free space indexed by start
+					     byte */
+	struct list_head free_space_list; /* list of free space for freeing */
 	spinlock_t lock;
 	u64 pinned;
 	u64 flags;
@@ -507,7 +519,6 @@ struct btrfs_fs_info {
 	struct btrfs_root *dev_root;
 	struct radix_tree_root fs_roots_radix;
 
-	struct extent_io_tree free_space_cache;
 	struct extent_io_tree block_group_cache;
 	struct extent_io_tree pinned_extents;
 	struct extent_io_tree pending_del;
@@ -1743,4 +1754,16 @@ int btrfs_check_acl(struct inode *inode,
 int btrfs_check_acl(struct inode *inode, int mask);
 int btrfs_init_acl(struct inode *inode, struct inode *dir);
 int btrfs_acl_chmod(struct inode *inode);
+
+/* free-space-cache.c */
+int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
+			 u64 bytenr, u64 size);
+int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
+			    u64 bytenr, u64 size);
+void btrfs_remove_free_space_cache(struct btrfs_block_group_cache
+				   *block_group);
+struct btrfs_free_space *btrfs_find_free_space_start(struct
+						     btrfs_block_group_cache
+						     *block_group, u64 bytenr,
+						     u64 size);
 #endif
disk-io.c +0 -2
diff -r 401378fbac2a disk-io.c
@@ -1284,8 +1284,6 @@ struct btrfs_root *open_ctree(struct sup
 
 	BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
 
-	extent_io_tree_init(&fs_info->free_space_cache,
-			     fs_info->btree_inode->i_mapping, GFP_NOFS);
 	extent_io_tree_init(&fs_info->block_group_cache,
 			     fs_info->btree_inode->i_mapping, GFP_NOFS);
 	extent_io_tree_init(&fs_info->pinned_extents,
extent-tree.c +63 -44

239 lines not on this page · raw message

free-space-cache.c new file +213 -0

213 lines not on this page · raw message