]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ocfs2: Count more refcount records in file system fragmentation.
authorTao Ma <tao.ma@oracle.com>
Thu, 22 Jul 2010 05:56:45 +0000 (13:56 +0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 26 Aug 2010 23:45:46 +0000 (16:45 -0700)
commit 8a2e70c40ff58f82dde67770e6623ca45f0cb0c8 upstream.

The refcount record calculation in ocfs2_calc_refcount_meta_credits
is too optimistic that we can always allocate contiguous clusters
and handle an already existed refcount rec as a whole. Actually
because of file system fragmentation, we may have the chance to split
a refcount record into 3 parts during the transaction. So consider
the worst case in record calculation.

Signed-off-by: Tao Ma <tao.ma@oracle.com>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
fs/ocfs2/refcounttree.c

index 3ac5aa733e9c8018090bc2493d819937593760a0..73a11ccfd4c280681abe672c5e9cd81e3b229a93 100644 (file)
@@ -2436,16 +2436,26 @@ static int ocfs2_calc_refcount_meta_credits(struct super_block *sb,
                len = min((u64)cpos + clusters, le64_to_cpu(rec.r_cpos) +
                          le32_to_cpu(rec.r_clusters)) - cpos;
                /*
-                * If the refcount rec already exist, cool. We just need
-                * to check whether there is a split. Otherwise we just need
-                * to increase the refcount.
-                * If we will insert one, increases recs_add.
-                *
                 * We record all the records which will be inserted to the
                 * same refcount block, so that we can tell exactly whether
                 * we need a new refcount block or not.
+                *
+                * If we will insert a new one, this is easy and only happens
+                * during adding refcounted flag to the extent, so we don't
+                * have a chance of spliting. We just need one record.
+                *
+                * If the refcount rec already exists, that would be a little
+                * complicated. we may have to:
+                * 1) split at the beginning if the start pos isn't aligned.
+                *    we need 1 more record in this case.
+                * 2) split int the end if the end pos isn't aligned.
+                *    we need 1 more record in this case.
+                * 3) split in the middle because of file system fragmentation.
+                *    we need 2 more records in this case(we can't detect this
+                *    beforehand, so always think of the worst case).
                 */
                if (rec.r_refcount) {
+                       recs_add += 2;
                        /* Check whether we need a split at the beginning. */
                        if (cpos == start_cpos &&
                            cpos != le64_to_cpu(rec.r_cpos))