From razor@ldc.ro  Sat Jul 26 12:02:24 2003
Return-Path: <razor@ldc.ro>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id AA5BA37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 26 Jul 2003 12:02:24 -0700 (PDT)
Received: from ldc.ro (ldc-gw.rdsnet.ro [213.157.163.8])
	by mx1.FreeBSD.org (Postfix) with SMTP id 4894F43F85
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 26 Jul 2003 12:02:15 -0700 (PDT)
	(envelope-from razor@ldc.ro)
Received: (qmail 29202 invoked by uid 666); 26 Jul 2003 19:02:13 -0000
Message-Id: <20030726190213.29201.qmail@ldc.ro>
Date: 26 Jul 2003 19:02:13 -0000
From: Alex Popa <razor@ldc.ro>
Reply-To: Alex Popa <razor@ldc.ro>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: FreeBSD -stable and -current free space handling for UFS filesystems
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         54884
>Category:       kern
>Synopsis:       FreeBSD -stable and -current free space handling for UFS filesystems
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    mckusick
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 26 12:10:19 PDT 2003
>Closed-Date:    Wed Jan 11 06:07:24 UTC 2012
>Last-Modified:  Wed Jan 11 06:07:24 UTC 2012
>Originator:     Alex Popa
>Release:        FreeBSD 4.8-STABLE i386 / FreeBSD 5.1-CURRENT i386
>Organization:
>Environment:
System: FreeBSD xxx.xxx.xx 4.8-STABLE FreeBSD 4.8-STABLE #0: Fri Jul 4 14:01:45 EEST 2003 root@xxx.xxx.xx:/usr/obj/usr/src/sys/XXX i386

>Description:

There appears to be a caching of free space on UFS1 filesystem in the
filesystem superblock.  These caching methods appear to be different in
-current and -stable.

An update free space value for a certain UFS1 filesystem mounted on a
-current kernel will be seen when the filesystem is mounted in -stable.
However, if there is a change of the free space while the filesystem is
mounted in -stable, the change will not reflect in -current.

Please note this is NOT related to the reserved percent of UFS
filesystems (-m flag to tunefs).

>How-To-Repeat:

Make sure an UFS1 filesystem is clean.  Force fsck both on -current and
-stable (see below).

Mount the filesystem in -current, then create a large file, preferably
amounting to a large percentage of the filesystem size.  Write down the
values returned by df for that filesystem, then reboot to -stable and
remove the file.  Reboot again to -current, and notice the values from
df have not changed.  However, the file can be created again, and
deleted again in -stable.

Another way to abuse this is to create the files on -stable and remove
them in -current.  This will make the used blocks count on the
filesystem to decrease with each repetition.

It is possible to fix the free space issue by forcing fsck.  Otherwise
the filesystem will appear clean.  However, it seems that the -stable
and -current versions of fsck do not check for the same things, and only
fix the issue for their respective OS versions.  Mounting the filesystem
read/write on -current, after the -current fsck is run will cause the
kernel to update both versions of the free space value.

Some command outputs
STABLE:
*on fsck -p
/dev/ad0s2g: clean, -212550 free (79930 frags, -36560 blocks, 3.5% fragmentation)

*on forcing fsck:
** /dev/ad0s2g
** Last Mounted on /usr
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
SUMMARY INFORMATION BAD
SALVAGE? [yn] y
FREE BLK COUNT(S) WRONG IN SUPERBLK
SALVAGE? [yn] y
208421 files, 1831342 used, 422700 free
(80596 frags, 42763 blocks, 3.6% fragmentation)

CURRENT:
*on fsck -p
/dev/ad0s2g: FILESYSTEM CLEAN; SKIPPING CHECKS
/dev/ad0s2g: clean, -212550 free (79930 frags, -36560 blocks, 3.5% fragmentation)
*on forcing fsck
** /dev/ad0s2g
** Last Mounted on /usr
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
SUMMARY BLK COUNT(S) WRONG IN SUPERBLK
SALVAGE? [yn] y
208421 files, 1831344 used, 422698 free (80586 frags, 42764
blocks, 3.6% fragmentation)
***** FILE SYSTEM WAS MODIFIED *****


Fun things to do:
(1) Get the filesystem usage figure to over 109% on an UFS1 filesystem,
which has the default reserved percentage for the superuser at 8%, or
get df to report more used blocks than the filesystem size.
Example:
Filesystem  1K-blocks     Used   Avail Capacity  Mounted on
/dev/ad0s2g   4508084  4933184 -785746   119%    /usr2

(2) Get the filesystem usage figure to be negative.
Example:
Filesystem  1K-blocks     Used   Avail Capacity  Mounted on
/dev/ad0s2g   4508084  -282454 4429892    -7%    /usr


>Fix:
Workaround by forcing fsck when booting from one version to the other,
or do not use one UFS1 filesystem under both versions of FreeBSD.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->kirk 
Responsible-Changed-By: kris 
Responsible-Changed-When: Fri Oct 10 22:47:03 PDT 2003 
Responsible-Changed-Why:  
Assign to softupdates maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54884 
Responsible-Changed-From-To: kirk->mckusick 
Responsible-Changed-By: kris 
Responsible-Changed-When: Sat Oct 11 01:06:32 PDT 2003 
Responsible-Changed-Why:  
Correct kirk's user id 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54884 

From: Andrey Rabeshko <admin@atrace.com>
To: bug-followup@FreeBSD.org, razor@ldc.ro
Cc:  
Subject: Re: kern/54884: FreeBSD -stable and -current free space handling
 for UFS filesystems
Date: Wed, 05 Mar 2008 12:28:06 +0200

 I have the same problem on UFS2 Filesystems on FreeBSD 6.3 and 7.0
 I face with it everyday, when mysql creates and deletes big tmp tables 
 on 2G /var partition. When i move mysql temp to big partition (20-30G of 
 free space), problem disappears.
 
 Got this problem on different hardware and servers.
 
 sun# du -sh /var/
 210M    /var/
 sun# df -h /var
 Filesystem       Size    Used   Avail Capacity  Mounted on
 /dev/amrd0s1e    1.9G    1.1G    707M    61%    /var
 sun# fsck /var
 ** /dev/amrd0s1e (NO WRITE)
 ** Last Mounted on /var
 ** Phase 1 - Check Blocks and Sizes
 INCORRECT BLOCK COUNT I=235629 (1851264 should be 1849536)
 CORRECT? no
 
 ** Phase 2 - Check Pathnames
 ** Phase 3 - Check Connectivity
 ** Phase 4 - Check Reference Counts
 UNREF FILE I=47127  OWNER=root MODE=140666
 SIZE=0 MTIME=Mar  5 01:01 2008
 CLEAR? no
 
 UNREF FILE I=235629  OWNER=root MODE=100600
 SIZE=947341890 MTIME=Mar  5 13:19 2008
 CLEAR? no
 
 ** Phase 5 - Check Cyl groups
 FREE BLK COUNT(S) WRONG IN SUPERBLK
 SALVAGE? no
 
 SUMMARY INFORMATION BAD
 SALVAGE? no
 
 BLK(S) MISSING IN BIT MAPS
 SALVAGE? no
State-Changed-From-To: open->closed 
State-Changed-By: mckusick 
State-Changed-When: Wed Jan 11 06:03:17 UTC 2012 
State-Changed-Why:  
This problem was finally fixed in 8.0 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54884 
>Unformatted:
