- OS - Home
- OS - Overview
- OS - History
- OS - Evolution
- OS - Functions
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- Process Management
- Processes in Operating System
- States of a Process
- Process Schedulers
- Process Control Block
- Operations on Processes
- Process Suspension and Process Switching
- Process States and the Machine Cycle
- Inter Process Communication (IPC)
- Context Switching
- Threads
- Types of Threading
- Multi-threading
- System Calls
- Scheduling Algorithms
- Process Scheduling
- Types of Scheduling
- Scheduling Algorithms Overview
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithm
- HRRN Scheduling Algorithm
- Priority Scheduling Algorithm
- Multilevel Queue Scheduling
- Lottery Scheduling Algorithm
- Starvation and Aging
- Turn Around Time & Waiting Time
- Burst Time in SJF Scheduling
- Process Synchronization
- Process Synchronization
- Solutions For Process Synchronization
- Hardware-Based Solution
- Software-Based Solution
- Critical Section Problem
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Mutual Exclusion Using Interrupt Disabling
- Peterson's Algorithm
- Dekker's Algorithm
- Bakery Algorithm
- Semaphores
- Binary Semaphores
- Counting Semaphores
- Mutex
- Turn Variable
- Bounded Buffer Problem
- Reader Writer Locks
- Test and Set Lock
- Monitors
- Sleep and Wake
- Race Condition
- Classical Synchronization Problems
- Dining Philosophers Problem
- Producer Consumer Problem
- Sleeping Barber Problem
- Reader Writer Problem
- OS Deadlock
- Introduction to Deadlock
- Conditions for Deadlock
- Deadlock Handling
- Deadlock Prevention
- Deadlock Avoidance (Banker's Algorithm)
- Deadlock Detection and Recovery
- Deadlock Ignorance
- Resource Allocation Graph
- Livelock
- Memory Management
- Memory Management
- Logical and Physical Address
- Contiguous Memory Allocation
- Non-Contiguous Memory Allocation
- First Fit Algorithm
- Next Fit Algorithm
- Best Fit Algorithm
- Worst Fit Algorithm
- Buffering
- Fragmentation
- Compaction
- Virtual Memory
- Segmentation
- Buddy System
- Slab Allocation
- Overlays
- Free Space Management
- Locality of Reference
- Paging and Page Replacement
- Paging
- Demand Paging
- Page Table
- Page Replacement Algorithms
- Optimal Page Replacement Algorithm
- Belady's Anomaly
- Thrashing
- Storage and File Management
- File Systems
- File Attributes
- Structures of Directory
- Linked Index Allocation
- Indexed Allocation
- Disk Scheduling Algorithms
- FCFS Disk Scheduling
- SSTF Disk Scheduling
- SCAN Disk Scheduling
- LOOK Disk Scheduling
- I/O Systems
- I/O Hardware
- I/O Software
- I/O Programmed
- I/O Interrupt-Initiated
- Direct Memory Access
- OS Types
- OS - Types
- OS - Batch Processing
- OS - Multiprocessing
- OS - Hybrid
- OS - Monolithic
- OS - Zephyr
- OS - Nix
- OS - Linux
- OS - Blackberry
- OS - Garuda
- OS - Tails
- OS - Clustered
- OS - Haiku
- OS - AIX
- OS - Solus
- OS - Tizen
- OS - Bharat
- OS - Fire
- OS - Bliss
- OS - VxWorks
- OS - Embedded
- OS - Single User
- Miscellaneous Topics
- OS - Security
- OS Questions Answers
- OS - Questions Answers
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Free Space Management in Operating System
Computer systems have limited space (hard disk), so it is important that we utilize the disk space in a prudent manner.
When a file is created, the operating system works to allocate free space to the files. It also creates a free void space when a file is deleted from the system. For doing all these tasks and managing spaces in our system, the operating system works with the help of a free space management system and allocates and deallocates memory spaces simultaneously.
There is a system software in an operating that manipulates and keeps a track of free spaces to allocate and deallocate memory blocks to file, this system is called a file managemnet system in an operating system. There is a free space list in an operating system that maintains the record of free blocks.
When a file is created, the operating system searches the free space list for the required space allocated to save a file. While deletion a file, the file system frees the given space and adds this to the free space list.
Read this chapter to learn more about how the operating system manages the free space in the memory (hard disk).
Methods of Free Space Management
Operating system provides different four methods to manage the free space list and these are as −
- Bitmap/Bit Vector Method
- Linked List Method
- Grouping Method
- Counting Method
Let's discuss each of these methods one by one.
Bitmap/Bit Vector Method
Bitmap or bit vector is a most frequently used method to implement the free space list. It is a series or collection of bit array in which each bits represents a disk block. The values taken by the bits are either 1 or 0. If the block bit is 1, it means the block is empty and if the block bit is 0, it means the block is not free.
Let's understand through a example −
Above given diagram is a representation of a disk in which there are 16 blocks. There are also some free and ocupied blocks present. The upper part is showing block number and free blocks are represented by bits 0 and 1. Free blocks are represented by 1 and occupied blocks are represented by 0. It means the blocks represent by 0, stores some data and the blocks represent by 1, those are free.
Features of Bitmap Method
Let's discuss some important features of bitmap and they are as −
- The unit size in bitmaps is very important and should be chosen with care.
- If the unit size is smaller, the bitmap will be larger as it will hold the value 0 or 1 for each of the units. Similarly, if the unit size is larger, bitmap will be smaller.
- The unit size need not be too large, as even with a unit size as small as 3 bytes, only one bit of the bitmap can represent 24 bits.
Advantages of Bitmap Method
Following are the advantages of bitmap and they are as−
- Bitmap is simple and easy to understand because it is easy way to keep track of the memory.
- Bitmap consumes less memory.
- It is efficient to search free space in the memory.
Disadvantages of Bitmap Method
Following are the disadvantages of bitmap and they are as−
- In this method the size of array is fixed once it is declared.
- Using this method operating system goes through all the blocks until it finds a free block.
- This method is not efficient if the size of disk is too large.
- A major problem in the bitmap occurs if a ânâ size memory block needs to be occupied by a process. Then a ânâ size vacancy is needed in the bitmap where the values are all zeroes.
- Insertion and deletion operations are slow, as elements are stores sequentially or index wise.
Linked List Method
After the bitmap method, another common approach used by operating systems to manage free space is the linked list method. Instead of tracking free space using bits, this method connects all free blocks together using pointers.
Linked list is a another approach for free space management in an operating system. In this, all free blocks inside a disk are linked together in a linked list structure. Each free block contains two parts:
Size/data field − It stores the size of the free memory block.
Link/Pointer Field − It stores the address of the next free block.
These free blocks on the disk are linked together by a pointer. These pointers contains the address of the next free block and the last pointer of the list points to null which indicates the end of linked list. This method is not enough to traverse the list because we have to read each disk block one by one which requires more I/O time.
Let's understand through a example −
As we know, each free block contains two parts one part stores the size of the block, and the other part stores the address of the next free block. In the given diagram, the colored blocks are empty (free), and the non-colored blocks are occupied. The free space list head first points to Block 2, which then points to Block 3, the next available free block, and this continues for all free blocks. The last free block (Block 27)contains a NULL pointer, indicating the end of free list.
Advantages of Linked list Method
Following are the advantages of linked list method and they are as−
- In linked list method, available spce is used efficiently.
- In linked list method, there is no size limit so, a new free space can be added easily.
Disadvantages of Linked list Method
Following are the disadvantages of linked list method and they are as−
- In linked list method, we also need to handle the overhead of maintaining pointers, since each free block must store the address of the next block.
- This method is not efficient when we need to traverse every block of memory, because each block must be visited one by one through pointers.
Grouping Method
The grouping method is also known as modification of a linked list because in linked list it is difficult to find all free blocks quickly. In grouping method, the free block of memory contains the addresses of the n free blocks and the last free blocks of these n free blocks contains the addres of the next n free block of memory and this keeps going on. This method separates the empty and occupied blocks of space of memory.
Let's understand through a example −
Suppose we have a disk with some free blcoks and some occupied blocks. The free block numbers are 3,4,5,6,9,10,11,12,13 and 14 and occupied blocks numbers are 1,2,7,8,15 and 16 and so on. They are allocated to some files.
When the grouping method is applied, block 3 will store the addresses of blocks 4,5 and 6 because block 3 is the first free block. In the same way, block 6 will store the addresses of blocks 9, which is '0' and '1' because block 6 is the first occupied block and so on.
Advantages of Grouping Method
Following are the advantages of grouping method and they are as −
- Using grouping method, we can easily find addresses of a large number of free blocks easily and quickly.
- In this method, there is no need to traverse the whole list.
Disadvantages of Grouping Method
Following are the disadvantages of grouping method and they are as −
- We need to change the entire list if one block gets occupied because the addresses of the free blocks in the group must be updated to show the new allocation.
- Some space in a block is wasted because the last block of each group is used to store the addresses of the next n free blocks instead of storing data.
- There is an overhead in maintaining the index of blocks.
Counting Method
In memory space, several files are created and deleted at the same time. For which memory blocks are allocated and de-allocated for the files. Creating of files occupy free blocks and deletion of diles frees blocks. When there is an entry in the free space, it consists of two parameters- address of first free disk block(a pointer) and a number n which specifies how many consecutive free blocks are available.
Let's understand through a example −
Suppose a disk has 16 blocks in which some blocks are empty and some blocks are occupied as given below −
Where block numbers 3, 4, 5, 6, 9, 10, 11, 12, 13, and 14 are free, and the rest of the blocks, i.e., block numbers 1, 2, 7, 8, 15 and 16 are allocated to some files.
When use counting method, it groups those blocks which are consecutive. In this example, the block number 3, 4, 5, 6 will grouped together and create one contiguous space. Block 3 will point to Block 4 and store the count 4 (since Block 3, 4, 5, and 6 are contiguous). Similarly, Block 9 will point to Block 10 and keep the count of 6 (since Block 9, 10, 11, 12, 13, and 14 are contiguous).
Advantages of Counting Method
Following are the advantages of counting method and they are as−
- Using counting method, a bunch of free blocks takes place fastly.
- It is a fast allocation of a large number of consecutive free blocks.
- The overall list is smaller in size.
Disadvantages of Counting Method
Following are the disadvantages of counting method and they are as−
- Using counting method, the first free blocks stores the rest free blocks, so it require more space.
- For efficient insertion, deletion, and traversal operations. We need to store the entries in B-tree data structure.
- Everything is grouped together, so the total area you can work becomes smaller, which sometimes makes accessing individual data less flexible.
Conclusion
Free space management plays an important role in an operating system because it keeps track of which parts of the disk are free and which are already used. Without proper free space management, the system would not know where to store new files or how to reuse deleted space efficiently. Different methods like the bit vector method, linked list method, grouping, and counting help the Operating system to manage the storage in different way.