]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Btrfs: reduce the amount of space needed for truncates
authorJosef Bacik <josef@redhat.com>
Fri, 19 Aug 2011 14:29:59 +0000 (10:29 -0400)
committerChris Mason <chris.mason@oracle.com>
Wed, 16 Nov 2011 02:20:16 +0000 (21:20 -0500)
With btrfs_truncate_inode_items we always return if we have to go to another
leaf, which makes us do our reservation again.  This means we will only ever
modify one leaf at a time, so we only need 1 items worth of slack space.  Also,
since we are deleting we will not be creating nodes as we go down, if anything
we'll be free'ing them as we merge them together, so make a different
calculation for truncate which will only have the worst case useage of COW'ing
the entire path down to the leaf.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 07127184efb629f1336c0592bfdacec258cab731)

fs/btrfs/ctree.h
fs/btrfs/inode.c

index 0cd6db2145fee7ed0c78a135bcb5a00a3bddb646..d1ae92126f4997680bb6d867d95fe9805840ab85 100644 (file)
@@ -2130,6 +2130,17 @@ static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
                3 * num_items;
 }
 
+/*
+ * Doing a truncate won't result in new nodes or leaves, just what we need for
+ * COW.
+ */
+static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_root *root,
+                                                unsigned num_items)
+{
+       return (root->leafsize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
+               num_items;
+}
+
 void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
                           struct btrfs_root *root, unsigned long count);
index 4bf0c291763290c095adedb2a0aef458c929720e..057edcfc08915a61ceb05852d2259aceb150a0f8 100644 (file)
@@ -3380,7 +3380,7 @@ void btrfs_evict_inode(struct inode *inode)
        struct btrfs_trans_handle *trans;
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_block_rsv *rsv;
-       u64 min_size = btrfs_calc_trans_metadata_size(root, 2);
+       u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
        unsigned long nr;
        int ret;
 
@@ -6290,7 +6290,7 @@ static int btrfs_truncate(struct inode *inode)
        struct btrfs_trans_handle *trans;
        unsigned long nr;
        u64 mask = root->sectorsize - 1;
-       u64 min_size = btrfs_calc_trans_metadata_size(root, 2);
+       u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
 
        ret = btrfs_truncate_page(inode->i_mapping, inode->i_size);
        if (ret)
@@ -6340,12 +6340,12 @@ static int btrfs_truncate(struct inode *inode)
                return -ENOMEM;
 
        /*
-        * 2 for the truncate slack space
+        * 1 for the truncate slack space
         * 1 for the orphan item we're going to add
         * 1 for the orphan item deletion
         * 1 for updating the inode.
         */
-       trans = btrfs_start_transaction(root, 5);
+       trans = btrfs_start_transaction(root, 4);
        if (IS_ERR(trans)) {
                err = PTR_ERR(trans);
                goto out;