Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: Bob Harris <harris@zk3.dec.com>
Subject: Re: Efficient way of deleted large directories
Date: Thu, 23 Sep 2004 02:37:38 GMT	[thread overview]
Message-ID: <harris-52EA92.22311222092004@cacnews.cac.cpqcorp.net> (raw)
In-Reply-To: 6425a413.0409221716.55a1cb5@posting.google.com

In article <6425a413.0409221716.55a1cb5@posting.google.com>,
 panzerboy@gmail.com (Jeremy Thomson) wrote:

> Well I got myself into quite a mess.
> We have a vdump tape backup, that saved cloned filesets.
> The vdump was taking soo long it was still going when purge routines
> kicked into life by cron.
> So we were backing up directories whilst trying to delete old files
> from them.
> Things slowed down.

Because there was a clone, you were not deleting the files.  You were 
moving all the storage for every deleted file from the original fileset 
into the clone.  Lots of metadata manulipulation, while vdump was 
already placing a heavy I/O demand on your disks.

You did not specify your operating system version, and more important 
which on-disk format of AdvFS is your file system(s).  The showfdmn 
command will tell you the domain version number (DVN) 4 is the most 
recent.

If you have DVN 4, then any directory greater than 8K in size will have 
a shadow index file that uses b-trees to make fast name addition, name 
lookup, and name removal.

If you have DVN 3, then the larger the directory the slower the add, 
lookup, removal of a name in the directory.

> It seems the more activity there is on a cloned fileset the longer it
> takes to remove the clone, am I right?

Removing a clone requires returning all copy-one-write (COW) for 
modified files or deleted files in the original fileset.

NOTE:  If a deleted file had been first modified while the clone 
existed, and then deleted, then the move to the clone must move _ONLY_ 
the blocks which were not previously COW'ed to the clone.  So it is not 
as simple as just moving all the extents in mass to the clone.  Only 
selected extent information can be moved and the parts that were 
modified after the clone was created, then they get deleted.

The longer a clone exists while file modifications to files that existed 
at the time the clone was created, the more COW data that needs to be 
deleted when the clone is removed.

> So I had directories with upwards of 500,000 files in them.

You really Really REALLY want to see if you can get a v5.* version of 
Tru64 UNIX and then recreate your domains so that they are DVN 4 so that 
these directories will have the shadow b-tree index files.  These b-tree 
files give you near linear add, lookup, remove access to your 
directories.

> Doing ...
> ls -1 >filelist
> takes a long time.

use "/bin/ls -f".  Using /bin/ls means you have not grabbed an alternate 
version of ls, or used a shell alias.  The -f option turns off sorting, 
this will save you time.  Never ask ls to get any file information if 
you want speed.  Asking for size or dates on a file or using an ls that 
will colorize the file based on file type or protections (eg. gnu ls or 
csh built-in ls) will slow down the world while ls does an lstat() 
system call on every file in the directory.

Another feature of -f is that this is the order that the files are 
actually stored in the directory.

> xargs -i  rm -f {} <filelist

If you do _NOT_ have DVN 4 domains, then each delete must do a 
sequential search of the directory until it finds the file to be 
removed.  Just doing a back-of-the-envolope calculation I'm guessing 
that your directory is around 12MB to 15MB in size.  So using DVN 3 
disks, that is a lot of sequential searching.  Assume on average you 
will end up searching half of the file.

I think, but I am unsure, that as names are removed from the beginning 
of a directory the entries are marked as empty and if they are adjacent 
to another empty entry, the 2 entries are merged into one larger empty 
entry up to 512 bytes in size.  So if you delete from the front of the 
directory, then as more and more of the entries in the beginning of the 
directory get removed, the search will be able to take giant steps of 
512 bytes over the previously removed entries at the beginning of the 
file. 

I am even weaker about this next thing, but I think the directory lookup 
code keeps a hint about where to start the next search based on where it 
stopped the previous search.  So if you delete from the beginning, then 
the next file to delete should start its lookup at just the right place.

So try using /bin/ls -f to select the files to be removed.  That might 
make deleting files more efficient.

> Would it be more efficient to reverse the order of files in filelist?
> I'm thinking a rm would delete a directory entry them perhaps all the
> entries below get shuffled up to close the gap in the directory file?

Deleting from the back would hurt even more.  First when an entire 8K 
page at the end of the directory becomes empty, then extra work is done 
to free that storage from the directory.  Where as if you delete entries 
from the beginning, then you get to keep all the directory pages until 
you maybe delete the very last entry.  Less work.

Also if you delete from the end, using a DVN 3 format domain you will 
force the file system to search the entire directory from the beginning 
each time.  If my recollections are right about the search hint and the 
consolidations of empty entries into 512 byte chunks, then deleting from 
the back will defeat that and then you will be sequentially searching a 
very large directory.

> What I'm doing now is a mv of the directory to a new name.
> Recreate the directory.
> then rm -r newdirname
> This doesnt seem to be working any faster.

I think it would be better to use the /bin/ls -f to get the list of 
names and delete them in the order they are stored in the directory.  
Only just a little better, not too much.

rm -r will do an lstat() of every file in the directory before it does 
the delete.  It is doing the lstat() to find subdirectories.  I think (I 
could be wrong about what I think) rm builds a list of all the files 
first, so with 500,000 files to be deleted, that is a lot of user memory 
consumed.  Plus it is unlikely that the file lstat()'ed at the beginning 
of the directory will no longer be in the cache, so all the work to get 
the lstat() information will have to be read back into memory yet again.  
A real waste of disk I/O bandwidth.

For a small directory, rm -r is not an issue as the cache will have all 
the lstat() info still hanging around in memory so the file system can 
defer extra I/O.  But 500,000 is a lot of information to keep around in 
the cache, and more than likely it will be gone by the time the actual 
delete comes along.

        /bin/ls -f directory | xarge rm -f      # I think the best

And while I think the above would be the best, I have not tested this, 
I'm just going strictly on theory and educated guesses (_VERY_ educated 
guess :-)
 
> I really need these directories cleared so that the vdump wont take so
> long.

Try very hard to have Tru64 UNIX v5.* and DVN 4 domains to get the 
directory shadow b-tree index files.  It will make a huge difference in 
directory management.

Delete files in the order they are stored in the directory. Use /bin/ls 
-f to get the list of files in the order they are stored in directory.

Avoid rm -r
Avoid any ls options or alternate ls commands that will attempt to get 
file information (kind of file, size, date, protections, ownership, 
etc...)
Try to do the delete before creating the clone.  Once the clone is 
created, the deletes just move the file's storage to the clone, and then 
you get to do the real delete when the clone is removed.

                                        Bob Harris

> thanx in advance,
> Jeremy Thomson


  reply	other threads:[~2004-09-23  2:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-23  1:16 Efficient way of deleted large directories Jeremy Thomson
2004-09-23  2:37 ` Bob Harris [this message]
2004-09-23 22:59   ` Jeremy Thomson
2004-09-24  2:13     ` Bob Harris
2004-09-26 22:50       ` Jeremy Thomson
2004-09-23 13:23 ` Peter da Silva
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox