If you wish to get every possible millisecond out of your system, there are a few things you should know about directories in UNIX file systems. (Though technically I'm talking about the implementation of the EXT2 file system, the points apply to almost all UNIX file systems.)
First note that though the command ls always displays the directory in a sorted order, directories are not stored with their entries sorted. Instead, each new entry is placed as close to the front of the directory as possible.
To find a file in a directory, the file name is compared with the first file in the directory. If it doesn't match, the second name is checked, and so on until either a match is found, or the end of the directory is reached. Consequently, if you have a large number of files in a directory and are frequently opening the last file in the directory, your CPU is doing a lot of comparisons. If, however, you could control the order of the entries, so as to place the most-frequently-used entries at the beginning of the directory, this would not be such an issue.
If you want to redo the internal ordering of the entries in /dev, boot from a floppy and then mount your primary file system. If your regular file system is mounted as /mnt, your regular device directory is /mnt/dev. Create a new directory called /mnt/dev2. Now you can move device files from /mnt/dev to /mnt/dev2. You will probably want to start with /mnt/dev/zero and /mnt/dev/null, as these two are opened far more frequently than any other devices.
If that sounds like a hassle, then don't bother with it. You probably won't notice any difference unless you are running on an old 386. Furthermore, the new directory cache under development in the 2.1.x kernel series will most likely make this a non-issue.
Preston Crow grew up in Boise, Idaho. He has a Master's degree in Computer Science from Dartmouth College and hopes to soon upgrade to a Ph.D. He now works for the Open Group in Cambridge, MA, where he lives with his brilliant wife. He can be reached via e-mail at Preston.F.Crow@Dartmouth.edu.
Webinar: 8 Signs You’re Beyond Cron
11am CDT, April 29th
Join Linux Journal and Pat Cameron, Director of Automation Technology at HelpSystems, as they discuss the eight primary advantages of moving beyond cron job scheduling. In this webinar, you’ll learn about integrating cron with an enterprise scheduler.Join us!
|Play for Me, Jarvis||Apr 16, 2015|
|Drupageddon: SQL Injection, Database Abstraction and Hundreds of Thousands of Web Sites||Apr 15, 2015|
|Non-Linux FOSS: .NET?||Apr 13, 2015|
|Designing Foils with XFLR5||Apr 08, 2015|
|diff -u: What's New in Kernel Development||Apr 07, 2015|
- Drupageddon: SQL Injection, Database Abstraction and Hundreds of Thousands of Web Sites
- Play for Me, Jarvis
- Non-Linux FOSS: .NET?
- Designing Foils with XFLR5
- Not So Dynamic Updates
- Flexible Access Control with Squid Proxy
- New Products
- New GeekGuide: Beyond Cron
- Users, Permissions and Multitenant Sites