Re: Question regarding reported directory sizes.

2004-05-25 Thread Cordula's Web
 I have a very large directory (say, a mail spool) whose directory entry is 
 approx 606K..
 drwx--  5 cyrus  cyrus  606208 May 25 10:29 .
 Now.. That directory had a lot of files in it.  However, after deleting all 
 of the files in that directory, the directory entry's size stays the same. 
 I realize this is fairly unimportant, however is there a way to 'garbage 
 collect' that directory entry and all others like it?

Have you tried the obvious?
  1. mkdir tmpdir
  2. mv everything from olddir/* to tmpdir, [*]
  3. rmdir olddir
  4. mv tmpdir olddir

[*] mv olddir/* tempdir may not work if you have many files left.
Use a script, find(1), tar(1) or whatever you feel comfortable
with, instead.

The directory could be in theory compacted, but only if it is not
in use (i.e. not mapped in the kernel's VNODE(9)s). It's perhaps
too cumbersome to create a syscall that would do this.

 Thanks!
 Jason DiCioccio

-- 
Cordula's Web. http://www.cordula.ws/

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Question regarding reported directory sizes.

2004-05-25 Thread Dan Nelson
In the last episode (May 25), Jason DiCioccio said:
 I know this question may seem silly..  However, here's my scenario.
 
 I have a very large directory (say, a mail spool) whose directory entry is 
 approx 606K..
 drwx--  5 cyrus  cyrus  606208 May 25 10:29 .
 Now.. That directory had a lot of files in it.  However, after deleting all 
 of the files in that directory, the directory entry's size stays the same. 
 I realize this is fairly unimportant, however is there a way to 'garbage 
 collect' that directory entry and all others like it?

Create another file in the directory, and you'll see it shrink down. 
The truncation code is in the file create codepath, not the delete one
(which means it's not constantly trying to shrink the directory as you
delete files).

-- 
Dan Nelson
[EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Question regarding reported directory sizes.

2004-05-25 Thread Jason DiCioccio
Thanks Dan..  However, this does not appear to be happening...  I could of 
course create a new directory and move everything into it as was suggested 
earlier.  However, this is more of a curiosity thing than anything.. I'm 
wondering if at any point the entry does become truncated, because it 
hasn't happened yet, even after the creation of files.

The OS release is: 5.2-CURRENT from May 12th
Thanks!
Jason DiCioccio
--On Tuesday, May 25, 2004 10:42:42 -0500 Dan Nelson 
[EMAIL PROTECTED] wrote:

In the last episode (May 25), Jason DiCioccio said:
I know this question may seem silly..  However, here's my scenario.
I have a very large directory (say, a mail spool) whose directory entry
is  approx 606K..
drwx--  5 cyrus  cyrus  606208 May 25 10:29 .
Now.. That directory had a lot of files in it.  However, after deleting
all  of the files in that directory, the directory entry's size stays
the same.  I realize this is fairly unimportant, however is there a way
to 'garbage  collect' that directory entry and all others like it?
Create another file in the directory, and you'll see it shrink down.
The truncation code is in the file create codepath, not the delete one
(which means it's not constantly trying to shrink the directory as you
delete files).
--
Dan Nelson
[EMAIL PROTECTED]


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Question regarding reported directory sizes.

2004-05-25 Thread Dan Nelson
In the last episode (May 25), Jason DiCioccio said:
 [EMAIL PROTECTED] wrote:
 In the last episode (May 25), Jason DiCioccio said:
 I have a very large directory (say, a mail spool) whose directory entry
 is  approx 606K..
 drwx--  5 cyrus  cyrus  606208 May 25 10:29 .
 
 Now.. That directory had a lot of files in it.  However, after
 deleting all of the files in that directory, the directory entry's
 size stays the same.  I realize this is fairly unimportant, however
 is there a way to 'garbage collect' that directory entry and all
 others like it?
 
 Create another file in the directory, and you'll see it shrink down.
 The truncation code is in the file create codepath, not the delete
 one (which means it's not constantly trying to shrink the directory
 as you delete files).

 Thanks Dan..  However, this does not appear to be happening...  I
 could of course create a new directory and move everything into it as
 was suggested earlier.  However, this is more of a curiosity thing
 than anything.. I'm wondering if at any point the entry does become
 truncated, because it hasn't happened yet, even after the creation of
 files.

Your first post said you deleted all the files, but your second post
mentions move everything into it.  The kernel can only truncate the
directory past the last filename.  If you happen to have an existing
file in there that's sitting at the 600k mark in the directory, then
that's as small as the directory can get.

Run this script in a test directory to see it in action.  Put the
script itself someplace so it doesn't affect the dir sizes:

#! /bin/sh
echo Creating 1000 files
for i in `jot 1000 1` ; do touch $i ; done
ls -ld .
echo Deleting 999 files, leaving file 10500
for i in `jot 500 1` `jot 499 10501` ; do rm $i ; done
ls -ld .
echo Creating 1 file.  Directory should shrink by 50%
touch 1 ; ls -ld .
echo Deleting last file
rm 10500 ; ls -ld .
echo Creating another file.  Directory should shrink to one frag
touch 10001 ; ls -ld .
rm 1 10001

-- 
Dan Nelson
[EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]