CS Oss 3
CS Oss 3
UNIT 3
3.1 Main memory
The term memory can be defined as a collection of data in a specific format. It is used to
store instructions and process data. The memory comprises a large array or group of
words or bytes, each with its own location. The primary purpose of a computer system is
to execute programs. These programs, along with the information they access, should be
in the main memory during execution. The CPU fetches instructions from memory
according to the value of the program counter.
To achieve a degree of multiprogramming and proper utilization of memory, memory
management is important. Many memory management methods exist, reflecting various
approaches, and the effectiveness of each algorithm depends on the situation.
Before we start Memory management, let us know what is main memory is.
What is Main Memory?
The main memory is central to the operation of a Modern Computer. Main Memory is a
large array of words or bytes, ranging in size from hundreds of thousands to billions. Main
memory is a repository of rapidly available information shared by the CPU and I/O
devices. Main memory is the place where programs and information are kept when the
processor is effectively utilizing them. Main memory is associated with the processor, so
moving instructions and information into and out of the processor is extremely fast. Main
memory is also known as RAM (Random Access Memory). This memory is volatile. RAM
loses its data when a power interruption occurs.
Main Memory
p1
p2
p3
p4
Partition Table
Once partitions are defined operating system keeps track of the status of memory
partitions it is done through a data structure called a partition table.
Sample Partition Table
Starting Address of Partition Size of Partition Status
0k 200k allocated
Memory Allocation
To gain proper memory utilization, memory allocation must be allocated efficient manner.
One of the simplest methods for allocating memory is to divide memory into several fixed-
sized partitions and each partition contains exactly one process. Thus, the degree of
multiprogramming is obtained by the number of partitions.
Multiple partition allocation: In this method, a process is selected from the input
queue and loaded into the free partition. When the process terminates, the partition
becomes available for other processes.
Fixed partition allocation: In this method, the operating system maintains a table that
indicates which parts of memory are available and which are occupied by processes.
Initially, all memory is available for user processes and is considered one large block of
available memory. This available memory is known as a “Hole”. When the process
arrives and needs memory, we search for a hole that is large enough to store this
process. If the requirement is fulfilled then we allocate memory to process, otherwise
keeping the rest available to satisfy future requests. While allocating a memory
sometimes dynamic storage allocation problems occur, which concerns how to satisfy
a request of size n from a list of free holes. There are some solutions to this problem:
First Fit
In the First Fit, the first available free hole fulfil the requirement of the process allocated.
First Fit
Here, in this diagram, a 40 KB memory block is the first available free hole that can store
process A (size of 25 KB), because the first two blocks did not have sufficient memory
space.
Best Fit
In the Best Fit, allocate the smallest hole that is big enough to process requirements. For
this, we search the entire list, unless the list is ordered by size.
Best Fit
Here in this example, first, we traverse the complete list and find the last hole 25KB is the
best suitable hole for Process A(size 25KB). In this method, memory utilization is
maximum as compared to other memory allocation techniques.
Worst Fit
In the Worst Fit, allocate the largest available hole to process. This method produces the
largest leftover hole.
Worst Fit
Here in this example, Process A (Size 25 KB) is allocated to the largest available memory
block which is 60KB. Inefficient memory utilization is a major issue in the worst fit.
Fragmentation
Fragmentation is defined as when the process is loaded and removed after execution
from memory, it creates a small free hole. These holes can not be assigned to new
processes because holes are not combined or do not fulfill the memory requirement of the
process. To achieve a degree of multiprogramming, we must reduce the waste of
memory or fragmentation problems. In the operating systems two types of fragmentation:
1. Internal fragmentation: Internal fragmentation occurs when memory blocks are
allocated to the process more than their requested size. Due to this some unused
space is left over and creating an internal fragmentation problem.Example: Suppose
there is a fixed partitioning used for memory allocation and the different sizes of blocks
3MB, 6MB, and 7MB space in memory. Now a new process p4 of size 2MB comes and
demands a block of memory. It gets a memory block of 3MB but 1MB block of memory
is a waste, and it can not be allocated to other processes too. This is called internal
fragmentation.
2. External fragmentation: In External Fragmentation, we have a free memory block, but
we can not assign it to a process because blocks are not
contiguous. Example: Suppose (consider the above example) three processes p1, p2,
and p3 come with sizes 2MB, 4MB, and 7MB respectively. Now they get memory
blocks of size 3MB, 6MB, and 7MB allocated respectively. After allocating the process
p1 process and the p2 process left 1MB and 2MB. Suppose a new process p4 comes
and demands a 3MB block of memory, which is available, but we can not assign it
because free memory space is not contiguous. This is called external fragmentation.
Both the first-fit and best-fit systems for memory allocation are affected by external
fragmentation. To overcome the external fragmentation problem Compaction is used. In
the compaction technique, all free memory space combines and makes one large block.
So, this space can be used by other processes effectively.
Another possible solution to the external fragmentation is to allow the logical address
space of the processes to be noncontiguous, thus permitting a process to be allocated
physical memory wherever the latter is available.
Paging
Paging is a memory management scheme that eliminates the need for a contiguous
allocation of physical memory. This scheme permits the physical address space of a
process to be non-contiguous.
Logical Address or Virtual Address (represented in bits): An address generated by
the CPU.
Logical Address Space or Virtual Address Space (represented in words or
bytes): The set of all logical addresses generated by a program.
Physical Address (represented in bits): An address actually available on a memory
unit.
Physical Address Space (represented in words or bytes): The set of all physical
addresses corresponding to the logical addresses.
Example:
If Logical Address = 31 bits, then Logical Address Space = 2 31 words = 2 G words (1 G
= 230)
If Logical Address Space = 128 M words = 2 7 * 2 20 words, then Logical Address =
log 2 227 = 27 bits
If Physical Address = 22 bits, then Physical Address Space = 2 22 words = 4 M words (1
M = 220)
If Physical Address Space = 16 M words = 2 4 * 2 20 words, then Physical Address =
log 2 224 = 24 bits
The mapping from virtual to physical address is done by the memory management unit
(MMU) which is a hardware device and this mapping is known as the paging technique.
The Physical Address Space is conceptually divided into several fixed-size blocks,
called frames.
The Logical Address Space is also split into fixed-size blocks, called pages.
Page Size = Frame Size
Let us consider an example:
Physical Address = 12 bits, then Physical Address Space = 4 K words
Logical Address = 13 bits, then Logical Address Space = 8 K words
Page size = frame size = 1 K words (assumption)
Paging
In this scheme, User can load the bigger size processes than the available main memory by having the
illusion that the memory is available to load the process.
Instead of loading one big process in the main memory, the Operating System loads the different parts of
more than one process in the main memory.
By doing this, the degree of multiprogramming will be increased and therefore, the CPU utilization will
also be increased.
Since all this procedure happens automatically, therefore it makes the computer feel like it is having the
unlimited RAM.
The page tables of both the pages are 1 KB size each and therefore they can be fit in one frame each. The
page tables of both the processes contain various information that is also shown in the image.
The CPU contains a register which contains the base address of page table that is 5 in the case of P1 and 7
in the case of P2. This page table base address will be added to the page number of the Logical address
when it comes to accessing the actual corresponding entry.
Advantages of Virtual Memory
Demand Paging
Demand Paging is a popular method of virtual memory management. In demand paging, the pages of a
process which are least used, get stored in the secondary memory.
A page is copied to the main memory when its demand is made or page fault occurs. There are various
page replacement algorithms which are used to determine the pages which will be replaced. We will
discuss each one of them later in detail.
According to the concept of Virtual Memory, in order to execute some process, only a part of the process
needs to be present in the main memory which means that only a few pages will only be present in the
main memory at any time.
However, deciding, which pages need to be kept in the main memory and which need to be kept in the
secondary memory, is going to be difficult because we cannot say in advance that a process will require a
particular page at particular time.
Therefore, to overcome this problem, there is a concept called Demand Paging is introduced. It suggests
keeping all pages of the frames in the secondary memory until they are required. In other words, it says
that do not load any page in the main memory until it is required.
Whenever any page is referred for the first time in the main memory, then that page will be found in the
secondary memory.
After that, it may or may not be present in the main memory depending upon the page replacement
algorithm which will be covered later in this tutorial.
If the referred page is not present in the main memory then there will be a miss and the concept is called
Page miss or page fault.
The CPU has to access the missed page from the secondary memory. If the number of page fault is very
high then the effective access time of the system will become very high.
This is the first basic algorithm of Page Replacement Algorithms. This algorithm is basically dependent on
the number of frames used. Then each frame takes up the certain page and tries to access it. When the
frames are filled then the actual problem starts. The fixed number of frames is filled up with the help of
first frames present. This concept is fulfilled with the help of Demand Paging
After filling up of the frames, the next page in the waiting queue tries to enter the frame. If the frame is
present then, no problem is occurred. Because of the page which is to be searched is already present in
the allocated frames.
If the page to be searched is found among the frames then, this process is known as Page Hit.
If the page to be searched is not found among the frames then, this process is known as Page Fault.
When Page Fault occurs this problem arises, then the First In First Out Page Replacement Algorithm
comes into picture.
The First In First Out (FIFO) Page Replacement Algorithm removes the Page in the frame which is allotted
long back. This means the useless page which is in the frame for a longer time is removed and the new
page which is in the ready queue and is ready to occupy the frame is allowed by the First In First Out Page
Replacement.
Let us understand this First In First Out Page Replacement Algorithm working with the help of an example.
Example:
Points to Remember
Reference String:
The Ratio of Page Hit to the Page Fault = 8 : 12 - - - > 2 : 3 - - - > 0.66
The Page Hit Percentage = 8 *100 / 20 = 40%
The Page Fault Percentage = 100 - Page Hit Percentage = 100 - 40 = 60%
Explanation
First, fill the frames with the initial pages. Then, after the frames are filled we need to create a space in the
frames for the new page to occupy. So, with the help of First in First Out Page Replacement Algorithm we
remove the frame which contains the page is older among the pages. By removing the older page we give
access for the new frame to occupy the empty space created by the First in First out Page Replacement
Algorithm.
After filling up of the frames, the next page in the waiting queue tries to enter the frame. If the frame is
present then, no problem is occurred. Because of the page which is to be searched is already present in
the allocated frames.
If the page to be searched is found among the frames then, this process is known as Page Hit.
If the page to be searched is not found among the frames then, this process is known as Page Fault.
When Page Fault occurs this problem arises, then the OPTIMAL Page Replacement Algorithm comes into
picture.
The OPTIMAL Page Replacement Algorithms works on a certain principle. The principle is:
Replace the Page which is not used in the Longest Dimension of time in future
This principle means that after all the frames are filled then, see the future pages which are to occupy the
frames. Go on checking for the pages which are already available in the frames. Choose the page which is
at last.
Example:
0, 3, 4, 6, 0, 2, 1, 2, 1, 2, 0, 3, 2, 1, 2, 0
Now we need to enter 0 into the frame by removing one page from the page
So, let us check which page number occurs last
From the sub sequence 0, 3, 4, 6, 0, 2, 1 we can say that 1 is the last occurring page number. So we can
say that 0 can be placed in the frame body by removing 1 from the frame.
Let us understand this OPTIMAL Page Replacement Algorithm working with the help of an example.
Example:
Points to Remember
Reference String:
The Ratio of Page Hit to the Page Fault = 8 : 12 - - - > 2 : 3 - - - > 0.66
The Page Fault Percentage = 100 - Page Hit Percentage = 100 - 40 = 60%
Explanation
First, fill the frames with the initial pages. Then, after the frames are filled we need to create a space in the
frames for the new page to occupy.
Here, we would fill the empty spaces with the pages we and the empty frames we have. The problem
occurs when there is no space for occupying of pages. We have already known that we would replace the
Page which is not used in the Longest Dimension of time in future.
There comes a question what if there is absence of page which is in the frame.
0, 2, 4, 6, 0, 2, 1, 2, 1, 2, 0, 3, 2, 1, 2, 0
Here, we can see that page number 5 is not present in the Reference String. But the number 5 is present
in the Frame. So, as the page number 5 is absent we remove it when required and other page can occupy
that position.
This is the last basic algorithm of Page Replacement Algorithms. This algorithm is basically dependent on
the number of frames used. Then each frame takes up the certain page and tries to access it. When the
frames are filled then the actual problem starts. The fixed number of frames is filled up with the help of
first frames present. This concept is fulfilled with the help of Demand Paging
After filling up of the frames, the next page in the waiting queue tries to enter the frame. If the frame is
present then, no problem is occurred. Because of the page which is to be searched is already present in
the allocated frames.
If the page to be searched is found among the frames then, this process is known as Page Hit.
If the page to be searched is not found among the frames then, this process is known as Page Fault.
When Page Fault occurs this problem arises, then the Least Recently Used (LRU) Page Replacement
Algorithm comes into picture.
The Least Recently Used (LRU) Page Replacement Algorithms works on a certain principle. The principle is:
Replace the page with the page which is less dimension of time recently used page in the past.
Example:
6, 1, 1, 2, 0, 3, 4, 6, 0
The pages with page numbers 6, 1, 2 are in the frames occupying the frames.
Let us understand this Least Recently Used (LRU) Page Replacement Algorithm working with the help of
an example.
Example:
Points to Remember
Reference String:
The Page Fault Percentage = 100 - Page Hit Percentage = 100 - 35 = 65%
Explanation
First, fill the frames with the initial pages. Then, after the frames are filled we need to create a space in the
frames for the new page to occupy.
Here, we would fill the empty spaces with the pages we and the empty frames we have. The problem
occurs when there is no space for occupying of pages. We have already known that we would replace the
Page which is not used in the Longest Dimension of time in past or can be said as the Page which is very
far away in the past.
A Physical Address is required by the Central Processing Unit (CPU) for the frame creation and the
physical Addressing provides the actual address to the frame created. For each page a frame must be
created.
o The Frames that can be allocated cannot be greater than total number of frames.
o Each process should be given a set minimum amount of frames.
o When fewer frames are allocated then the page fault ration increases and the process execution
becomes less efficient
o There ought to be sufficient frames to accommodate all the many pages that a single instruction
may refer to
AD
There are three types of Frame Allocation Algorithms in Operating Systems. They are:
Here, in this Frame Allocation Algorithm we take number of frames and number of processes at once. We
divide the number of frames by number of processes. We get the number of frames we must provide for
each process.
This means if we have 36 frames and 6 processes. For each process 6 frames are allocated.
It is not very logical to assign equal frames to all processes in systems with processes of different sizes. A
lot of allocated but unused frames will eventually be wasted if a lot of frames are given to a little
operation.
2) Proportionate Frame Allocation Algorithms
Here, in this Frame Allocation Algorithms we take number of frames based on the process size. For big
process more number of frames is allocated. For small processes less number of frames is allocated by the
operating system.
The problem in the Proportionate Frame Allocation Algorithm is number of frames are wasted in some
rare cases.
The advantage in Proportionate Frame Allocation Algorithm is that instead of equally, each operation
divides the available frames according to its demands.
According to the quantity of frame allocations and the processes, priority frame allocation distributes
frames. Let's say a process has a high priority and needs more frames; in such case, additional frames will
be given to the process. Processes with lower priorities are then later executed in future and first only high
priority processes are executed first.
What is Thrashing?
If the number of page faults is equal to the number of referred pages or the number of page faults are so
high so that the CPU remains busy in just reading the pages from the secondary memory then the
effective access time will be the time taken by the CPU to read one word from the secondary memory and
it will be so high. The concept is called thrashing.
If the page fault rate is PF %, the time taken in getting a page from the secondary memory and again
restarting is S (service time) and the memory access time is ma then the effective access time can be given
as;
Allocating kernel memory is a critical task in operating system design, as the kernel needs
to manage memory efficiently and effectively to ensure optimal system performance. Two
common methods for allocating kernel memory are the buddy system and the slab
system.
The buddy system is a memory allocation algorithm that works by dividing memory into
blocks of a fixed size, with each block being a power of two in size. When a request for
memory is made, the algorithm finds the smallest available block of memory that is large
enough to satisfy the request. If the block is larger than the requested size, it is split into
two smaller blocks of equal size (the “buddies”), with each buddy being marked as either
allocated or free. The algorithm then continues recursively until it finds the exact size of
the requested memory or a block that is the smallest possible size.
The slab system is a memory allocation algorithm that is designed specifically for kernel
memory. It works by dividing memory into fixed-size caches or slabs, each of which
contains a set of objects of the same type. When a request for memory is made, the
algorithm first checks if there is an available object in the appropriate slab cache. If there
is, the object is returned. If not, the algorithm allocates a new slab and adds it to the
appropriate cache.
The advantages of the buddy system are that it is easy to implement and can handle a
wide range of memory sizes. The disadvantages are that it can lead to memory
fragmentation and that it can be inefficient for allocating small amounts of memory.
The advantages of the slab system are that it is efficient for allocating small amounts of
memory and that it can prevent memory fragmentation. The disadvantages are that it can
be more complex to implement than the buddy system and that it may require more
memory overhead.
Overall, both the buddy system and the slab system are effective methods for allocating
kernel memory, and the choice between the two depends on the specific needs and
requirements of the operating system being developed.
Two strategies for managing free memory that is assigned to kernel processes:
1. Buddy system –
Buddy allocation system is an algorithm in which a larger memory block is divided into
small parts to satisfy the request. This algorithm is used to give best fit. The two smaller
parts of block are of equal size and called as buddies. In the same manner one of the two
buddies will further divide into smaller parts until the request is fulfilled. Benefit of this
technique is that the two buddies can combine to form the block of larger size according
to the memory request.
Example – If the request of 25Kb is made then block of size 32Kb is allocated.
Four Types of Buddy System –
1. Binary buddy system
2. Fibonacci buddy system
3. Weighted buddy system
4. Tertiary buddy system
Why buddy system?
If the partition size and process size are different then poor match occurs and may use
space inefficiently.
It is easy to implement and efficient then dynamic allocation.
Binary buddy system –
The buddy system maintains a list of the free blocks of each size (called a free list), so
that it is easy to find a block of the desired size, if one is available. If no block of the
requested size is available, Allocate searches for the first non-empty list for blocks of
atleast the size requested. In either case, a block is removed from the free list.
Example – Assume the size of memory segment is initially 256kb and the kernel requests
25kb of memory. The segment is initially divided into two buddies. Let we call A1 and A2
each 128kb in size. One of these buddies is further divided into two 64kb buddies let say
B1 and B2. But the next highest power of 25kb is 32kb so, either B1 or B2 is further
divided into two 32kb buddies(C1 and C2) and finally one of these buddies is used to
satisfy the 25kb request. A split block can only be merged with its unique buddy block,
which then reforms the larger block they were split from.
Fibonacci buddy system –
This is the system in which blocks are divided into sizes which are Fibonacci numbers. It
satisfies the following relation:
Zi = Z(i-1)+Z(i-2)
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 144, 233, 377, 610. The address calculation for the
binary and weighted buddy systems is straight forward, but the original procedure for the
Fibonacci buddy system was either limited to a small, fixed number of block sizes or a
time consuming computation.
Advantages –
In comparison to other simpler techniques such as dynamic allocation, the buddy
memory system has little external fragmentation.
The buddy memory allocation system is implemented with the use of a binary tree to
represent used or unused split memory blocks.
The buddy system is very fast to allocate or deallocate memory.
In buddy systems, the cost to allocate and free a block of memory is low compared to
that of best-fit or first-fit algorithms.
Other advantage is coalescing.
Address calculation is easy.
Efficient memory management: Kernel memory allocators are designed to efficiently
manage memory resources, ensuring that memory is allocated and deallocated in a
way that minimizes fragmentation and maximizes available space.
Customizable allocation policies: Kernel memory allocators can be customized to
implement specific allocation policies, such as best fit, worst fit, or first fit. This allows
for more precise control over memory usage and allocation.
High performance: Kernel memory allocators are typically designed for high-
performance systems, allowing for fast and efficient allocation and deallocation of
memory.
Reduced memory overhead: Memory allocators can reduce memory overhead by
allowing for more efficient use of memory resources, reducing the overall memory
footprint of the system.
Improved system stability: Efficient memory management can help improve system
stability by reducing the likelihood of memory leaks, crashes, and other issues related
to memory allocation.
Overall, using a kernel memory allocator can help improve system performance, stability,
and memory management, making it an essential component of any operating system.
What is coalescing?
It is defined as how quickly adjacent buddies can be combined to form larger segments
this is known as coalescing.
For example, when the kernel releases the C1 unit it was allocated, the system can
coalesce C1 and C2 into a 64kb segment. This segment B1 can in turn be coalesced with
its buddy B2 to form a 128kb segment. Ultimately we can end up with the original 256kb
segment.
Drawback –
The main drawback in buddy system is internal fragmentation as larger block of memory
is acquired then required. For example if a 36 kb request is made then it can only be
satisfied by 64 kb segment and remaining memory is wasted.
2. Slab Allocation –
A second strategy for allocating kernel memory is known as slab allocation. It eliminates
fragmentation caused by allocations and deallocations. This method is used to retain
allocated memory that contains a data object of a certain type for reuse upon subsequent
allocations of objects of the same type. In slab allocation memory chunks suitable to fit
data objects of certain type or size are preallocated. Cache does not free the space
immediately after use although it keeps track of data which are required frequently so that
whenever request is made the data will reach very fast. Two terms required are:
Slab – A slab is made up of one or more physically contiguous pages. The slab is the
actual container of data associated with objects of the specific kind of the containing
cache.
Cache – Cache represents a small amount of very fast memory. A cache consists of
one or more slabs. There is a single cache for each unique kernel data structure.
Example –
A separate cache for a data structure representing processes descriptors
Separate cache for file objects
Separate cache for semaphores etc.
Each cache is populated with objects that are instantiations of the kernel data structure
the cache represents. For example the cache representing semaphores stores instances
of semaphore objects, the cache representing process descriptors stores instances of
process descriptor objects.
Implementation –
The slab allocation algorithm uses caches to store kernel objects. When a cache is
created a number of objects which are initially marked as free are allocated to the cache.
The number of objects in the cache depends on size of the associated slab.
Example – A 12 kb slab (made up of three contiguous 4 kb pages) could store six 2 kb
objects. Initially all objects in the cache are marked as free. When a new object for a
kernel data structure is needed, the allocator can assign any free object from the cache to
satisfy the request. The object assigned from the cache is marked as used.
In linux, a slab may in one of three possible states:
1. Full – All objects in the slab are marked as used
2. Empty – All objects in the slab are marked as free
3. Partial – The slab consists of both
The slab allocator first attempts to satisfy the request with a free object in a partial slab. If
none exists, a free object is assigned from an empty slab. If no empty slabs are available,
a new slab is allocated from contiguous physical pages and assigned to a cache.
Benefits of slab allocator –
No memory is wasted due to fragmentation because each unique kernel data structure
has an associated cache.
Memory request can be satisfied quickly.
The slab allocating scheme is particularly effective for managing when objects are
frequently allocated or deallocated. The act of allocating and releasing memory can be
a time consuming process. However, objects are created in advance and thus can be
quickly allocated from the cache. When the kernel has finished with an object and
releases it, it is marked as free and return to its cache, thus making it immediately
available for subsequent request from the kernel.
1. Hard disk: The most common form of internal storage device used in a
computer is a hard disk. A hard disk has a circular, magnetized surface on which
the data is stored. A hard disk spins at a speed of between 60 and 120 revolutions
per second. The data stored on the hard disk is read or written by a head that floats
just above the disk (less than 0.1 mm) on a cushion of air. The surface of a hard
disk is divided up into sectors and tracks. Data is stored in the 'blocks' created by
the sectors and tracks. Moving data into a 'block' is called random access.
2. Compact disk: Compact disks can be used to store much more data than aahe
floppy disk. Most compact disks can hold 650 megabytes of data. There are three
main types of compact disk: CD-ROM, CD-R, CD-RW.
3. Magnetic tape: This is a cheap method of storing large amounts of data
(typically 26 gigabytes) and is often used as a 'backing store' for large and
mainframe computers.
4. Removable media: Zip drives are similar to floppy drives and use special (and
rather expensive) floppy disks that can hold between 100 megabytes and 2
gigabytes of data.
Magnetic Disk
• To store computer data, hard disks, flash memory, magnetic tape and optical
Wiedsmil
• Alternate storage for hard disk is Solid State Disks (SSD). These flash memory
tollon based devices offer a different set of tradeoffs from a standard disk. At the
same time, capacity of the hard disk also increases.
• Hybrid category is introduced for storage media. It is hard disks with large flash
memory buffers. Disk sizes are specified in gigabytes.
• Performances of hard disk and SSD technology is given below:
• Hard disk contains several rotating platters coated with magnetic film. They are
read and written by tiny skating heads that are mounted on a metal arm that swings
back and forth to position them. Heads float close to the surface of the platters but
do not actually touch.
• A hard disk is really a set of stacked "disks," each of which, like phonograph
records, has data recorded electromagnetically in concentric circles or "tracks" on
the disk.
• A "head" writes or reads the information on the tracks. Two heads, one on each
side of a disk, read or write the data as the disk spins. Each read or write operation
requires that data be located, which is an operation called a "seek."
• A hard disk/drive unit comes with a set rotation speed varying from 4500 to 7200
rpm. Disk access time is measured in milliseconds.
• Although the physical location can be identified with cylinder, track and sector
locations, these are actually mapped to a Logical Block Address (LBA) that works
with the larger address range on today's hard disks.
• Mean Time Between Failures (MTBF) is the predicted elapsed time between
inherent failures of a system during operation. MTBF can be calculated as the
arithmetic mean (average) time between failures of a system.
• Each disk drive is managed by a controller. Each type of controller can support a
fixed number of drives. SCSI controllers support up to seven disks per controller
or up to 15 disks per controller.
• Each disk is assigned a drive address. This address is set by a switch, a dial or
jumpers on the disk or by the physical location of the disk. Some SCSI devices,
such as RAID's, have an additional identifying number called a logical unit
number. It is used to address disks within the device.
• Fig. 5.1.1 shows physical disk.
• A disk consists of circular plates called platters. Each platter has an upper and
lower oxide-coated surface. Recording heads, at least one per surface, are mounted
on arms that can be moved to various radial distances from the center of the
platters. The heads float very close to the surfaces of the platters, never actually
touching them, and read and record data as the platters spin around.
• A ring on one surface is called a track. Each track is divided into disk blocks.
Sometimes called sectors, these physical blocks on a disk are different from file
system blocks.
• Formatting a disk divides the disk into tracks and disk blocks that can be
addressed by the disk controller, writes timing marks, and identifies bad areas on
the disk.
• SCSI disk drives are shipped preformatted. They do not require formatting at any
time. Bad block handling is performed automatically by SCSI disks. Bad blocks
are areas of a disk that cannot reliably store data.
Platter
• Platter is a circular, metal disk that is mounted inside a hard disk drive. Several
platters are mounted on a fixed spindle motor to create more data storage surfaces
in a smaller area.
• The platter has a core made up of aluminum or glass substrate, covered with a
thin layer of Ferric oxide or cobalt alloy. On both sides of the substrate material, a
thin coating is deposited by a special manufacturing technique. This, thin coating
where actual data is stored is the media layer.
• Attributes of platter
1. It is a rigid, round disk this is coated with magnetically sensitive material.
2. Data is stored in binary code.
3. It is encoded by polarizing magnetic areas on the disk surface.
4. Data can be written to and read from both surfaces of a platter.
5. A platter's storage capacity varies across drives.
Tracks
• Each platter is broken into thousands of tightly packed concentric circles, known
as tracks. These tracks resemble the structure of annual rings of a tree.
• All the information stored on the hard disk is recorded in tracks. Starting from
zero at the outer side of the platter, the number of tracks goes on increasing to the
inner side.
• Each track can hold a large amount of data counting to thousands of bytes.
Sectors
• Each track is further broken down into smaller units called sectors. As sector is
the basic unit of data storage on a hard disk. Disk contains concentric tracks.
Tracks are divided into sectors. A sector is the smallest addressable unit in a disk.
• Fig. 5.1.2 shows surface of disk showing tracks and sectors.
• A single track typically can have thousands of sectors and each sector can hold
more than 512 bytes of data. A few additional bytes are required for control
structures and error detection and correction.
Clusters: Sectors are often grouped together to form clusters.
Read/Write Heads
• The heads are an interface between the magnetic media where the data is stored
and electronic components in the hard disk. The heads convert the information,
which is in the form of bits to magnetic pulses when it is to be stored on the platter
and reverses the process while reading.
• The heads are the most sophisticated part of the hard disk. Each platter has two
read/write heads, one mounted on the top and the other one at the bottom. These
heads are mounted on head sliders, which are suspended at the ends of head
• The head arms are all fused into a singular structure called actuator, which is
responsible for their movement. Drives rotate at 60 to 200 times per second.
• Transfer rate is rate at which data flow between drive and computer.
Positioning time (random-access time) is time to move disk arm to desired cylinder
(seek time) and time for desired sector to rotate under the disk head. Head crash
results from disk head making contact with the disk surface.
• "Each platter (disc-shaped) is coated with magnetic material on both surfaces. All
platter surfaces has arm extended from fixed position. Tip of the arm contains
read/write head for reading or writing data.
• The arm moves the heads from the spindle edge to the edge of the disc.
• When a program reads a byte from the disk, the operating system locates the
surface, track and sector containing that byte, and reads the entire sector into a
special area in main memory called buffer.
• The bottleneck of a disk access is moving the read/write arm.
• A cylinder is the set of tracks at a given radius of a disk pack. A cylinder is the
set of tracks that can be accessed without moving the disk arm. All the information
on a cylinder can be accessed without moving the read/write arm.
Fig. 5.1.3 shows moving-head disk mechanism.
• The arm assembly is moved in or out to position a head on a desired track. Tracks
under heads make a cylinder. Only one head reads/writes at any one time. Block
size is a multiple of sector size.
• Disks can be removable. Drive attached to computer via I/O bus. Buses vary,
including EIDE, ATA, SATA, USB, Fibre channel, SCSI etc.
• Host controller in computer uses bus to talk to disk controller built into drive or
storage array.
• Disk controllers typically embedded in the disk drive, which acts as an interface
between the CPU and the disk hardware. The controller has an internal cache that it
uses to buffer data for read/write requests.
Zone Bit Recording
• Also known as multiple zone recording or zone-CAV recording. Disk divided
into zones. Fig. 5.1.4 shows zone bit recording.
• Cylinders in different zones have a different number of sectors. Number of
sectors in a particular zone is constant. Data is buffered so the data rate to the I/O
interface is constant.
• Zoned-bit recording uses the disk more efficiently. It groups tracks into zones
that are based upon their distance from the center of the disk.
• Each zone is assigned an appropriate number of sectors per track. This means
that a zone near the center of the platter has fewer sectors per track than a zone on
the outer edge.
Magnetic Tape
• Magnetic tapes are used mostly for storing files of data: For example, a
company's payroll record.
• Access is sequential and consists of records that can be accessed one after other
as Saib the tape moves along a stationary read-write mechanism.
• It is one of the cheapest and slowest methods for storage and has the advantage
that tapes can be recovered when not in use.
• A magnetically coated strip of plastic on which data can be encoded. Tape is
much less expensive than other storage mediums but commonly a much slower
solution that is commonly used for backup.
Fig. 5.1.5 shows connection of tape with processor.
• In addition, random access to magnetic tape is about a thousand times slower than
random access to magnetic disk, so tapes are not very useful for secondary is
storage.
• The I/O bus consists of data lines, address lines, and control lines. Each
peripheral device has associated with it an interface unit. Each interface decodes
the address and control received from the I/O bus, interprets them for the
peripheral, and provides signals for the peripheral controller.
• The I/O bus from the processor is attached to all peripheral interfaces. To
communicate with a particular device, the processor places a device address on the
address lines. Each interface attached to the I/O bus contains an address decoder
that monitors the address lines.
• When the interface detects its own address, it activates the path between the bus
lines and the device that it controls.
• All peripherals whose address does not correspond to the address in the bus are
disabled their interface. At the same time that the address is made available in the
address lines, the processor provides a function code in the control lines.
• The interface selected responds to the function code and proceeds to execute it.
The function code is referred to as an I/O command and is in essence an instruction
that is executed in the interface and its attached peripheral unit.
• The interpretation of the command depends on the peripheral that the processor is
addressing. There are four types of commands that an interface may receive. They
are classified as control, status, status, data output, and data input.
3.5 HDD Scheduling
Disk scheduling is done by operating systems to schedule I/O requests arriving for the
disk. Disk scheduling is also known as I/O Scheduling.
Importance of Disk Scheduling in Operating System
Multiple I/O requests may arrive by different processes and only one I/O request can
be served at a time by the disk controller. Thus other I/O requests need to wait in the
waiting queue and need to be scheduled.
Two or more requests may be far from each other so this can result in greater disk arm
movement.
Hard drives are one of the slowest parts of the computer system and thus need to be
accessed in an efficient manner.
Key Terms Associated with Disk Scheduling
Seek Time: Seek time is the time taken to locate the disk arm to a specified track
where the data is to be read or written. So the disk scheduling algorithm that gives a
minimum average seek time is better.
Rotational Latency: Rotational Latency is the time taken by the desired sector of the
disk to rotate into a position so that it can access the read/write heads. So the disk
scheduling algorithm that gives minimum rotational latency is better.
Transfer Time: Transfer time is the time to transfer the data. It depends on the rotating
speed of the disk and the number of bytes to be transferred.
Disk Access Time:
Disk Access Time = Seek Time + Rotational Latency + Transfer Time
Total Seek Time = Total head Movement * Seek Time
Disk Response Time: Response Time is the average time spent by a request waiting
to perform its I/O operation. The average Response time is the response time of all
requests. Variance Response Time is the measure of how individual requests are
serviced with respect to average response time. So the disk scheduling algorithm that
gives minimum variance response time is better.
Disk Scheduling Algorithms
There are several Disk Several Algorithms. We will discuss each one of them.
FCFS (First Come First Serve)
FCFS is the simplest of all Disk Scheduling Algorithms. In FCFS, the requests are
addressed in the order they arrive in the disk queue. Let us understand this with the help
of an example.
First Come First Serve
Example:
Suppose the order of request is- (82,170,43,140,24,16,190)
And current position of Read/Write head is: 50
So, total overhead movement (total distance covered by the disk arm) =
(82-50)+(170-82)+(170-43)+(140-43)+(140-24)+(24-16)+(190-16) =642
Advantages of FCFS
Here are some of the advantages of First Come First Serve.
Every request gets a fair chance
No indefinite postponement
Disadvantages of FCFS
Here are some of the disadvantages of First Come First Serve.
Does not try to optimize seek time
May not provide the best possible service
SSTF (Shortest Seek Time First)
In SSTF (Shortest Seek Time First), requests having the shortest seek time are executed
first. So, the seek time of every request is calculated in advance in the queue and then
they are scheduled according to their calculated seek time. As a result, the request near
the disk arm will get executed first. SSTF is certainly an improvement over FCFS as it
decreases the average response time and increases the throughput of the system. Let us
understand this with the help of an example.
Example:
Circular SCAN
LOOK Algorithm
C-LOOK
As LOOK is similar to the SCAN algorithm, in a similar way, C-LOOK is similar to the
CSCAN disk scheduling algorithm. In CLOOK, the disk arm in spite of going to the end
goes only to the last request to be serviced in front of the head and then from there goes
to the other end’s last request. Thus, it also prevents the extra delay which occurred due
to unnecessary traversal to the end of the disk.
Example:
1. Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the
Read/Write arm is at 50, and it is also given that the disk arm should move “towards
the larger value”
C-LOOK
So, the total overhead movement (total distance covered by the disk arm) is calculated as
= (190-50) + (190-16) + (43-16) = 341
Types of File
• File type represents the internal structure of the file. According to the
structure, file is divided into certain types: text, source, executable and object
file.
1. Text file: It is sequence of character which organized into lines. Text file is a
regular file.
2. Source file: It contains sequence of subroutines, procedure and functions.
3. Executable file: It contains a series of code sections. This file is input to the
loader and loader loads this file into memory and then execute.
4. Object file: Object file is input to the linker. An Object file is a binary file
that the compiler creates that converts the source to object code.
File Types
File is divided into following types:
1. Ordinary file
2. Directory file
3. FIFO file
4. Character device file
5. Block device file.
Ordinary file
• Also called regular file. It contains only data as a stream of characters. An bis
ordinary file cannot contain another file, or directory.
• It is either text file or a binary file.
• Examples of ordinary files include simple text files, application data files,
files containing high-level source code, executable text files, and binary image
files.
• Text file: It contains only printable characters.
• Binary file: It contains printable and unprintable characters that cover the
entire ASCII range.
• Regular files may be created, browsed through, and modified by various
means such as text editors.
Directory file
• A directory file is like a folder that contains other files, including subdirectory
files.
• Directory files act as a container for other files, of any category. Directory
files don't contain data in the user sense of data; they merely contain references
to the files contained within them.
• Directory is created in UNIX by the mkdir command.
• The UNIX directory is considered empty if it contains no other files except the
"." and "..".
• Directory is removed by using rmdir command. Content of directory is displayed.
by ls command.
Device file
• Special files are also known as device files. In UNIX all physical devices are
accessed via device files; they are what programs use to communicate with
hardware.
• Files hold information on location, type, and access mode for a specific device.
There are two types of device files; character and block.
• Block device files are used to access block device I/O. Block devices do buffered
ar I/O, meaning that the data is collected in a buffer until a full block can be
transferred.
• Character device files are associated with character or raw device access. They
are used for un-buffered data transfers to and from a device. Rather than
transferring data in blocks the data is transferred character by character.
• One transfer can consist of multiple characters.
• Some devices, such as disk partitions, may be accessed in block or character
mode. Because each device file corresponds to a single access mode, physical
devices that have more than one access mode will have more than one device file.
• Device files are found in the /dev directory. Each device is assigned a major and
minor device number."
• The major device number identifies the type of device, i.e. all SCSI devices,
would have the same number as would all the keyboards.
• The minor device number identifies a specific device, i.e. the keyboard attached
to workstation.
• Device files are created using the mknod command.
• Example of character device files is printers, modems and consoles.
FIFO file
• FIFO file is special pipe device file which provides temporary buffers for two or
more processes to communicate by writing data to and reading data from the
buffer.
• A FIFO is created by the mknod system call and may be opened and accessed by
any process that knows the name and has the permissions.
• The buffer associated with a FIFO file is allocated when the first process opens
the FIFO file for read or write. The buffer is discarded when all processes which
are connected to the FIFO close their reference to the FIFO file.
• FIFO file may be removed like any regular file. FIFO files can be removed in
UNIX via the rm command.
File Attributes
• One of the characteristics of file is a set of file attributes that give the operating
system more information about the file and how it is intended to be used. For
human users convenience bane is given to the file. File attributes are varies from
system to system.
• File attributes are as follows:
1. Name
2. Identifier
3. Type
4. Location/place
5. Size
6. Protection
7. Date and Time
• File name is in human readable. User can perform any operation on file using its
name.
• When file is created by user, operating system assigns unique identification
number to each file. OS uses this identifier for its operation.
• Type information is required for systems that support different types of files.
• Location/place information is pointer to a device and actual location of files on
the device. The information needed to locate the file on disk is kept in memory.
• Size is measured in bits or bytes. It gives idea about current size of the file.
• Protection: This information is stored on the per-process table so the operating
system can allow or deny subsequent requests. Attributes like protection,
password, creator and owner provides protection to a file.
• Date and time: This information is related to creation and modification of files.
Protection, security and monitoring purposes this data is used by operating system.
Operation on File
• File operations are simply those things that user can perform on a file. For
example, user can create a file, save a file, open a file, read a file and modify a file.
There are many different types of file operations supported by operating system.
• Operating system can provides system call for performing various operations on
the file. Six basic file operations are creating, write, read, delete, repositioning and
truncating.
• Following are the some list of file operation:
1. Create
2. Write
3. Closes
4. Read
5. Delete
6. Repositioning.
• All these operations require that the directory structure be first searched for the
target file.
• File creation: Any time user can create a file. File is also created without data.
The steps for creating a file.
a. Space: File system must provide a space for the file.
b. New file entry is made in the directory.
• Write: To perform write operation on the file, file name and data is required. It
updates a file by adding new data and changes some content of the file. For writing
into a file, operating system searches the directory for particular file. Write pointer
is kept at the location where the writing starts. Write pointer position is at middle
of the file or end of the file. Write pointer is updated when writing to file is
completed.
• Close: Process is not used a file after closing. Process can not perform any
operation on file. Operating system remove it entry from open file table.n
• Read: A process reads all or some portion of the data in a file. Read system call
is used for reading a file. For reading a file, name and position of the memory is
specified. Read pointer is kept into the file for next read operation. Read pointer is
updated after completion of the read system call. Information about read pointer is
stored in per process current file position pointer.
• Delete: Operating system remove the file from file structure. For deleting a file,
no directory is searched with particular name and file is deleted. Deleting
means making space free from memory and disk. Operating system also removes
the directory entry. This free space is used by another file. ein
• Repositioning: The directory is searched for the proper entry, and the current-
file-position pointer is repositioned to a given value. Repositioning within
• Other file operations are open, append, seek, get and set attributes and rename.
• Open: Before performing any operation on file, it is necessary to
• Append: Append is related to write operation of file. Append only add data to
the end of the file.
• Get and set attributes: Get attribute is used before performing operation on file.
When user request a file for any operation, get attributes is executed by the
process. Depending upon the attributes, user can allow or deny the operation. User
can set the attributes and it changed after creation of file.
• Rename: User can change the name of existing file.
File Structure
• File structure is represented by field, record, file and database. It is also
represented by byte sequence, record sequence and tree.
• Fig. 6.1.1 shows the three different kinds of files. Unix and windows both use
unstructured byte sequence
• Batch application uses sequential files. A byte stream file uses sequential access
method.
• Example: Compiler and editor usually access files in this method. Transaction
file is also example of sequential access method.
• Sequential file organization only method easily stored on tape and hard disk.
Sequential access is best suited where most of the records in a file are to be
processed.
Disadvantages:
• It provides poor performances.
• More efficient search technique is required.
• Each record has its own address on the file with by the help of which it can be
directly accessed for reading or writing. This feature is used by editors. An editors
need to randomly access the contents of the file.
• There is no restriction on the order of reading or writing for a direct access file.
Operating system support is not required for direct access file.
• At the time of file creation, access method is defined. According to defined
access method, file is accessed. Sequential access of a direct access file is possible
but direct access of a sequential file is not.
Disadvantages:
1. Poor utilization of input-output device.
2. Consumes CPU time for record address calculation.
• Indexed sequential files are store records in the order that they are written to the
disk. Records may be retrieved in sequential order or in random order using an
index to represent the record number in the file.
• If file size is large, larger index is required and it contains large number of
entries. CPU takes time to search in to the index. Higher level index is used to
reduce the search time. An entry in the higher level index points to a section of the
index. This higher index contains the records. This index is searched to find the
section sdns of the disk that may contains a required record.
• File system maintains an overflow file. It adds new records to an overflow file.
The record in the main file that immediately precedes the new record in logical
sequence is updated to contain pointer to the new record in the overflow file.
• The overflow file is merged with the main file during a batch update. The
multiple indexes for the same key field can be set up to increase efficiency.
• The lowest level of index file is treated as a sequential file and a higher level
index file is created for that file. Higher index file would contain pointers to lower
index files, which would point to the actual data items.
3.8 Directory Structure
User stores file in file system using directory. File system stores files of many
users. Files are stored on the secondary storage device like hard disk, optical disk
and memory disk. These device support random access method.
• Directory structure organizes and provides information about all files in the
system. Every partition has a file system which consists of files and directory. Hard
disks are split into one or more partitions. It is called as minidisks or volumes. User
can assign names to volumes. Each disk contains minimum one partition.
• Operating systems support upto 24 partitions. Partitions can be larger than a disk
i.e combing two hard disks. These partitions are called "virtual disks". Partition
maintains information about files in "Device Directory".
• Files are stored in the directory. Directory is created by user. User is free to create
as many as directory and assign suitable names. File system contains many
directories. Directory maintains information about the file. File information
includes type, size, date modified and name.
• In some operating system, directory itself is considered as a file. A set of
logically associated files is called directory. Directory structure of the file system
connects a directory to other directories in the system.
• Directory is a data structure that lists files and subdirectories in a collection.
Directory structure contains a list of entries one for each file.
• Directory does not store any user data. Single dot (.) indicates a current directory
rote and double dot (..) indicates parent directory. The root is identified by the
directory '/'. The root file system has several subdirectories.
• Windows file system uses a letter followed by colon for specifying root directory.
For example, root directory in windows is C: or D: or E:
• UNIX and Linux based file system uses slash (/) for specifying root directory.
• A directory can contain any number of files. A directory can also contain
subdirectories. Because a directory is nothing more than a special kind of file,
directories also have names.
Operation on directory :
1. File searching: Directory structure is searched for particular file entry. File uses
symbolic names and similar names may indicate a relationship between files.
2. Create a file: User creates new files and added to the directory.
3. Delete a file: User remove the file after completing its work on files.
4. Rename a file: User change the file name if file content is change.
5. Listing of directory: Listing of files in the directory for some use. MS-DOS
and windows uses "dir" command and Linux/UNIX uses "ls" command for this
purposes.
• Single level directory structure is suitable only for single user. If user increases, it
creates the problem with assigning the name to files.
• In single level directory structure, no two files can have the same name.
• It is simple to implement and searching of file is faster. This type of directory
system is used in cameras and phones.
• Because of limitation of file names, this structure is rarely implemented.
• File name size varies according to the operating system. MS-DOS operating
system allows only 11 character file names and UNIX OS allows upto 255
characters.
Disadvantages of single level directory:
1. Not suitable for a large number of files
2. Limitation of unique file name.
3. For large number of file, recalling file name is difficult.
• Here user can work only in own directory. Other user need not worry about
deleting or modifying files by other users.
• When user wants to create a file, system search that particular file name in the
directory. If same file name is not found, then it creates a file otherwise it gives
error messages.
• In this structure, different users may have files with same name. It solves the Viol
name conflict problem. When user want to open a file, filename is searched for in
users directory.
• A two level directory can be a tree or an inverted tree of height 2.
• There are still problems with two-level directory structure. It effectively isolates
one user from another. This is some time advantage or some time disadvantages.
For completely independent user is an advantages and disadvantages when
cooperation between two users is required.
• In this structure, directory itself is a file. A directory and sub directory contains a
set of files. Internal format is same for all directories
• Commonly used directory structure is tree structure. Tree has a root directory.
All files in disk have a unique path name.
• A path name describes the path that the operating system must take to get from
some starting point in the file system to the destination object. Each process has its
own working directory. Path names are of two types : relative and absolute.
• Relative path name : Its path starts from current working directory (may start
with
• Absolute path name: Its path starts from root directory (starts from "/").
• Tree structured directory differentiate file and subdirectory by using one bit
representation. Zero (0) represents file and one (1) represents subdirectory.
• When process makes reference to a file for opening, file system search this file in
the current directory. If needed file is not found in the current directory, then user
either change the directory or give the full path of the file. System calls are used
for performing any operation on the files or directory.
• Empty directory and its entry are easily deleted by operating system. If directory
contains files and subdirectory, i.e. non-empty directory, some operating systems
not delete the directory.
• To delete a directory, user must first delete all the files and subdirectory in that
directory.
Merits
1. User can create his/her own directory.
2. User can access other user files by specifying path name.
3. Separate subdirectory for files associated with different topics
4. Searching id fast and efficient.
Demerits
1. Sub directory can not share between the user
2. Path is longer than two level directory structure
Acyclic Graph Directory
• Acyclic graph directory solve the problem of tree structure directory.
• It allows sharing the directory in between two users. At a time more than one
places shared directory or file will exist in the file system.
• Fig. 6.3.4 shows acyclic graph directory. Links can be used to construct acyclic
graph
• It is very interesting to note that a shared directory or file is not the same as two
copies of the file. When there are two copies of files, each user can view the copy
rather than the original, but if one user changes the file content, the changes will e
file content, t not appear in the other's copy.
• Only one original file exists for shared copy. Any changes made by one user are
immediately visible to the other user. When user create file in shared directory, it
automatically appear in all the shared subdirectories.
Implementation of shared files and directory:
1. Using link :
• Link is used for creating shared files and directory. A link is a pointer to another
file or subdirectory. If reference to a file is made, the directory is first searched. A
link is a logical relationship between an inode and a file that relates the name of a
file to its physical location.
• UNIX operating system uses acyclic graph directory structure. Reference count is
maintained by UNIX for files and directory. UNIX operating system provides two
types of links: hard link and symbolic link
• A hard link contains multiple directory entries that both refer to the same file.
Hard links are only used with ordinary files in the same file system.
• A symbolic link is also called soft link. It contains a special file which maintains
the information about file where to find the linked file. Symbolic links may be used
to link directories and files in other file systems.
• Soft links were designed for two specific situations: Links to directories, which
must be symbolic, and links to files in other file systems.
• Windows operating system only supports symbolic links.
• Hard links require a reference count, or link count for each file, keeping track of
how many directory entries are currently referring to this file. Whenever one of the
references is removed the link count is reduced, and when it reaches zero, the disk
space can be reclaimed.
2. Duplicating information:
• Duplicate all information about shared files in both sharing directories. Original
file will remain as it is without modifying any content by shared user.
• Consistencyis not supported by copied file and shared file. Shared files may have
more than one absolute path.
Advantages:
1. Simple for file traverse.
2. Structure is more flexible than a simple tree structure.
3. It allows directories and files to be shared between other users.
Disadvantages:
1. Deletion of file is difficult.
2. Problem with duplicate directory entries is maintaining consistency if the file is
modified.
Type of Access
• Access is limited or full access of data. User having full access can perform read,
write and modify operation on the data and information. In limited access, user
only read and executes the information.
• Protection mechanism provides controlled access. Following are some of the aw
operation performed on the files.
1. Read: User can read a file.
2. Write: User can rewrite a file.
3. Delete: User can delete a file whenever space is required.
4. Execute: User execute a file after loading into the main memory.
5. List: User check attributes of the file and file/directory names.
Access Control
• Traditionally, a file object in Linux is associated with three sets of permissions.
These sets assign read (r), write (w), and execute (x) permissions for the three user
groups file owner group, and other.
• Nine bits are used to determine the characteristics of all objects in a Linux
system. Additionally, the set user id, set group id and sticky bits can be set for
special cases.
• ACLS can be used for situations where the traditional file permission concept
does not suffice. They allow the assignment of permissions to individual users or
groups even if these do not correspond to the owner or the owning group. Access
Control Lists are a feature of the Linux kernel.
• There are two types of ACLS : Access ACLS and default ACLs. An access ACL
is the access control list for a specific file or directory. A default ACL can only be
associated with a directory; if a file within the directory does not have an
access ACL, it uses the rules of the default ACL for the directory. Default ACL's
are optional.
• ACL's can be configured:
1. Per user 2. Per group
3. Via the effective rights mask
4. For users not in the user group for the file.
Access determination
• When a process attempts to access a file, its effective UID is compared to the
UID that owns the file. If they are the same, access is determined by the ACL's
user permissions. Otherwise, if a matching user specific ACL entry exists,
permissions are determined by that entry in combination with the ACL mask.
• If no specific entry is available, the file system tries to locate a valid group related
b entry that provides the required access; these entries are processed in conjunction
se with the ACL mask. If no matching entry can be found, the other entry prevails.
NFSv4 ACL
• The NFSv4 (Network File System - Version 4 protocol introduces a new ACL
format that extends other existing ACL formats. NFSv4 ACL is easy to work with
and introduces more detailed file security attributes, making NFSv4ACLs more
• NFSv4 ACL's are similar to Windows ACL's in structural perspective. In both the
system, ACL stores this entity as a string.
The Windows and NFSv4 permission model is more granular than the traditional
UNIX read-write-execute model.
1. NFSv4 distinguishes permissions to create files within a directory from
permission to create subdirectories.
2. NFSv4 has a separate append permission bit.
3. NFSv4 has separate read and write permissions for data, file attributes, extended
attributes, and ACLs.
4. NFSv4 controls a user's ability to change the ownership of a file through the
standard ACL.
NFSv4 file permissions
Contiguous Allocation
• When user creates a file, system allocates a set of contiguous blocks on disk. This
is a pre-allocation method that uses portion of variable size. Contiguous allocation
is simple method to implement. It only search free list of correct number of
consecutive blocks and mark them as used block.
• Disk address is a linear ordering on the disk. Because of linear ordering,
accessing block b + 1 after block b normally requires no head movement. Here
head movement is only one track. Fig. 6.10.1 shows contiguous allocation.
• Contiguous allocation of a file is defined by the disk address and the length of the
on first block.
• If the file size is "n" blocks and starting location is "L", then it occupies blocks L,
L+1, L+2, L+3, ......, L+(n-1). The directory entry for each file indicates the
address of the starting block and the length of the area allocated for this file.
• Sequential and random access can be supported by contiguous allocation.
• It is easy to retrieve single block. To improve the I/O performance of sequential
processing, multiple blocks can be brought in one at a time. It supports sequential
access very well because files entire data is stored in adjacent block. This method
bra also supports random access.
• Contiguous allocation also suffers from external fragmentation. Small free disk
spaces are created after allocation free block and deleting files.. External
fragmentation means there will require free space available but that is not
contiguous. To solve the problem of external fragmentation, compaction method is
used.
• One more problem is that how to calculate the space needed for a file. It is
difficult to estimate the required space.
• This method is good for storing data on CD-ROM.
Characteristic of contiguous file allocation :
1. It supports variable size portions.
2. Pre-allocation is required.
3. It requires only single entry for a file.
4. Allocation frequency is only once.
Advantages:
1. It supports variable size portion.
2. Easy to retrieve single block.
3. Accessing a file is easy.
4. It provides good performance.
Disadvantages:
1. It suffers from external fragmentation.
2. Pre-allocation is required.
Linked Allocation
• Linked allocation is also called chained allocation. Operating system keeps an
ordered list of free blocks. File descriptor stores pointers to the first block and each
block stores pointer to the nest block.
• Fig. 6.10.2 shows linked allocation. The disk blocks may be scattered anywhere
on the disk. The directory contains a pointer to the first and last blocks of the file.
No space is lost to disk fragmentation.
• Creation of new file is easy. For new file, simply create new entry in the
directory. Reading a file is straightforward. User simple read blocks by following
pointers from block to block. There is no external fragmentation with linked
allocation.
• To write to file, system finds a free block, and this new block is written to and
linked to the end of the file.
• While creating a new file, it is not necessary to declare the size of the file. A file
can contiguous to grow as long as free blocks are available.
• Compaction can be used so that blocks of one file are located continuously on the
disk. It optimizes disk access.
• File allocation table is an extension of the linked allocation method. Instead of
putting the pointers in the file, keep a table of the pointers around. This pointer
table can be quickly searched to find ant random block in the file.
• Fig. 6.10.3 shows the file allocation table. All blocks on the disk must be
included in the table. This method is used by windows operating system.
(Refer Fig. 6.10.3 on next page)
Characteristics
1. It supports fixed size portions.
2. Pre-allocation is possible.
3. File allocation table is one entry for a file.
4. Allocation frequency is low to high.
Advantages:
1. There is no external fragmentation.
2. It is never necessary to compact disk space.
3. Pre-allocation is not required.
Disadvantages:
1. Files are accessed only sequentially.
2. Space required for pointers.
3. Reliability is not good.
4. Can not support direct access.
Indexed Allocation
• Indexed allocation method solves the problem of both contiguous and linked
allocation. It uses concept of index block. Index block stores the entire pointer in
one location. But the index block will occupy some space and thus could be
considered as an overhead of the method.
• OS keeps a list of free blocks. It allocates an array to hold pointers to all the
blocks used by the file. It allocates blocks only on demand. Fig. 6.10.4 shows
indexed allocation.
• In indexed allocation, each file maintains its own index block. It contains an array
of disk sector of addresses. For example: The nth entry in the index block points to
the nth sector of the file. The directory contains the address of the index block of a
file. To read the nth sector of the file, the pointer in the nth index block entry
• It supports direct access and without suffering from external fragmentation. Any
free block anywhere on the disk may satisfy a request for more space.
• Indexed allocation does suffer from wasted space. The pointer overhead of the
index block is generally greater than the pointer overhead of linked
allocation. Advantages:
1. It supports sequential and direct access.
2. No external fragmentation.
3. Faster than other two methods.
4. It supports fixed and variable size blocks.
Disadvantages:
1. Indexed allocation does suffer wasted space.
2. Pointer overhead is generally greater.
• When bit table is stored into the memory, then exhaustive search of the table can
ano slow file system performance. Most of the file system use auxiliary data
structure al for bit table. File system also maintain summary table. Summary table
contains sub-range, number of free blocks and maximum sized contiguous number
of free blocks.
• Summary table is used to store information about contiguous free blocks.
Whenever file system needs a number of contiguous blocks, it can scan the
summary table to find an appropriate sub-range and then search that sub-range.
This method is used in Apple Macintosh.
Advantage :
a. Easy to find a free blocks
b. It is as small as possible.
Disadvantage :
It may not be feasible to keep the bitmap in memory for large disks.
2. Link list
• In this method, all free space disk blocks are linked, keeping a pointer to the first
free block. All file allocation methods used link list free space techniques.
• There is small space overhead because there is no need for a disk allocation table.
In the above example, free blocks are 3, 4, 5, 7, 9, 14, 15, 19, 30, 31, 32, 35, 36,
37, 38. Here free block pointer is on block number 3. Block 3 contains pointer to
block 4, block 4 contains pointer to block 5 and block 5 contains pointer to block 7
and so on.
• This method is not efficient because to reach free block 9, we have to traverse
973 block 3, 4, 5 and 7 then we will reach to block 9.
• Disk will become quite fragmented after some use. Many portions will be a single
block long.
3. Grouping
• First free block contains the addresses of n free blocks. The first n-1 of these
blocks is actually free. The last block also contains the address of another n free
block.
• Consider the free blocks: 3, 4, 5, 7, 9, 14, 15, 19, 30, 31, 32, 35, 36, 37, 38
• When all the blocks in the group have been allocated, then use the block that held
the pointer.
• Because of grouping method, address of a large number of free blocks can be
found quickly.
4. Counting
• It keeps the address of the first free block and the number n of free contiguous
blocks that follow the first block. Each entry in the free space list then consists of a
disk address and a count.