Free Space Management




                        http://raj-os.blogspot.in/   1
HOME     PREVIOUS TOPIC NEXT
PREVIOUS QUESTION PAPERS FOR OS
CPP TUTORIALS




        http://raj-os.blogspot.in/   2
Recap

In the last class, you have learnt:

• Secondary memory, types of secondary memory

• Various types of heads, advantages of one over other

• Techniques for increasing storage capacity

• Characteristics of the disk

                       http://raj-os.blogspot.in/        3
Objectives

On completion of this period, you would be able to
 know
• Need for free space management


• Various implementations of free space lists


• Bit vector, Linked list, Grouping, Counting




                        http://raj-os.blogspot.in/   4
Understand Free Space Management

• Need for free space management

  – Limited amount of disk space

  – Necessary to reuse the space from deleted files




                   http://raj-os.blogspot.in/         5
Need for Free Space Management

• To keep track of disk space :

   – The system maintains a free space list

   – The free space list records all disk blocks that
     are free




                    http://raj-os.blogspot.in/          6
File Creation & Deletion

• File creation
   – Search the free space list of the required amount of
     space
   – Allocate the space to the new file
   – Remove the space from free space list
• File deletion
   – Add the disk space to the free space list


                      http://raj-os.blogspot.in/        7
Various Implementations of Free Space List

• Bit Vector


• Linked List


• Grouping


• Counting


                 http://raj-os.blogspot.in/    8
Bit Vector

• Free space list is implemented as a bit map or bit
  vector

• If the block is free the bit is set to 1

• If the block is allocated the bit is set to 0




                        http://raj-os.blogspot.in/     9
Bit Vector

• Example:

  – Consider a disk, where blocks
    2,3,4,5,8,9,10,11,12,13,17,18,25,26 & 27 are free
    and the rest of the blocks are allocated
  – The free-space bit map would be

  – 001111001111110001100000011100000……

                    http://raj-os.blogspot.in/      10
Bit Vector (n blocks)

           0 1 2                                 n-1
                                         …
                    0 ⇒ block[i] free
         bit[i] =
                    1 ⇒ block[i] occupied


Block number calculation

  (number of bits per word) *
  (number of 0-value words) +
  offset of first 1 bit
                    http://raj-os.blogspot.in/         11
Bit Vector

• Bit map requires extra space

Example:
   – Disk Size = 1.3 GB

   – Block size = 512 bytes

   – Need a bit map of over 332 KB to track its free
     blocks


                 http://raj-os.blogspot.in/       12
Bit Vector

• Advantage:

  – Relatively Simple and Efficient

  – Easy to get contiguous files




                    http://raj-os.blogspot.in/   13
Linked List

• Approach

  – Link all free disk blocks together

  – Keep a pointer to the first free block

  – This block contains a pointer to next free block,
    and so on

                     http://raj-os.blogspot.in/         14
Linked Free Space List on Disk

Example:

• As shown in figure in the next slide, there is a

• Pointer to block 2, as the first free block

• Block 2 would contain a pointer to block 3,

• Which would point to block 4,

• Which would point 5,8,9,10,11,12,13,17,18,25,26,27
                      http://raj-os.blogspot.in/     15
Fig 1
Linked free space list on disk
         http://raj-os.blogspot.in/   16
Linked List

• Linked list (free list)
   – Cannot get contiguous space easily

   – No waste of space

   – Not efficient for faster access

   – Substantial I/O

                       http://raj-os.blogspot.in/   17
Grouping

• Approach

  – Store addresses of n free blocks in the first free
    block
  – The first n-1 of these are actually free

  – The last block contains the address as of another
    free blocks, and so on as shown in the next slide
    Fig : 2
                   http://raj-os.blogspot.in/            18
Block No     Block No                             Block No
Block No     Block No                             Block No
    .                                                .
                .                           ...      .
    .           .                                    .


Block No     Block No                             Block No


First Free
  block
                    Fig 2

                      Grouping


                    http://raj-os.blogspot.in/               19
Grouping

• Advantage

  – Large number of free blocks can be found quickly




                   http://raj-os.blogspot.in/      20
Counting

• Approach

  – Based on the fact that several contiguous blocks may
    be allocated and freed simultaneously
  – Holds the address of the first free block and number
    “n” of free contiguous blocks that follow the first
    block
  – Each entry is the free space list consist of a disk
    address and a count
                     http://raj-os.blogspot.in/           21
Counting

• Entry in a free space list consists of

   – Disk address

   – Count




                    http://raj-os.blogspot.in/   22
Counting

Constraints:
   • Each entry requires more space than a simple
    disk address
   • The overall list will be shorter, as long as the
    count is greater than one



                   http://raj-os.blogspot.in/           23
Summary

In this class, you have learnt:
• What is free space management

• Various free space management techniques




                    http://raj-os.blogspot.in/   24
Frequently asked questions

1. Explain the need for free space management

2. List the various implementations of free space list

3. Explain bit vector




                     http://raj-os.blogspot.in/          25
Frequently Asked Questions

4. Explain the following free space management techniques
a)   linked list
b)   Grouping
c)   Counting


5. Write the advantages and disadvantages of linked list method
     of free space management



                         http://raj-os.blogspot.in/               26
Quiz
• To keep track of disk space the system maintains

       Free space list

• Bit map requires extra space [T/F]

            True




                      http://raj-os.blogspot.in/     27
Quiz

• In Linked allocation it is easy to get the contiguous space
  [T/F]
           False

• In Counting it is easy to get the contiguous space [T/F]
            True




                         http://raj-os.blogspot.in/             28
Other subject materials

•   Web designing
•   Micro processors
•   C++ tutorials
•   java

home


                 http://raj-os.blogspot.in/   29

Free space managment46

  • 1.
    Free Space Management http://raj-os.blogspot.in/ 1
  • 2.
    HOME PREVIOUS TOPIC NEXT PREVIOUS QUESTION PAPERS FOR OS CPP TUTORIALS http://raj-os.blogspot.in/ 2
  • 3.
    Recap In the lastclass, you have learnt: • Secondary memory, types of secondary memory • Various types of heads, advantages of one over other • Techniques for increasing storage capacity • Characteristics of the disk http://raj-os.blogspot.in/ 3
  • 4.
    Objectives On completion ofthis period, you would be able to know • Need for free space management • Various implementations of free space lists • Bit vector, Linked list, Grouping, Counting http://raj-os.blogspot.in/ 4
  • 5.
    Understand Free SpaceManagement • Need for free space management – Limited amount of disk space – Necessary to reuse the space from deleted files http://raj-os.blogspot.in/ 5
  • 6.
    Need for FreeSpace Management • To keep track of disk space : – The system maintains a free space list – The free space list records all disk blocks that are free http://raj-os.blogspot.in/ 6
  • 7.
    File Creation &Deletion • File creation – Search the free space list of the required amount of space – Allocate the space to the new file – Remove the space from free space list • File deletion – Add the disk space to the free space list http://raj-os.blogspot.in/ 7
  • 8.
    Various Implementations ofFree Space List • Bit Vector • Linked List • Grouping • Counting http://raj-os.blogspot.in/ 8
  • 9.
    Bit Vector • Freespace list is implemented as a bit map or bit vector • If the block is free the bit is set to 1 • If the block is allocated the bit is set to 0 http://raj-os.blogspot.in/ 9
  • 10.
    Bit Vector • Example: – Consider a disk, where blocks 2,3,4,5,8,9,10,11,12,13,17,18,25,26 & 27 are free and the rest of the blocks are allocated – The free-space bit map would be – 001111001111110001100000011100000…… http://raj-os.blogspot.in/ 10
  • 11.
    Bit Vector (nblocks) 0 1 2 n-1 … 0 ⇒ block[i] free bit[i] = 1 ⇒ block[i] occupied Block number calculation (number of bits per word) * (number of 0-value words) + offset of first 1 bit http://raj-os.blogspot.in/ 11
  • 12.
    Bit Vector • Bitmap requires extra space Example: – Disk Size = 1.3 GB – Block size = 512 bytes – Need a bit map of over 332 KB to track its free blocks http://raj-os.blogspot.in/ 12
  • 13.
    Bit Vector • Advantage: – Relatively Simple and Efficient – Easy to get contiguous files http://raj-os.blogspot.in/ 13
  • 14.
    Linked List • Approach – Link all free disk blocks together – Keep a pointer to the first free block – This block contains a pointer to next free block, and so on http://raj-os.blogspot.in/ 14
  • 15.
    Linked Free SpaceList on Disk Example: • As shown in figure in the next slide, there is a • Pointer to block 2, as the first free block • Block 2 would contain a pointer to block 3, • Which would point to block 4, • Which would point 5,8,9,10,11,12,13,17,18,25,26,27 http://raj-os.blogspot.in/ 15
  • 16.
    Fig 1 Linked freespace list on disk http://raj-os.blogspot.in/ 16
  • 17.
    Linked List • Linkedlist (free list) – Cannot get contiguous space easily – No waste of space – Not efficient for faster access – Substantial I/O http://raj-os.blogspot.in/ 17
  • 18.
    Grouping • Approach – Store addresses of n free blocks in the first free block – The first n-1 of these are actually free – The last block contains the address as of another free blocks, and so on as shown in the next slide Fig : 2 http://raj-os.blogspot.in/ 18
  • 19.
    Block No Block No Block No Block No Block No Block No . . . ... . . . . Block No Block No Block No First Free block Fig 2 Grouping http://raj-os.blogspot.in/ 19
  • 20.
    Grouping • Advantage – Large number of free blocks can be found quickly http://raj-os.blogspot.in/ 20
  • 21.
    Counting • Approach – Based on the fact that several contiguous blocks may be allocated and freed simultaneously – Holds the address of the first free block and number “n” of free contiguous blocks that follow the first block – Each entry is the free space list consist of a disk address and a count http://raj-os.blogspot.in/ 21
  • 22.
    Counting • Entry ina free space list consists of – Disk address – Count http://raj-os.blogspot.in/ 22
  • 23.
    Counting Constraints: • Each entry requires more space than a simple disk address • The overall list will be shorter, as long as the count is greater than one http://raj-os.blogspot.in/ 23
  • 24.
    Summary In this class,you have learnt: • What is free space management • Various free space management techniques http://raj-os.blogspot.in/ 24
  • 25.
    Frequently asked questions 1.Explain the need for free space management 2. List the various implementations of free space list 3. Explain bit vector http://raj-os.blogspot.in/ 25
  • 26.
    Frequently Asked Questions 4.Explain the following free space management techniques a) linked list b) Grouping c) Counting 5. Write the advantages and disadvantages of linked list method of free space management http://raj-os.blogspot.in/ 26
  • 27.
    Quiz • To keeptrack of disk space the system maintains Free space list • Bit map requires extra space [T/F] True http://raj-os.blogspot.in/ 27
  • 28.
    Quiz • In Linkedallocation it is easy to get the contiguous space [T/F] False • In Counting it is easy to get the contiguous space [T/F] True http://raj-os.blogspot.in/ 28
  • 29.
    Other subject materials • Web designing • Micro processors • C++ tutorials • java home http://raj-os.blogspot.in/ 29