0% found this document useful (0 votes)
26 views20 pages

Operating System Lecture Four: DR Jamal Altuwaijari

Uploaded by

Yusef Abusalem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views20 pages

Operating System Lecture Four: DR Jamal Altuwaijari

Uploaded by

Yusef Abusalem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Operating system

Lecture four
Dr jamal altuwaijari
4. Free-space list and allocation methods
Disks provide the bulk of secondary storage on which a file system is
maintained. To improve I/O efficiency, I/O transfers between memory
and disk are performed in units of blocks. Each block is one of more
sectors. Depending on disk drive, sectors vary from 32 bytes to 4096
bytes. Disks have two important characteristics that make them a
:convenient medium for storing multiple files

A- They can be rewritten in place, it is possible to read a block from the


.disk, to modify the block and to write it back into the same place
.B- We can access directly any given block of information on the disk
4.1 Free-space list (FSL)
Since there is only a limited amount of disk space it is necessary to -
.reuse the space from deleted files for new files if possible
To keep track of free disk space, the system maintains a free—space -
.list (FSL)
FSL records all disk blocks that are free. To create a file we search the -
FSL for the required amount of space, and allocate that space to new
file. This space is then removed from the FSL. When the file deleted its
.disk space is added to the FSL

: There arc many methods used to organized the FSL, some of these are
4-1-1 Bit vector
The FSL is implemented as a Bit—mac or Bit—vector. Each block if represented by I bit. If the block is
free the bit is set to 1 if the block is allocated the bit is set to 0.

. Example
Consider a disk where blocks 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 17, 18, 25, 26, and 27 are free and the rest
.of the blocks arc allocated. The FSL bit map (vector) would be
.... I 1 0 0 1 1 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0 0 1 1 0 0

Advantages
It is simple and efficient to find the first free block, or n consecutive free blocks on disk. Many
computers supply bit—manipulation instruction that can be used effectively, for that purpose the
calculation of the block number is
x (number of 0 — value words) + offset of first I bit )number of bits per word(

Disadvantages
The Bit—vectors are inefficient unless the entire vector is kept in main memory (and is written to disk
.occasionally for recovery needs )
4.1.2 Linked List
Another approach is to link together all the free disk blocks, keeping a
pointer to the first free block in a special location on the disk and
caching it in memory. This first block contains a pointer to the next free
disk block and so on, see figure 4.1.
4.1.2 Linked List
4.1.2 Linked List
Advantages
We can flow the link (pointer) to allocate blocks to the file.

Disadvantages
It is not efficient To traverse the list we require to read each block so it
needs more I/O time.
4.1.3 Grouping
A modification of the free—list is to store the addresses of n free blocks
in the first free block.

The first n-I of these blocks are actually free. The last block contains the
addresses of another n free blocks and so on.

Advantages
The addresses of a large number of free blocks can be found quickly.
4.1.4 Counting
Another approach is to take advantage of the fact generally several
contiguous blocks may be allocated or freed simultaneously.

Thus rather than keeping a list of n free disk addresses, we can keep the
address of the first free block and the number n of free contiguous
blocks that follow the first block.

Each entry in the FSL then consists of a disk address and a count,
therefore the overall list will be shorter as long as the count is generally
greater than I see the following example of counting list to the free
blocks in the example in page (2).
4.1.4 Counting

Advantage
It is shorter than linked list and useful for contiguous allocationmethods
4-2 Allocation methods
The direct—access nature of disks allows us flexibility in the
implementation of files, many files will be stored on the same disk.
- The main problem is how to allocate space to these files, so that disk
space is utilized effective! and files can be accessed quickly.

- there are three major methods of allocating disk space are in wide
use:
Contiguous, linked, and indexed allocation methods. Each has its
advantages and disadvantages.
4.2.1 Contiguous allocation
- This method requires each file to occupy a set of contiguous block.
- Disk address defines a linear ordering on the disk.

- The disk address and length (in blocks) define contiguous allocation of
a file. If the file is (n) blocks long and start at location (b) then it occupy
blocks. b, b+1, b+2, , b + n - 1.

- The directory entry for each file indicates the address of the starting
block and the length of the area allocated for the file.
4.2.1 Contiguous allocation

Advantages
Accessing a file is easy where sequential and direct access can be sported.

Disadvantages
4.2.2 Linked allocation
- Linked allocation solves all problems of contiguous allocation.
- Each file is a linked list of disk blocks; the disk blocks may be scatterd
any where on the disk.
- The directory contains a pointers to the first and last blocks of the file.
- The start pointer is initialized to nil to signify an empty file.
4.2.2 Linked allocation
Advantages
- Creating file is easy by creating a new entry in the directory, where there is no
need to declare the file size when its created.

- A file can continue to grow as long as there are free blocks.


- There is no need to compact disk space.
There is no external fragmentation with linked list.

Disadvantages
- It can be used effectively for only sequential—access file. To find the block we
must start at the beginning of that file and follow the pointers until we get to
the ith block.
- Pointers require additional space.
4.2.2 Linked allocation
An important application on the linked allocation method is the use of a file
allocation table (FAT).

This simple but efficient method of disk space allocation is used by the MS—
DOS and OS/2 operating system.

A section of disk at the beginning of each partition is set a side to contain a


table. The directory entry contains the block number of the block of the file.

The table entry indexed by that block number then contain the block number
of the next block in the file.

This chain continues until the last block which has a special—end—of—file,
4.2.2 Linked allocation

Advantage
Simple and efficient.

Disadvantage
It needs significant number of disk head seeks unless the FAT is cached.
4.2.3 Indexed Allocation
- Indexed allocation solved the problem lost pointvi in linked allocation
by
bringing all the pointers together into one location, the indexed block.

-Each file has its own index block which is one array of disk block
addresses, the in' entry in the index block point to ill' block of the file.

- The directory contains the address of the index block, when the file is
created all pointers in the index block are set to nil.
-For large tile several inaex me may oe LISCC.
- Figure 4.5 show the indexed allocation structure.
4.2.3 Indexed Allocation
4.2.3 Indexed Allocation
Advantage
-It supports direct access without suffering from E—Fragementation.
- Any free block where on the disk may satisfy a request for more space

Disadvantage
- It does suffer from wasted space.
- The pointer overhead of index block is generally greater than the
pointer overhead of linked allocation.

You might also like