defragmenter for directories, including ext3/ext4

Registered by jan

I have many directories with hundreds individual data files.
I've noticed that as ext3/ext4 directories get defragmented, system performance degrades.
even though many sites on ext3/ext4 state this should not happen. Defragmentation may be due to the fact that as the directories are created, also a lot of data is written. Therefore caching may not work.
I noticed a BIG speed improvement, and less disk access after the following sequence of commands, where $t is a directory name.
Unfortunately, it does not work if hidden files are present, or if a process has one of the directories is in use.
I'd like to work out a script (e.g. with find ) that processes a file system while it is mounted.
Preferably, it would link all files to a new directory (where ln, unfortunately, refuses to link sub-directories) and then quickly swap the names of old directory for the new directory.

   mkdir ../mvdir
   mv $t/* ../mvdir
   rmdir $t
   mv ../mvdir $t

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

This is probably just shake for directories rather than files:
https://launchpad.net/~un-brice/+archive/ppa
or fidefrag
https://answers.launchpad.net/fidefrag/trunk

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.