Discrepancy in free space reported by df and du

book

Article ID: 100010424

calendar_today

Updated On:

Description

Error Message

Discrepancy in free space reported by df and du

 

Resolution

It is common for applications to acquire an exclusive use lock on a temporary file by opening it and deleting it immediately The file will still be opened by the process, but no other process can get hold of it because it no longer exists in the directory structure. For example,
 
# cd /voltmp
# mkfile 2000m tmpfile
# sleep 999999 < tmpfile&
[5] 28882
 
# rm tmpfile
 
# df -k /voltmp
Filesystem kbytes used avail capacity Mounted on
/dev/vx/dsk/datadg/voltmp
6291456 5132210 1086799 83% /voltmp
 
# du -sk /voltmp
3066193 /voltmp
 
There is a discrepancy of 2GB in the free space reported by df and du.
 
pfiles shows that the file is still opened by process 28882, but there is no trace of it in the directory structure.
 
jacaranda# pfiles 28882
28882: sleep 999998888
Current rlimit: 256 file descriptors
0: S_IFREG mode:0600 dev:223,55022 ino:8 uid:0 gid:1size:2097152000 <<<< This inode is stillopened.
O_RDONLY|O_LARGEFILE
1: S_IFCHR mode:0620 dev:223,0 ino:77990 uid:0 gid:7rdev:24,5
O_RDWR
2: S_IFCHR mode:0620 dev:223,0 ino:77990 uid:0 gid:7rdev:24,5
O_RDWR
5: S_IFCHR mode:0620 dev:223,0 ino:77990 uid:0 gid:7rdev:24,5
O_RDWR
8: S_IFREG mode:0644 dev:223,0 ino:231957 uid:0 gid:0size:4464
O_RDWR
9: S_IFREG mode:0644 dev:223,0 ino:231957 uid:0 gid:0size:4464
O_RDWR
 
The following script can be used to search all processes for the missing files. The script is named as "missing inodes".
 
---------- Begin script missinginodes--------------
#!/bin/ksh
 
# This script will search deleted files that is stillopened by processes
# in the specified mounted file system. Thosedeleted but still kept open
# files will cause a discrepancy in the free space asreported by df and du.
 
# This script will create a temp files in /tmp withname started
# with missinginodes to store the inode list. Ifthere is already
# an ilist file (e.g. /tmp/missinginodes.1232), youcan reuse the
# file with the -i option.
 
PATH=/usr/bin; export PATH
 
CMDNAME=´basename $0´
 
USAGE="Usage: $CMDNAME [-i ]"
 
ILISTFILE=
 
while getopts i: option
do
case $option in
i) ILISTFILE=$OPTARG
;;
?) echo $USAGE
exit 1;;
esac
done
 
shift $(($OPTIND -1))
 
if [ $# -lt 1 ]
then
echo "$USAGE"
exit 1
fi
 
MNTPOINT=$1
 
if ! cat /etc/mnttab | awk '{print $2}' | grep$MNTPOINT > /dev/null
then
echo "$MNTPOINT is not a mountpoint"
exit 1
fi
 
DEVICE=´df -k $MNTPOINT | tail +2 | head -1 |awk '{print $1}'´
DEVINODE=´ls -lL $DEVICE | awk '{print $5, $6}'| sed 's/, */,/
s/ [^ ]*$//
s/ //g' ´
 
if [ -z "$ILISTFILE" ]
then
ILISTFILE=/tmp/$CMDNAME.$$
echo "Generating inodelist...."
find $MNTPOINT -mount -ls >$ILISTFILE
fi
 
echo "Searching processes with deletedfiles..."
 
(cd /proc; ls ) | while read p
do
MESG=´pfiles $p | grep"S_IFREG.*dev:$DEVINODE"´
if [ $? -eq 0 ]
then
echo "$MESG" | while read m
do
ino=´echo "$m" | sed's/.*ino:\([0-9]*\).*/\1/'´
if ! grep -l "^ *$ino " $ILISTFILE >/dev/null
then
echo Process $p holds missing inode$ino
echo " $m"
fi
done
fi
done
 
----------- End script missinginodes-------------
 
Run this script against the file system mountpoint.
 
jacaranda# missinginodes /voltmp
Generating inode list....
Searching processes with deletedfiles...
Process 28882 holds missing inode 8
0: S_IFREG mode:0600 dev:223,55022 ino:8 uid:0 gid:1size:2097152000
 
It shows that process 28882 is holding the missing inode8 which has a size of 2GB.
 
 
 
 
 

 

Issue/Introduction

Discrepancy in free space reported by df and du