From: Bob Harris <harris@zk3.dec.com>
Subject: Re: Efficient way of deleted large directories
Date: Fri, 24 Sep 2004 02:13:22 GMT [thread overview]
Message-ID: <harris-83C45E.22064023092004@cacnews.cac.cpqcorp.net> (raw)
In-Reply-To: 6425a413.0409231459.564df263@posting.google.com
In article <6425a413.0409231459.564df263@posting.google.com>,
panzerboy@gmail.com (Jeremy Thomson) wrote:
> Bob Harris <harris@zk3.dec.com> wrote in message
> news:<harris-52EA92.22311222092004@cacnews.cac.cpqcorp.net>...
> > In article <6425a413.0409221716.55a1cb5@posting.google.com>,
> > panzerboy@gmail.com (Jeremy Thomson) wrote:
> ...
>
> > 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.
>
> We have Tru64 v5.1, the showfdmn shows domain version 4.
that's good.
> > 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.
> ...
> > > 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.
>
> I believe we do.
> When you do a listing of a large directory the first time thru takes
> ages.
> After that subsequent listings are very fast.
> Does ADVFs keep that index in memory?
No. It is a file on disk. You can look at it using the
/usr/sbin/showfile -i directory
command. The -i option displays the information about the directory's
index file. man showfile
AdvFS does cache recently accessed pages, so the directory and the index
file would most likely be in cache for a 2nd pass.
But I would not expect the index file to be used for a /bin/ls -f or
even a /bin/ls operation. The index file would only get called into
play if the ls command was doing lstat() operations on the files, like
when you do an 'ls -l' or any other ls option that needs to get file
specific information. Directories only hold the name and tag of the
file (where tag can be equated to a UFS inode number). All other
information about a file is kept in metadata files.
The reason the index file would not get called into play for a simple ls
is that the only thing being done is to sequentially read the directory
to get the names and tags of the files. The index file is not needed
for that.
The index file comes into play when doing a random lookup of a file, or
adding a new file to make sure it does not already exist and to find an
empty spot in the directory to stick the new name as well as updating
the directory and the index with the new name, and finally if you are
removing a name from the directory, the lookup to find the name and the
work needed to remove the name from the directory and the index.
If the ls is told to ask for more than just the name of the files in the
directory, then the ls command must lstat() the names, and the lstat()
operation will cause a random lookup in the directory and that is when
the index file gets called into play during an ls.
If there is sufficient memory on the system to cache all the file
metadata after doing something like an 'ls -l' then the first one will
be a bear because of all the random disk seeks to find all the metadata,
but the 2nd one should go faster if it can find all the metadata sitting
in the cache. But you have to have a lot of idle memory sitting around
to hold the metadata for 500,000 files. Plus on v5.1 the AdvFS cache is
fixed in size as a percent of physical memory. I think the default was
that AdvFS was allowed to use up to 30% of physical memory (or was it 7%
- it has been too long and I forget things too easily :-). It was a
tunable. In some later version, AdvFS was integrated with the UBC, so
that it could all of memory if VM did not want it, or use just a little
of memory if VM's demands were stronger.
> > > 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
> >
> ...
> > 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
>
> Ta for that Bob.
> It seems the problem is mostly there was far too many files but I'll
> change our purge scripts to use /bin/ls -f
>
> Finally got the directories deleted, probably took about 20 hours over
> a couple of days.
> That was two directories with 518,000 and 528,000 files respectively.
> The last way I tried deleteing was ls -1r | xargs -i rm -f {}
> That seemed a little bit faster though by that time there was only
> 200,000 files to delete, so I guess it would have been faster anyway.
I think that /bin/ls -1r would just change the name sorting order, but I
do not think it would cause an lstat() operation. And since you have
index files, there is not as much benefit to removing the files in a
specific order. But if you want to squeeze out very last drop of
performance, then I think
/bin/ls -1f directory | xargs rm -f
would be about as good as it gets. You might squeeze a few tiny drops
out of writing your own C program to read the directory using readdir()
and call remove(). That would eliminate multiple invocations of the rm
command, but the xargs command does bunch up the files so that it does
not need to invoke rm too many times. I think ls -f into xargs is good
enough.
> regards,
> Jeremy Thomson
I don't know what the files in the huge directory(s) are used for, if
you have a way to pruning them on a regular basis, say via a cron job,
it might help with the sudden load demand to do this before the vdump.
Bob Harris
next prev parent reply other threads:[~2004-09-24 2:13 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
2004-09-23 22:59 ` Jeremy Thomson
2004-09-24 2:13 ` Bob Harris [this message]
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