From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Thread: fa528,d86f44c2176449dd X-Google-Attributes: gidfa528,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!tdsnet-transit!newspeer.tds.net!HSNX.atgi.net!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!news.cpqcorp.net!53ab2750!not-for-mail From: Bob Harris Newsgroups: comp.unix.tru64 Subject: Re: Efficient way of deleted large directories References: <6425a413.0409221716.55a1cb5@posting.google.com> User-Agent: MT-NewsWatcher/3.4 (PPC Mac OS X) Message-ID: Date: Thu, 23 Sep 2004 02:37:38 GMT NNTP-Posting-Host: 16.115.192.72 X-Complaints-To: abuse@HP.com X-Trace: news.cpqcorp.net 1095907058 16.115.192.72 (Wed, 22 Sep 2004 19:37:38 PDT) NNTP-Posting-Date: Wed, 22 Sep 2004 19:37:38 PDT Organization: Hewlett-Packard Company Xref: g2news1.google.com comp.unix.tru64:309 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 {} 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