[Ocfs2-tools-devel] [PATCH 4/4] defrag.ocfs2: Pass 3: Defrag filesystem

Joel Becker Joel.Becker at oracle.com
Fri Jul 23 10:23:23 PDT 2010


On Tue, May 11, 2010 at 11:02:45PM -0500, Goldwyn Rodrigues wrote:
> Defrags the filesystem. For each group_desc, scan for holes.
> If a hole is found, try and find extent rec which fits the hole best
> and is greater than the block number of the hole. Move the data in
> the hole.

	This seems like a suboptimal scheme.  It's going to move random
things to random places.

> +/* A simple selection sort for now */
> +static void sort_gds(struct defrag_state *dst)
> +{
> +	int i, j, n=dst->num_gds;
> +	struct ocfs2_group_desc **gd = dst->gds;
> +	struct ocfs2_group_desc *t;
> +
> +	for (i=0; i<n-1; i++)
> +		for (j=i+1; j<n; j++)
> +			if (gd[i]->bg_blkno > gd[j]->bg_blkno) {
> +				t = gd[i];
> +				gd[i]=gd[j];
> +				gd[j] = t;
> +			}
> +}

	The C library has qsort().  I bet it works better ;-)

Joel

-- 

"Senator let's be sincere,
 As much as you can."

Joel Becker
Consulting Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127



More information about the Ocfs2-tools-devel mailing list