* Efficient way of deleted large directories
@ 2004-09-23 1:16 Jeremy Thomson
2004-09-23 2:37 ` Bob Harris
2004-09-23 13:23 ` Peter da Silva
0 siblings, 2 replies; 6+ messages in thread
From: Jeremy Thomson @ 2004-09-23 1:16 UTC (permalink / raw)
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.
It seems the more activity there is on a cloned fileset the longer it
takes to remove the clone, am I right?
So I had directories with upwards of 500,000 files in them.
Doing ...
ls -1 >filelist
xargs -i rm -f {} <filelist
takes a long time.
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?
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 really need these directories cleared so that the vdump wont take so
long.
thanx in advance,
Jeremy Thomson
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Efficient way of deleted large directories 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-23 13:23 ` Peter da Silva 1 sibling, 1 reply; 6+ messages in thread From: Bob Harris @ 2004-09-23 2:37 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Efficient way of deleted large directories 2004-09-23 2:37 ` Bob Harris @ 2004-09-23 22:59 ` Jeremy Thomson 2004-09-24 2:13 ` Bob Harris 0 siblings, 1 reply; 6+ messages in thread From: Jeremy Thomson @ 2004-09-23 22:59 UTC (permalink / raw) 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. > > 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? > > 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. regards, Jeremy Thomson ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Efficient way of deleted large directories 2004-09-23 22:59 ` Jeremy Thomson @ 2004-09-24 2:13 ` Bob Harris 2004-09-26 22:50 ` Jeremy Thomson 0 siblings, 1 reply; 6+ messages in thread From: Bob Harris @ 2004-09-24 2:13 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Efficient way of deleted large directories 2004-09-24 2:13 ` Bob Harris @ 2004-09-26 22:50 ` Jeremy Thomson 0 siblings, 0 replies; 6+ messages in thread From: Jeremy Thomson @ 2004-09-26 22:50 UTC (permalink / raw) Bob Harris <harris@zk3.dec.com> wrote in message news:<harris-83C45E.22064023092004@cacnews.cac.cpqcorp.net>... > In article <6425a413.0409231459.564df263@posting.google.com>, > panzerboy@gmail.com (Jeremy Thomson) wrote: ... > > 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 The data isnt at all important, one is a log of the output of UniData phantom processes, the other captures of SQL enquiries. We only look at this stuff if something goes wrong. We do have a regular cron'd purge, it was the failure of this that started the whole problem. I had a c program that would compare list of filenames and a cutoff date and output the filenames modified earlier than the cutoff so they could be deleted. It fell over when it couldnt stat() a file. Unbeknownst to me temporary files were being put in one of the directories then renamed. That broke the purge. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Efficient way of deleted large directories 2004-09-23 1:16 Efficient way of deleted large directories Jeremy Thomson 2004-09-23 2:37 ` Bob Harris @ 2004-09-23 13:23 ` Peter da Silva 1 sibling, 0 replies; 6+ messages in thread From: Peter da Silva @ 2004-09-23 13:23 UTC (permalink / raw) In article <6425a413.0409221716.55a1cb5@posting.google.com>, Jeremy Thomson <panzerboy@gmail.com> wrote: > I really need these directories cleared so that the vdump wont take so > long. Deleting files tends to be a slow operation with most UNIX file systems, because each deletion involves updating metadata so it tends to happen synchronously. I've also noticed that advfs is particularly hard hit by large directories. There may not be a better solution. You might consider putting these files on a UFS partition. UFS is also not really fast at deleting, but it seems less out of control with large directories. If these files are REALLY temporary, you could replace the directories with symlinks to a filesystem you just rebuild from scratch, or at least don't vdump... -- I've seen things you people can't imagine. Chimneysweeps on fire over the roofs of London. I've watched kite-strings glitter in the sun at Hyde Park Gate. All these things will be lost in time, like chalk-paintings in the rain. `-_-' Time for your nap. | Peter da Silva | Har du kramat din varg, idag? 'U` ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-09-26 22:50 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2004-09-26 22:50 ` Jeremy Thomson 2004-09-23 13:23 ` Peter da Silva
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox