From 73ae2e3718e20b60a2a2b3050ba5d333e8e1a8f7 Mon Sep 17 00:00:00 2001 From: Tristan Ye Date: Fri, 18 Mar 2011 14:35:40 +0800 Subject: [PATCH] --- yaml --- r: 251812 b: refs/heads/master c: ee16cc037e255801892481a2d0b7c1fff2adf1aa h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/fs/ocfs2/move_extents.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index f465512c20b6..65e44c8ec141 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: e08477176d5575493ba4c30041245c34f2737ad4 +refs/heads/master: ee16cc037e255801892481a2d0b7c1fff2adf1aa diff --git a/trunk/fs/ocfs2/move_extents.c b/trunk/fs/ocfs2/move_extents.c index ae15c998a82a..1c822e08fea0 100644 --- a/trunk/fs/ocfs2/move_extents.c +++ b/trunk/fs/ocfs2/move_extents.c @@ -797,3 +797,33 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context, return ret; } + +/* + * Helper to calculate the defraging length in one run according to threshold. + */ +static void ocfs2_calc_extent_defrag_len(u32 *alloc_size, u32 *len_defraged, + u32 threshold, int *skip) +{ + if ((*alloc_size + *len_defraged) < threshold) { + /* + * proceed defragmentation until we meet the thresh + */ + *len_defraged += *alloc_size; + } else if (*len_defraged == 0) { + /* + * XXX: skip a large extent. + */ + *skip = 1; + } else { + /* + * split this extent to coalesce with former pieces as + * to reach the threshold. + * + * we're done here with one cycle of defragmentation + * in a size of 'thresh', resetting 'len_defraged' + * forces a new defragmentation. + */ + *alloc_size = threshold - *len_defraged; + *len_defraged = 0; + } +}