Unix United Professionals
Would you like to react to this message? Create an account in a few clicks or log in to continue.

What is UFS fragmentation and how can it be determined?

2 posters

Go down

What is UFS fragmentation and how can it be determined? Empty What is UFS fragmentation and how can it be determined?

Post by suran Fri Apr 11, 2008 1:59 pm

This article explains what UFS fragmentation is, how to identify a file system that is fragmented.

What is UFS fragmentation?

There are two file allocation units defined in UFS they are: Block size also known as logical block size and a fragment. On sun4u architecture the UFS block size is 8KB and the default fragment size is 1KB. A fragment can be defined as the smallest addressable part of a UFS.

When a file greater than 8KB is created, UFS allocates 8KB blocks each and an remaining fraction of a block is allocated as one or more fragments within the last block. This is true of a file whose size is less than 96KB, no fragments are allowed when creating files equal to or greater than 96KB i.e only full blocks are used.

UFS will assign one or more fragments of the same file to one logical OS block for files less than 8KB in size. There is however a restriction in that UFS will not allow fragments of the same file to be scattered across more than one OS block. Nevertheless, the same OS block may contain fragments from different files, for example 5 from file1, 2 from file 3 etc assuming a 1KB fragment size.

When the file system becomes heavily utilized, many blocks can be partially filled with allocated fragments. Thus, fragmentation increases and we get what we call a fragmented file system.

In extreme cases the UFS may become so fragmented such that it cannot allocate a single whole block to a new file even though there is a lot of fragmented space.

How do I determine if my file system is fragmented?

Well there are two methods that can be used to determine if your file system is fragmented. It involves using the fsck and fstyp commands.


Let's look at 2 cases. Case 1 being a slightly fragmented file system and case 2 being one that is highly fragmented. In each case I will show you how to determine fragmentation using both the fsck and fstyp commands

Case 1a: A slightly fragmented /opt file system (using fsck)

1) use df -k to physical device on which /opt is mounted:

# df -k /opt

Filesystem kbytes used avail capacity Mounted on

/dev/dsk/c0t0d0s6 2052750 354508 1636660 18% /opt

2) since this is a mounted file system we need to run fsck in read-only mode. This is done using the -n option:

# fsck -n /opt

** /dev/rdsk/c0t0d0s6 (NO WRITE)

** Currently Mounted on /opt
.... edited for brevity

7404 files, 354508 used, 1698242 free (1858 frags, 212048 blocks, 0.0% fragmentation)

The most important line here is the one in red. Let's break it down for simplicity

used = number of fragments that are used each being 1KB by default
free = This is the total number of free fragments in full and partial blocks
frags = The number of free fragments each being 1KB by default
blocks = number of free full blocks each being 8KB

the number of free fragments can be determined using a simply equation:

frags+blocks*8 = free

1858+212048*8 = 1698242

%fragmentation can be calculated using the equation:

frags/(used+free)*100

1858/(354508+1698242)*100= 0.0905127268%

We have determined using fsck and 2 simple formulas that /opt is 0.09% fragmented.

Case 1b: A slightly fragmented /opt file system (using fstyp)

1) use df -k to determine the /opt file system:

df -k /opt

Filesystem kbytes used avail capacity Mounted on

/dev/dsk/c0t0d0s6 2052750 354508 1636660 18% /opt

2) execute the fstyp command as follows:

fstyp -v
/dev/rdsk/c0t0d0s3 |
head
-20

ufs
1024 shift 10 mask 0xfffffc00
.... edited for brevity
blocks 2052750
.... edited for brevity.

nbfree 212048


nffree 1858


The most important lines here are those in red. Let's take a closer look.

nbfree = The number of free full blocks
nffree = The number of free fragments
blocks = The total number of 1KB blocks assigned to the file system. Please note that this block here refers to the smallest allocatable part of the file system i.e the fragment (1KB). Here the block also refers to the total number of fragments since the fsize is set to 1KB.

Using these values the following equation can be used to calculate the %fragmentation:

nffree/blocks*100

1858/2052750*100 = 0.0905127268%

Case 2a: A highly fragmented /opt file system (using fsck)

1) determine the file system for /opt by running a df -k:

df -k /opt

Filesystem kbytes used avail capacity Mounted on

/dev/dsk/c0t1d0s0 10325760 8759075 1463428 86% /opt

2) Run fsck with the -n option as before:

fsck /dev/rdsj/c0t1d0s0

** /dev/rdsk/c0t1d0s0

....edited for brevity

803827 files, 8759075 used, 1566685 free (1566685 frags, 0 blocks, 15.1% fragmentation)

As with the case in the slightly fragmented file sytem the last line in red here is the most important.

3) using the equation frags/(used+free)*100 = 1566685/(8759075+1566685)*100 = 15.1728587%

Thus we see that the /opt file system is 15.1% fragmented. Even though the file system is 86% free, there are no free full 8KB blocks left and therefore no file greater than 7KB can be created.

Case 2b: A highly fragmented /opt file system (using fstyp)

1) Determine the file system for /opt using df -k:

df -k /opt

Filesystem kbytes used avail capacity Mounted on

/dev/dsk/c0t1d0s0 10325760 8759075 1463428 86% /opt

2) run fstyp as follows:

fstyp -v /dev/rdsk/c0t1d0s0 | head -20

.... edited for brevity

blocks 10325760

....edited for brevity

nbfree 0
...edited for brevity

nffree 1566685


Once again the red indicates the three most important parameters of the fstyp.

3) using the equation nffree/blocks*100 = 1566685/10325760*100 = 15.1725878

So using fstyp and a simple formula we can see that the file system is 15.17% fragmented

suran

Posts : 15
Join date : 2008-04-10

Back to top Go down

What is UFS fragmentation and how can it be determined? Empty And the Cure....

Post by poshpaws Tue Apr 15, 2008 12:22 pm

backup the volume and newfs it again

but wait ... use the -o space option to newfs (default is time)
this option will not prevent fragmentation but will help.


Prevention is the best option it's less risky to ask your users if they really need 100,0000 1k jpegs!
(I have seen this before)

poshpaws

Posts : 1
Join date : 2008-04-15

http://www.linkedin.com/in/poshpaws

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum