[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: reading an empty directory after reboot is very slow



On 04/14/2015 at 12:55 PM, Bob Proulx wrote:

> Petter Adsen wrote:
> 
>> Can someone please enlighten me as to why the entry for this
>> directory is so large, even though it is empty? Since it's
>> apparently obvious to everyone else, I would very much like to know
>> :)
> 
> In the old days directories were simply an array of fixed sized 
> integers and fixed sized names.  The fixed maximum size of the name 
> was 14 characters.  The fixed size integer was the inode address. 
> That it was fixed sized allowed directories to be read into an array 
> of structures very efficiently using readdir(2) system call. 
> Individual entries were written by lseek(2)'ing to the proper slot
> and writing just that fixed size entry leaving the rest of the
> (special directory) file untouched.  Directories were an array of
> file entries.
> 
> That strategy was in use for many years in Unix systems.  But it has 
> unpleasant limitations.  Short fixed sized file names 14 characters
> or less were one.  The linear nature of the array data structure was 
> another.  The array influenced things considerably.  When a file was 
> deleted the entree was simply zero'd out.  lseek() to the proper 
> entry and zero it out.  That meant that directories could grow in
> size but never shrink.  If a directory became full it was easy to
> extend it by writing the array longer.  But if an early entry in the
> array was deleted the system would zero it out rather than move each
> and every entry in the file system down a slot.  (I always wondered
> why they didn't simply take the *last* entry and move it down to the
> deleted entry and simply keep the array always compacted.  I wonder.
> But they didn't do it that way.)

I'd guess that it was in order to avoid having the "internal order" of
files in a directory - which can affect the order in which they are
processed, depending on how you get your directory listing - be changed
by a seemingly unrelated operation.

Thanks for the lengthy explanation and historical background. By the
time I got started, apparently the 14-character limit was already far
enough in the background that it never made it into the documentation
that I read...

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man.         -- George Bernard Shaw

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: