Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Unix Operating Systems > HP-UX Operating System

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-16-2008, 05:32 PM
GertK
 
Posts: n/a
Default How to efficiently remove large directory tree

Hi,

A oracle process has tried to dump a core but created recursively a very
deeply nested directory structure like this instead:
core_8286/core_8286/core_8286/core_8286/....etc etc. until the inodes
ran out.
The amount of subdirectories is estimated to be almost 100,000 looking
at the increase of used inodes on the filesystem (vxfs on HPUX 11.0).
The process of creating these dirs has stopped now. After enlarging the
fs, there is free space and enough free inodes available. I'm trying to
get rid of all the subdirs.
I've tried to do a # rm -r from the first core_8286 level, but after
several hours it was still running and a trace on system calls showed it
was very busy with chdir calls and seemed to be looping, so I killed it.
A find core_8286 -depth |xargs rm -r also ran for hours without result.
Problem is that most unix utilities fail on these huge path lenghts;
du gives "path too long", bdf fails as well.
A script I made that just did a loop with a "cd core_8286" 100 times
showed that the deeper I get the longer it takes to execute a block of
100 cd commands. This is probably due to system calls taking longer
while traversing longer path names (exponential growth?)

Does anyone have a efficient method of cleaning this up while keeping
the filesystem online (50 databases running on it, so I want to avoid
downtime because of restoring the filesystem)?

Txs beforehand
Gert.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-16-2008, 05:32 PM
Darren Dunham
 
Posts: n/a
Default Re: How to efficiently remove large directory tree

In comp.unix.solaris GertK <gert.koopmanREMO@vethisplanet.nl> wrote:
> Hi,


> A oracle process has tried to dump a core but created recursively a very
> deeply nested directory structure like this instead:
> core_8286/core_8286/core_8286/core_8286/....etc etc. until the inodes
> ran out.


[snip]

> Does anyone have a efficient method of cleaning this up while keeping
> the filesystem online (50 databases running on it, so I want to avoid
> downtime because of restoring the filesystem)?


If you have the filesystem online, then I can't think of anything you
can do but use the standard OS interfaces to handle it.

At the moment it sounds like things are stable so even long-running
processes should be sufficient. You have a program that descended a few
hundred levels. Can you write one that attempts to go to the bottom and
see if it terminates? Do you have an estimate of how many files there
are in it? (total inodes in use - inodes elsewhere on the filesystem).

Try running something like....

% perl -e '$level=0;while (chdir "core_8286") { $level++; print "level $level\n" unless ($level % 100); } print "Terminated at level $level\n";'

If that works, then you could have it remove things also... Use the
termination level you get in place of <NUM> below...

% perl -e 'foreach $i (1 .. <NUM>) { chdir "core_8286"; }; while(rmdir "core_8286") { chdir "..";}'

I initially tried to use system (rm -r "xxx" ) there rather than perl's
rmdir because I didn't want a single "off-by-one" error where you don't
hit the bottom to kill the whole thing. But even a single rm -r at the
100K+ level took many dozens of seconds. The above only took about a
minute or two to delete a little over 100K descending directories.

This doesn't ever try to keep the entire pathname anywhere except in the
processes current directory, so there's nothing to blow up in the code
itself. I don't think it's any faster than anything else using the
filesystem, but it doesn't wast time worrying about where it is.

On an Ultra 5 with a slow disk and VxFS I was able to create 100K
directories in about a minute or two. That first script would descend
and find the bottom in about 15 seconds.

Good luck..

--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-16-2008, 05:32 PM
Mark Hittinger
 
Posts: n/a
Default Re: How to efficiently remove large directory tree

GertK <gert.koopmanREMO@VETHISplanet.nl> writes:

>A oracle process has tried to dump a core but created recursively a very
>deeply nested directory structure like this instead:
>core_8286/core_8286/core_8286/core_8286/....etc etc. until the inodes
>ran out.
> ...
>Does anyone have a efficient method of cleaning this up while keeping
>the filesystem online (50 databases running on it, so I want to avoid
>downtime because of restoring the filesystem)?


Don't know about efficient since you've got to stay online. How about
using a slightly backwards approach? Instead of attempting to go to
the bottom and remove the file why not try removing things from the
top end?

For example:

#! /bin/sh
renice 5 $$
while [ 1 ] ; do
mv core_8286 core_8286.rm
if [ $? -ne 0 ] ; then exit ; fi
mv core_8286.rm/core_8286 .
if [ $? -ne 0 ] ; then exit ; fi
rmdir core_8286.rm
if [ $? -ne 0 ] ; then exit ; fi
done

After one pass you have the same directory tree in core_8286 but with the
top level snipped off. It could just grind away in the background until
it hits the bottom.

Anyway just another idea to try. Good luck!

Later

Mark Hittinger
bugs@pu.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-16-2008, 05:32 PM
Icarus Sparry
 
Posts: n/a
Default Re: How to efficiently remove large directory tree

On Tue, 06 Jan 2004 01:27:03 +0000, Darren Dunham wrote:

> In comp.unix.solaris GertK <gert.koopmanREMO@vethisplanet.nl> wrote:
>> Hi,

>
>> A oracle process has tried to dump a core but created recursively a very
>> deeply nested directory structure like this instead:
>> core_8286/core_8286/core_8286/core_8286/....etc etc. until the inodes
>> ran out.

>


> Good luck..


You could also try a shell solution. (echo -n '.' might need to be changed
to echo -e '.\c', depending on your flavour of shell).

I presume that you are certain that it is an almost infinite tree, and not
a corrupted tree. Use 'ls -ia' to make sure that '.', '..' and 'core_8286'
all have different inode numbers (the number before the filename).

#!/bin/sh
while cd core_8286
do
echo -n '.'
done
echo
echo 'Starting to remove'
cd ..
while rmdir core_8286
do
echo -n 'X'
cd ..
done
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-16-2008, 05:32 PM
reb@cypress.com
 
Posts: n/a
Default Re: How to efficiently remove large directory tree

GertK <gert.koopmanREMO@VETHISplanet.nl> wrote in message news:<btcutt$l4f$1@news.cistron.nl>...
> A oracle process has tried to dump a core but created recursively a very
> deeply nested directory structure like this instead:
> core_8286/core_8286/core_8286/core_8286/....etc etc. until the inodes
> ran out.
> The amount of subdirectories is estimated to be almost 100,000 looking
> at the increase of used inodes on the filesystem (vxfs on HPUX 11.0).
> ...
> A script I made that just did a loop with a "cd core_8286" 100 times
> showed that the deeper I get the longer it takes to execute a block of
> 100 cd commands. This is probably due to system calls taking longer
> while traversing longer path names (exponential growth?)
> ...


(You should prefer to run the clean up directly running on the HP
not a remote host mounting that file system, right)?

What script language did you use?

Looks like some shells (csh and tcsh?) in some circumstances at least,
after each chdir will stat() each parent dir on up the hier. Thus each
shell chdir command from depth N to N+1 will cost one chdir() and N+1
stat() calls; and individual steps down to a deep depth by separate
chdirs will incur an exponential number of stat() calls.

The experience of the other responses suggest perl and sh likely never
produce similar behavior, so probably you are safe to just stick to one
of those. I don't know the purpose in the csh's of doing this, nor if
there's a way to avoid it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-16-2008, 05:32 PM
Darren Dunham
 
Posts: n/a
Default Re: How to efficiently remove large directory tree

In comp.unix.solaris Mark Hittinger <bugs@pu.net> wrote:
> GertK <gert.koopmanREMO@VETHISplanet.nl> writes:


>>A oracle process has tried to dump a core but created recursively a very
>>deeply nested directory structure like this instead:
>>core_8286/core_8286/core_8286/core_8286/....etc etc. until the inodes
>>ran out.


> Don't know about efficient since you've got to stay online. How about
> using a slightly backwards approach? Instead of attempting to go to
> the bottom and remove the file why not try removing things from the
> top end?


> For example:


> #! /bin/sh
> renice 5 $$
> while [ 1 ] ; do
> mv core_8286 core_8286.rm
> if [ $? -ne 0 ] ; then exit ; fi
> mv core_8286.rm/core_8286 .
> if [ $? -ne 0 ] ; then exit ; fi
> rmdir core_8286.rm
> if [ $? -ne 0 ] ; then exit ; fi
> done


> After one pass you have the same directory tree in core_8286 but with the
> top level snipped off. It could just grind away in the background until
> it hits the bottom.


Elegant! I don't think I would have thought of such an approach. It
nicely avoids the need to descend the tree in the first place.

I'd love to know exactly how deep the OP's chain was. I've only tested
with about 100K+ or so due to the time to create/kill the things.

--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-16-2008, 05:32 PM
Darren Dunham
 
Posts: n/a
Default Re: How to efficiently remove large directory tree

In comp.unix.solaris reb@cypress.com wrote:
> What script language did you use?


> Looks like some shells (csh and tcsh?) in some circumstances at least,
> after each chdir will stat() each parent dir on up the hier. Thus each
> shell chdir command from depth N to N+1 will cost one chdir() and N+1
> stat() calls; and individual steps down to a deep depth by separate
> chdirs will incur an exponential number of stat() calls.


> The experience of the other responses suggest perl and sh likely never
> produce similar behavior, so probably you are safe to just stick to one
> of those. I don't know the purpose in the csh's of doing this, nor if
> there's a way to avoid it.


When I was testing this on a Solaris 8 U10, my main problem with shell
scripts wasn't any stat stuff on chdirs, but just the slowness of forks
necessary to invoke the various utilities. Running the previous
poster's shell solution for popping the top directory off and removing
it would remove about 2500 directories a minute on the test box. (That
solution also doesn't use any chdir() calls). C and Perl rewrites of
the same thing both removed about 33K directories a minute. I don't
know if the HP forks would be any lighter weight or not.

--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-16-2008, 05:32 PM
cbigam@somewhereelse.nucleus.com
 
Posts: n/a
Default Re: How to efficiently remove large directory tree

In comp.unix.solaris GertK <gert.koopmanREMO@vethisplanet.nl> wrote:
> Hi,
>
> A oracle process has tried to dump a core but created recursively a very
> deeply nested directory structure like this instead:
> core_8286/core_8286/core_8286/core_8286/....etc etc. until the inodes
> ran out.


I've come across this once, and found some curious shell behaviour that
let me solve it.

One shell (I think /bin/sh) let me recursively cd down into the bottom
level of the directory. Once there, I could use a different shell
(/bin/ksh? Or maybe it was csh, but I doubt it) to recursively
"cd .. && rmdir <dirname>".

I think I was about 39k directories deep, and it took under an hour.

The other possiblity is that unlink might just wipe out the top level
directory. Don't know what happens to the previously allocated inodes
when you do it that way, though.

Colin
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-16-2008, 05:32 PM
Mark Hittinger
 
Posts: n/a
Default Re: How to efficiently remove large directory tree

Darren Dunham <ddunham@redwood.taos.com> writes:
>Elegant! I don't think I would have thought of such an approach. It
>nicely avoids the need to descend the tree in the first place.
>...
>I'd love to know exactly how deep the OP's chain was. I've only tested
>with about 100K+ or so due to the time to create/kill the things.


It also starts freeing inodes up right away. If the path does happen to
have some corruption in it then trimming things from the bottom won't
ever free anything :-(.

If the path is indeed corrupt then the shell script should die as soon as
the corrupted path is brought to the top. Then you have bigger fish to
fry but you can do something like mv the thing into lost+found at that
point.

Later

Mark Hittinger
bugs@pu.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-16-2008, 05:32 PM
Darren Dunham
 
Posts: n/a
Default Re: How to efficiently remove large directory tree

In comp.unix.solaris cbigam@somewhereelse.nucleus.com wrote:
> The other possiblity is that unlink might just wipe out the top level
> directory. Don't know what happens to the previously allocated inodes
> when you do it that way, though.


If you succeeded in doing that, I would expect them to remain allocated
until you could bring the system down and do an fsck. That wouldn't
help the original goal of trying to recover the space/inodes without a
reboot.

However, I was unable to directly unlink the parent directory, even as
root. VxFS does not appear to have a 'clri' utility the way Solaris UFS
does, and unlink fails with "File exists".

--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:56 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572