diff options
author | Tristan Ye <tristan.ye@oracle.com> | 2011-03-18 09:35:40 +0300 |
---|---|---|
committer | Tristan Ye <tristan.ye@oracle.com> | 2011-05-25 11:17:12 +0400 |
commit | ee16cc037e255801892481a2d0b7c1fff2adf1aa (patch) | |
tree | 00ec3109caf8becea9da524282bf66469361ed7c | |
parent | e08477176d5575493ba4c30041245c34f2737ad4 (diff) | |
download | linux-ee16cc037e255801892481a2d0b7c1fff2adf1aa.tar.xz |
Ocfs2/move_extents: helper to calculate the defraging length in one run.
The helper is to calculate the defrag length in one run according to a threshold,
it will proceed doing defragmentation until the threshold was meet, and skip a
LARGE extent if any.
Signed-off-by: Tristan Ye <tristan.ye@oracle.com>
-rw-r--r-- | fs/ocfs2/move_extents.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c index ae15c998a82a..1c822e08fea0 100644 --- a/fs/ocfs2/move_extents.c +++ b/fs/ocfs2/move_extents.c @@ -797,3 +797,33 @@ out: 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; + } +} |