On Saturday 19 December 2009 04:59:46 Peter Barada wrote:
> On Fri, 2009-12-18 at 18:03 +0800, JiSheng Zhang wrote:
> > Hi Charles,
> >
> > 2009/12/16 Charles Manning <manningc2@actrix.gen.nz>:
> > > On Wednesday 16 December 2009 16:36:02 JiSheng Zhang wrote:
> > >> 2009/12/16 JiSheng Zhang <jszhang3@gmail.com>:
> > >> > Hi list,
> > >> >
> > >> > First mount an empty partition, then cp some files to the mnt dir
> > >> > then run "df", and then delete all the files, then run "df" again.
> > >> > df report this time is wrong. It seems that the chunks occupied by
> > >> > unlinked files aren't recycled until needed.
> > >> >
> > >> > Is this a bug or characteristic?
> > >
> > > I don't see that problem.
> > >
> > > root@linux-dual-head:/opt/y/cvs/yaffs2# mount -t yaffs2 /dev/mtdblock0
> > > /mnt root@linux-dual-head:/opt/y/cvs/yaffs2# df
> > > Filesystem 1K-blocks Used Available Use% Mounted on
> > > /dev/mtdblock0 65536 1152 64384 2% /mnt
> >
> > Here used blocks is 1152.
> >
> > > root@linux-dual-head:/opt/y/cvs/yaffs2# cp * /mnt
> > > root@linux-dual-head:/opt/y/cvs/yaffs2# df
> > > Filesystem 1K-blocks Used Available Use% Mounted on
> > > /dev/mtdblock0 65536 5860 59676 9% /mnt
> > > root@linux-dual-head:/opt/y/cvs/yaffs2# rm /mnt/*
> > > root@linux-dual-head:/opt/y/cvs/yaffs2# df
> > > Filesystem 1K-blocks Used Available Use% Mounted on
> > > /dev/mtdblock0 65536 1156 64380 2% /mnt
> >
> > Here used blocks is 1156. So there are 4 blocks lost.
>
> Would that be the root directory?
Yes that is one chunk which has been used by the root directory.
> I wonder if:
>
> mount -t yaffs2 /dev/mtdblock0 /mnt
> df
> ls -ld /mnt
> cp * /mnt
> df
> ls -ld /mnt
> rm /mnt/*
> df
> ls -ld /mnt
>
> would show that the root directory uses the 4 blocks to hold the
> directory entries for the files copied in.
Not quite
A directory object does not hold its contents. Instead each object's details
are stored in an object header.
However, writing a file in a directory causes the object header for the
directory to be updated too (since the directories mtime and ctime must be
updated). If there was no previous object header for root then one will be
written.
>
> Is there code to garbage collect directories when the entries are
> deleted?
This is not needed.
For a better understanding, read
http://users.actrix.co.nz/manningc/yaffs/HowYaffsWorks.pdf
This is certainly not a "leak". The only "lost" chunk is that root directory
and that is expected.
I just ran the following script with no change in the free chunks.
#! /bin/bash
for ((i=0; i < 100; i++))
do
echo start $i
cat /proc/yaffs | grep nFreeChunks
for ((j=0; j < 1000; j++)) ; do touch aa$j; done
echo created $i
cat /proc/yaffs | grep nFreeChunks
for ((j=0; j < 1000; j++)) ; do rm aa$j; done
echo rm done $i
cat /proc/yaffs | grep nFreeChunks
done
start 0
nFreeChunks........ 32767
created 0
nFreeChunks........ 31767
rm done 0
nFreeChunks........ 32767
start 1
nFreeChunks........ 32767
created 1
nFreeChunks........ 31767
rm done 1
nFreeChunks........ 32767
.....
rm done 98
nFreeChunks........ 32767
start 99
nFreeChunks........ 32767
created 99
nFreeChunks........ 31767
rm done 99
nFreeChunks........ 32767
Charles