Contiguous Allocation Method

Contiguous Allocation Method 

FILE LOCKING:

The file locking mechanism provides functionality similar to reader-write locks. A reader-write lock requires specifying the mode of the lock-in their read and write access. When a process wishes to only read shared data, it requests the reader-writer lock in reading mode. Similarly, when a process wishes to modify the shared data. it must request the lock in write mode.

File locking enables processes to implement exclusive access to a file. There are three major options for the implementation of the file. 

A file can be locked as a whole or only a part of the file can be locked.

A file may be locked for reading writing, modifying appending, etc. Most of the system provides both read and write locks. If a file is locked by a process for reading, then other processes can only read data from the file but the process cannot write new data into it (i,e write access by other process is defined) Similarly, if a file is locked by a process for writing, then other processes cannot read nor write the file (it means that both read and write accesses by other processes are defined.

File-locking

Locking may be either mandatory or advisory. If the locking is mandatory, then the operating system does not allow any other process to access the locked file. Similarly, if the locking is advisory, it is up to software developed to ensure that locks are appropriately acquired and released. Windows operating system adopts mandatory locking, and UNIX adopts advisory locking.

FILE BLOCKING:

The blocks are the unit of I/O on the secondary storage on which the I/O operating are performed. For I/O operating to be performed on a file, records must be organized as blocks. Typically, the size of a block is a multiple of a disk sector size. The largest the size of the block, the more records are passed in one I/O operating. In the case, if a file is being processed or searched sequentially, then the number of I/O operating is reduced and thus speed up the record processing. It is the main advantage of using the largest block. 
The blocking method determines how the records of a file are allocated into blocks. 
There are three methods of blocking that can be used and are discussed below:

Fixed blocking :

In fixed blocking, blocks are of fixed length. (i.e each block has a fixed-length e,g 512 bytes, 1K, 2KB, etc.) Each block stores an integral number of records for the file with fixed-size records.

Variable-Lenght Spanned Blocking:


In a variable-length spanned blocking scheme, variable-length records are used and are packed into blocks with no unused space. Thus, some records may be stored (or spanned) in multiple blocks.
With the continuation indicate by a pointer to a successor block.

variable-length Un-Spanned Blocking : 

In a variable-length un-spanned blocking scheme, multiple variable-length records can be stored in each block but no record may span over multiple blocks. No record may be larger than the size of the block.

ALLOCATING SPACE TO FILES ON SECONDARY STORAGE:

A file is stored on the secondary storage as a collection of blocks. The file management system (a part of the operating system) is responsible for allocating blocks to files. The main issue is how to allocate space to files on secondary storage (disk) so that disk space can be efficiently and files can be accessed quickly.

Fixed-blocking

Allocated Method:

The most popular and commonly used allocated methods are as follows:
  1. Contiguous allocated
  2. Linked allocated 
  3. Indexed allocated

Contiguous Allocated:

Contiguous allocation is the simplest allocation method. With contiguous allocated, each file occupies a set of contiguous blocks on the disk. Thus on a disk with a fixed-size block of 2KB, a file of size 30KB would be allocated 15 consecutive blocks.
 If the file length 'n' blocks long and starts at location x, then it occupies blocks x,x+ 1,x+2.....,x+ n-1. Thus, the file Allocated Table (FAT)needs just a single entry for each file, showing the starting block and length of the file.

Advantages:

The main advantages of contiguous allocation are as follows:   

 Contiguous allocation is best for sequential access files.

  1. It is very simple to implement.
  2. I/O  performance is excellent because multiple blocks (or entire file) can be retrieved from the disk in a single operating. 
  3. Both sequential and direct access method can easily be implemented using contiguous allocation.
  4. If any block of a file containing data is damaged, then other data stored in other blocks can be retrieved.

Disadvantages:

Contiguous allocated also has some problems. The main disadvantages are :
  1. Without this advance information, the operating system does not know how much disk space is to reserve.
  2. As files are created and deleted, external fragmentation may occur. So it becomes difficult to find contiguous blocks of space of sufficient length. From time to time, it will be necessary to call a compaction algorithm to make free space on the disk.

Linked List Allocated:

Linked list allocation is opposite to contiguous allocation. In linked list allocation, the physical blocks on disk in which a file is stored may be scattered anywhere on the disk, each block contains a pointer to the next one. In this way, all blocks that store the data of files are linked together. The File Allocation Table (FAT) needs just a single entry for each file, showing the pointer to the starting block and the length of the file in blocks. Some systems store only the pointer to the starting block for each entry. 
Reading data from a sequential file is straightforward and easy, but random access is extremely slow.

Advantages:

The following are some advantages of linked list allocation.
  1. There is no external fragmentation and any free blocks can be used for storing data of other files.
  2. It is very easy and suitable for sequential access files.
  3. There is no need to compact disk space.

Indexed Allocation:

In an indexed file, allocation of the linked list allocated method is used to store data of file but an index of all the blocks is created in a separate block, which also is a part of the file. This block contains the addresses of all blocks of files. This block is also known as an index block.

Advantages:

  1. It solves all the problems faced in linked list allocation.
  2. Direct access can be implemented very easily.
  3. Indexed allocation supports both sequential and direct access.

Disadvantages:

  1. If the index block of life is damaged, then data of the file cannot be accessed.
  2. A separate index for each file is created, so extra space on the disk is used for index blocks.


Comments

Popular posts from this blog

Modern scenario of information technology:

Deadlock Questions and Answers pdf

What is the bus interconnection?