0% found this document useful (0 votes)
4 views

OS Unit-4

Memory management is a critical function of an operating system that oversees the allocation and tracking of primary memory, facilitating process execution through various techniques such as swapping, paging, and segmentation. It involves managing logical and physical addresses, as well as handling fragmentation and memory allocation strategies. The document also discusses different types of memory, including RAM, ROM, SRAM, and DRAM, and their roles in efficient memory management.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

OS Unit-4

Memory management is a critical function of an operating system that oversees the allocation and tracking of primary memory, facilitating process execution through various techniques such as swapping, paging, and segmentation. It involves managing logical and physical addresses, as well as handling fragmentation and memory allocation strategies. The document also discusses different types of memory, including RAM, ROM, SRAM, and DRAM, and their roles in efficient memory management.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Unit-4 :MEMORY MANAGEMENT:

MEMORY MANAGEMENT :
Memory management is the functionality of an operating system which handles or manages primary memory and moves processes back and forth between main memory and
disk during execution. Memory management keeps track of each and every memory location, regardless of either it is allocated to some process or it is free. It checks how much
memory is to be allocated to processes. It decides which process will get memory at what time. It tracks whenever some memory gets freed or unallocated and correspondingly
it updates the status.
This tutorial will teach you basic concepts related to Memory Management.

Process Address Space


The process address space is the set of logical addresses that a process references in its code. For example, when 32-bit addressing is in use, addresses can range from 0 to
0x7fffffff; that is, 2^31 possible numbers, for a total theoretical size of 2 gigabytes.
The operating system takes care of mapping the logical addresses to physical addresses at the time of memory allocation to the program. There are three types of addresses
used in a program before and after memory is allocated −

S.N. Memory Addresses & Description

1
Symbolic addresses
The addresses used in a source code. The variable names, constants, and instruction
labels are the basic elements of the symbolic address space.

2
Relative addresses
At the time of compilation, a compiler converts symbolic addresses into relative
addresses.

3
Physical addresses
The loader generates these addresses at the time when a program is loaded into main
memory.

Virtual and physical addresses are the same in compile-time and load-time address-binding schemes. Virtual and physical addresses differ in execution-time address-binding
scheme.
The set of all logical addresses generated by a program is referred to as a logical address space. The set of all physical addresses corresponding to these logical addresses
is referred to as a physical address space.
The runtime mapping from virtual to physical address is done by the memory management unit (MMU) which is a hardware device. MMU uses following mechanism to convert
virtual address to physical address.

 The value in the base register is added to every address generated by a user process, which is treated as offset at the time it is sent to memory. For example, if the base
register value is 10000, then an attempt by the user to use address location 100 will be dynamically reallocated to location 10100.
 The user program deals with virtual addresses; it never sees the real physical addresses.

Static vs Dynamic Loading


The choice between Static or Dynamic Loading is to be made at the time of computer program being developed. If you have to load your program statically, then at the time of
compilation, the complete programs will be compiled and linked without leaving any external program or module dependency. The linker combines the object program with other
necessary object modules into an absolute program, which also includes logical addresses.
If you are writing a Dynamically loaded program, then your compiler will compile the program and for all the modules which you want to include dynamically, only references will
be provided and rest of the work will be done at the time of execution.
At the time of loading, with static loading, the absolute program (and data) is loaded into memory in order for execution to start.
If you are using dynamic loading, dynamic routines of the library are stored on a disk in relocatable form and are loaded into memory only when they are needed by the program.

Static vs Dynamic Linking

As explained above, when static linking is used, the linker combines all other modules needed by a program into a single executable program to avoid any runtime dependency.
When dynamic linking is used, it is not required to link the actual module or library with the program, rather a reference to the dynamic module is provided at the time of compilation
and linking. Dynamic Link Libraries (DLL) in Windows and Shared Objects in Unix are good examples of dynamic libraries.

Swapping

Swapping is a mechanism in which a process can be swapped temporarily out of main memory (or move) to secondary storage (disk) and make that memory available to other
processes. At some later time, the system swaps back the process from the secondary storage to main memory.
Though performance is usually affected by swapping process but it helps in running multiple and big processes in parallel and that's the reason Swapping is also known as a
technique for memory compaction.
The total time taken by swapping process includes the time it takes to move the entire process to a secondary disk and then to copy the process back to memory, as well as the
time the process takes to regain main memory.
Let us assume that the user process is of size 2048KB and on a standard hard disk where swapping will take place has a data transfer rate around 1 MB per second. The actual
transfer of the 1000K process to or from memory will take
2048KB / 1024KB per second
= 2 seconds
= 2000 milliseconds
Now considering in and out time, it will take complete 4000 milliseconds plus other overhead where the process competes to regain main memory.

Memory Allocation
Main memory usually has two partitions −

 Low Memory − Operating system resides in this memory.


 High Memory − User processes are held in high memory.
Operating system uses the following memory allocation mechanism.

S.N. Memory Allocation & Description

1
Single-partition allocation
In this type of allocation, relocation-register scheme is used to protect user processes
from each other, and from changing operating-system code and data. Relocation
register contains value of smallest physical address whereas limit register contains
range of logical addresses. Each logical address must be less than the limit register.

2
Multiple-partition allocation
In this type of allocation, main memory is divided into a number of fixed-sized partitions
where each partition should contain only one process. When a partition is free, a
process is selected from the input queue and is loaded into the free partition. When
the process terminates, the partition becomes available for another process.

Fragmentation

As processes are loaded and removed from memory, the free memory space is broken into little pieces. It happens after sometimes that processes cannot be allocated to memory
blocks considering their small size and memory blocks remains unused. This problem is known as Fragmentation.
Fragmentation is of two types −

S.N. Fragmentation & Description

1
External fragmentation
Total memory space is enough to satisfy a request or to reside a process in it, but it is
not contiguous, so it cannot be used.

2
Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory is left unused,
as it cannot be used by another process.

The following diagram shows how fragmentation can cause waste of memory and a compaction technique can be used to create more free memory out of fragmented memory

External fragmentation can be reduced by compaction or shuffle memory contents to place all free memory together in one large block. To make compaction feasible, relocation
should be dynamic.
The internal fragmentation can be reduced by effectively assigning the smallest partition but large enough for the process.

Paging

A computer can address more memory than the amount physically installed on the system. This extra memory is actually called virtual memory and it is a section of a hard that's
set up to emulate the computer's RAM. Paging technique plays an important role in implementing virtual memory.
Paging is a memory management technique in which process address space is broken into blocks of the same size called pages (size is power of 2, between 512 bytes and
8192 bytes). The size of the process is measured in the number of pages.
Similarly, main memory is divided into small fixed-sized blocks of (physical) memory called frames and the size of a frame is kept the same as that of a page to have optimum
utilization of the main memory and to avoid external fragmentation.
Address Translation
Page address is called logical address and represented by page number and the offset.
Logical Address = Page number + page offset

Frame address is called physical address and represented by a frame number and the offset.
Physical Address = Frame number + page offset

A data structure called page map table is used to keep track of the relation between a page of a process to a frame in physical memory.
When the system allocates a frame to any page, it translates this logical address into a physical address and create entry into the page table to be used throughout execution of
the program.
When a process is to be executed, its corresponding pages are loaded into any available memory frames. Suppose you have a program of 8Kb but your memory can
accommodate only 5Kb at a given point in time, then the paging concept will come into picture. When a computer runs out of RAM, the operating system (OS) will move idle or
unwanted pages of memory to secondary memory to free up RAM for other processes and brings them back when needed by the program.
This process continues during the whole execution of the program where the OS keeps removing idle pages from the main memory and write them onto the secondary memory
and bring them back when required by the program.

Advantages and Disadvantages of Paging


Here is a list of advantages and disadvantages of paging −

 Paging reduces external fragmentation, but still suffer from internal fragmentation.
 Paging is simple to implement and assumed as an efficient memory management technique.
 Due to equal size of the pages and frames, swapping becomes very easy.
 Page table requires extra memory space, so may not be good for a system having small RAM.

Segmentation

Segmentation is a memory management technique in which each job is divided into several segments of different sizes, one for each module that contains pieces that perform
related functions. Each segment is actually a different logical address space of the program.
When a process is to be executed, its corresponding segmentation are loaded into non-contiguous memory though every segment is loaded into a contiguous block of available
memory.
Segmentation memory management works very similar to paging but here segments are of variable-length where as in paging pages are of fixed size.
A program segment contains the program's main function, utility functions, data structures, and so on. The operating system maintains a segment map table for every process
and a list of free memory blocks along with segment numbers, their size and corresponding memory locations in main memory. For each segment, the table stores the starting
address of the segment and the length of the segment. A reference to a memory location includes a value that identifies a segment and an offset.

Main Memory

The main memory is the fundamental storage unit in a computer system. It is associatively large and quick memory and saves programs and information during computer
operations. The technology that makes the main memory work is based on semiconductor integrated circuits.
RAM is the main memory. Integrated circuit Random Access Memory (RAM) chips are applicable in two possible operating modes are as follows −

 Static − It consists of internal flip-flops, which store the binary information. The stored data remains solid considering power is provided to the unit. The static RAM is
simple to use and has smaller read and write cycles.
 Dynamic − It saves the binary data in the structure of electric charges that are used to capacitors. The capacitors are made available inside the chip by Metal Oxide
Semiconductor (MOS) transistors. The stored value on the capacitors contributes to discharge with time and thus, the capacitors should be regularly recharged through
stimulating the dynamic memory.
Random Access Memory
The term Random Access Memory or RAM is typically used to refer to memory that is easily read from and written to by the microprocessor. For a memory to be called random
access, it should be possible to access any address at any time. This differentiates RAM from storage devices such as tapes or hard drives where the data is accessed
sequentially.
RAM is the main memory of a computer. Its objective is to store data and applications that are currently in use. The operating system controls the usage of this memory. It gives
instructions like when the items are to be loaded into RAM, where they are to be located in RAM, and when they need to be rem oved from RAM.

Read-Only Memory
In each computer system, there should be a segment of memory that is fixed and unaffected by power failure. This type of memory is known as Read-Only Memory or ROM.

SRAM
RAMs that are made up of circuits and can preserve the information as long as power is supplied are referred to as Static Random Access Memories (SRAM). Flip-flops form
the basic memory elements in an SRAM device. An SRAM consists of an array of flip-flops, one for each bit. SRAM consists of an array of flip-flops, a large number of flip-flops
are needed to provide higher capacity memory. Because of this, simpler flip-flop circuits, BJT, and MOS transistors are used for SRAM.

DRAM
SRAMs are faster but their cost is high because their cells require many transistors. RAMs can be obtained at a lower cost if simpler cells are used. A MOS storage cell based
on capacitors can be used to replace the SRAM cells. Such a storage cell cannot preserve the charge (that is, data) indefinitely and must be recharged periodically. Therefore,
these cells are called dynamic storage cells. RAMs using these cells are referred to as Dynamic RAMs or simply DRAMs.

Swapping
o increase CPU utilization in multiprogramming, a memory management scheme known as swapping can be used. Swapping is the process of bringing a process
into memory and then temporarily copying it to the disc after it has run for a while. The purpose of swapping in an operating system is to access data on a hard disc
and move it to RAM so that application programs can use it. It’s important to remember that swapping is only used when data isn’t available in RAM. Although the
swapping process degrades system performance, it allows larger and multiple processes to run concurrently. Because of this, swapping is also known as memory
compaction. The CPU scheduler determines which processes are swapped in and which are swapped out. Consider a multiprogramming environment that employs
a priority-based scheduling algorithm. When a high-priority process enters the input queue, a low-priority process is swapped out so the high-priority process can
be loaded and executed. When this process terminates, the low priority process is swapped back into memory to continue its execution. Below figure shows the
swapping process in operating system:
Swapping has been subdivided into two concepts: swap-in and swap-out.
 Swap-out is a technique for moving a process from RAM to the hard disc.
 Swap-in is a method of transferring a program from a hard disc to main memory, or RAM.
Advantages
 If there is low main memory so some processes may has to wait for much long but by using swapping process do not have to wait long for execution on CPU.
 It utilize the main memory.
 Using only single main memory, multiple process can be run by CPU using swap partition.
 The concept of virtual memory start from here and it utilize it in better way.
 This concept can be useful in priority based scheduling to optimize the swapping process.
Disadvantages
 If there is low main memory resource and user is executing too many processes and suddenly the power of system goes off there might be a scenario where
data get erase of the processes which are took parts in swapping.
 Chances of number of page faults occur
 Low processing performance
Only one process occupies the user program area of memory in a single tasking operating system and remains in memory until the process is completed.
When all of the active processes in a multitasking operating system cannot coordinate in main memory, a process is swapped out of main memory so that other
processes can enter it.
Contiguous Memory Allocation
Contiguous Memory Allocation in Operating System
Allocating space to software applications is referred to as memory allocation. Memory is a sizable collection of bytes. Contiguous and non-contiguous memory allocation are the
two basic types of memory allocation. Contiguous memory allocation enables the tasks to be finished in a single memory region. Contrarily, non-contiguous memory allocation
distributes the procedure throughout many memory locations in various memory sections.

We will explore more about contiguous memory allocation in this post, as well as its advantages and disadvantages.

Contiguous Memory Allocation: What Is It?

An operating system memory allocation method is contiguous memory allocation. What, however, is memory allocation? A software or process requires memory space in order
to be run. As a result, a process must be given a specific amount of memory that corresponds to its needs. Memory allocation is the term for this procedure.

Contiguous memory allocation is one of these memory allocation strategies. We use this strategy to allocate contiguous blocks of memory to each process, as the name suggests.
Therefore, we allot a continuous segment from the entirely empty area to the process based on its size whenever a process requests to reach the main memory.

Techniques for Contiguous Memory Allocation

Depending on the needs of the process making the memory request, a single contiguous piece of memory blocks is assigned.

It is performed by creating fixed-sized memory segments and designating a single process to each partition. The amount of multiprogramming will be constrained, therefore, to
the number of memory-based fixed partitions.

Internal fragmentation results from this allocation as well. Consider the scenario where a process is given a fixed-sized memory block that is a little larger than what is needed.
Internal fragmentation is the term used to describe the leftover memory space in the block in the scenario. A partition becomes available for another process to run once a
process inside of it has completed.

In the variable partitioning scheme, the OS keeps a table that lists which memory partitions are free and which are used by processes. Contiguous memory allocation reduces
address translation overheads, expediting process execution.

According to the contiguous memory allocation technique, if a process needs to be given space in the memory, we must give it a continuous empty block of space to reside in.
There are two ways to allocate this:

o Fix-size Partitioning Method


o Flexible Partitioning Method

Let's examine both of these strategies in depth, along with their benefits and drawbacks.
Fix-size Partitioning Method

Each process in this method of contiguous memory allocation is given a fixed size continuous block in the main memory. This means that the entire memory will be partitioned
into continuous blocks of fixed size, and each time a process enters the system, it will be given one of the available blocks. Because each process receives a block of memory
space that is the same size, regardless of the size of the process. Static partitioning is another name for this approach.

Three processes in the input queue in the figure above require memory space allocation. The memory has fixed-sized chunks because we are using the fixed size partition
technique. In addition to the 4MB process, the first process, which is 3MB in size, is given a 5MB block. The second process, which is 1MB in size, is also given a 5MB block. So, it
doesn't matter how big the process is. The same fixed-size memory block is assigned to each.

It is obvious that under this system, the number of continuous blocks into which the memory will be partitioned will be determined by the amount of space each block covers,
and this, in turn, will determine how many processes can remain in the main memory at once.

The degree of multiprogramming refers to the number of processes that can run concurrently in memory. Therefore, the number of blocks formed in the RAM determines the
system's level of multiprogramming.

Advantages

A fixed-size partition system has the following benefits:


o This strategy is easy to employ because each block is the same size. Now all that is left to do is allocate processes to the fixed memory blocks that have been divided
up.
o It is simple to keep track of how many memory blocks are still available, which determines how many further processes can be allocated memory.
o This approach can be used in a system that requires multiprogramming since numerous processes can be maintained in memory at once.

Disadvantages

Although the fixed-size partitioning strategy offers numerous benefits, there are a few drawbacks as well:

o We won't be able to allocate space to a process whose size exceeds the block since the size of the blocks is fixed.
o The amount of multiprogramming is determined by block size, and only as many processes can run simultaneously in memory as there are available blocks.
o We must assign the process to this block if the block's size is more than that of the process; nevertheless, this will leave a lot of free space in the block. This open area
might have been used to facilitate another procedure.

Flexible Partitioning Method

No fixed blocks or memory partitions are created while using this style of contiguous memory allocation technique. Instead, according on its needs, each process is given a
variable-sized block. This indicates that if space is available, this amount of RAM is allocated to a new process whenever it requests it. As a result, each block's size is determined
by the needs and specifications of the process that uses it.
There are no partitions with set sizes in the aforementioned diagram. Instead, the first process is given just 3MB of RAM because it requires that much. The remaining 3 processes
are similarly given only the amount of space that is necessary for them.

This method is also known as dynamic partitioning because the blocks' sizes are flexible and determined as new processes start.

Advantages

A variable-size partitioning system has the following benefits:

o There is no internal fragmentation because the processes are given blocks of space according to their needs. Therefore, this technique does not waste RAM.
o How many processes are in the memory at once and how much space they take up will determine how many processes can be running simultaneously. As a result, it will
vary depending on the situation and be dynamic.
o Even a large process can be given space because there are no blocks with set sizes.

Disadvantages

Despite the variable-size partition scheme's many benefits, there are a few drawbacks as well:

o This method is dynamic, hence it is challenging to implement a variable-size partition scheme.


o It is challenging to maintain record of processes and available memory space.

Techniques for Contiguous Memory Allocation Input Queues

So far, we've examined two different contiguous memory allocation strategies. But what transpires when a fresh process needs to be given a location in the main memory? How
is the block or segment that it will receive chosen?

Continuous blocks of memory assigned to processes cause the main memory to always be full. A procedure, however, leaves behind an empty block termed as a hole after it is
finished. A new procedure could potentially be implemented in this area. As a result, there are processes and holes in the main memory, and each one of these holes might be
assigned to a new process that comes in.

First-Fit

This is a fairly straightforward technique where we start at the beginning and assign the first hole, which is large enough to meet the needs of the process. The first-fit technique
can also be applied so that we can pick up where we left off in our previous search for the first-fit hole.

Best-Fit

The goal of this greedy method, which allocates the smallest hole that meets the needs of the process, is to minimise any memory that would otherwise be lost due to internal
fragmentation in the event of static partitioning. Therefore, in order to select the greatest match for the procedure without wasting memory, we must first sort the holes according
to their diameters.

Worst-Fit

The Best-Fit strategy is in opposition to this one. The largest hole is chosen to be assigned to the incoming process once the holes are sorted based on size. The theory behind
this allocation is that because the process is given a sizable hole, it will have a lot of internal fragmentation left over. As a result, a hole will be left behind that can house a few
additional processes.

Contiguous Memory Allocation's advantages and disadvantages

Contiguous memory allocation has a range of benefits and drawbacks. The following are a few benefits and drawbacks:

Advantages

o The number of memory blocks remaining, which affects how many further processes can be given memory space, is easy to keep track of.
o Contiguous memory allocation has good read performance since the entire file can be read from the disc in a single process.
o The contiguous allocation works well and is easy to set up.

Disadvantages

o Fragmentation is not an issue because each new file can be written to the disk's end after the preceding one.
o In order to choose the proper hole size while creating a new file, it needs know its final size.
o The extra space in the holes would need to be compressed or used once the diskis full.

Conclusion

o When a process is brought into the main memory to be executed, contiguous memory allocation allocates contiguous blocks of memory to that process.
o There are two methods for allocating contiguous memory:
o Each process is given access to a fixed size continuous block of main memory through fixed size partitioning.
o Variable Size Partitioning: Depending on the needs of each process, space is allocated. No specific fixed-size block is present.
o There are three ways to give an entering process a hole:
o First-Fit: Assign the procedure to the first, adequate hole.
o The smallest hole that fulfils the procedure' requirements should be assigned.
o Worst-Fit: Give the entering process the hole with the biggest size among all.

Segmentation
A process is divided into Segments. The chunks that a program is divided into which are not necessarily all of the same sizes are called segments. Segmentation gives the user’s view
of the process which paging does not give. Here the user’s view is mapped to physical memory. There are types of segmentation:
1. Virtual memory segmentation – Each process is divided into a number of segments, but the segmentation is not done all at once. This segmentation may or may not take place at
run time of the program.
2. Simple segmentation – Each process is divided into a number of segments, all of which are loaded into memory at run time, though not necessarily contiguously.
There is no simple relationship between logical addresses and physical addresses in segmentation. A table stores the information about all such segments and is called Segment Table.
Segment Table – It maps two-dimensional Logical address into one-dimensional Physical address. It’s each table entry has:
 Base Address: It contains the starting physical address where the segments reside in memory.
 Segment Limit: Also known as segment offset. It specifies the length of the segment.
Translation of Two dimensional Logical Address to dimensional Physical Address.
Address generated by the CPU is divided into:
 Segment number (s): Number of bits required to represent the segment.
 Segment offset (d): Number of bits required to represent the size of the segment.
Advantages of Segmentation –
 No Internal fragmentation.
 Segment Table consumes less space in comparison to Page table in paging.
 As a complete module is loaded all at once, segmentation improves CPU utilization.
 The user’s perception of physical memory is quite similar to segmentation. Users can divide user programs into modules via segmentation. These modules are nothing more than
the separate processes’ codes.
 The user specifies the segment size, whereas in paging, the hardware determines the page size.
 Segmentation is a method that can be used to segregate data from security operations.
 Flexibility: Segmentation provides a higher degree of flexibility than paging. Segments can be of variable size, and processes can be designed to have multiple segments, allowing
for more fine-grained memory allocation.
 Sharing: Segmentation allows for sharing of memory segments between processes. This can be useful for inter-process communication or for sharing code libraries.
 Protection: Segmentation provides a level of protection between segments, preventing one process from accessing or modifying another process’s memory segment. This can help
increase the security and stability of the system.
Disadvantages of Segmentation –
 As processes are loaded and removed from the memory, the free memory space is broken into little pieces, causing External fragmentation.
 Overhead is associated with keeping a segment table for each activity.
 Due to the need for two memory accesses, one for the segment table and the other for main memory, access time to retrieve the instruction increases.
 Fragmentation: As mentioned, segmentation can lead to external fragmentation as memory becomes divided into smaller segments. This can lead to wasted memory and
decreased performance.
 Overhead: The use of a segment table can increase overhead and reduce performance. Each segment table entry requires additional memory, and accessing the table to retrieve
memory locations can increase the time needed for memory operations.
 Complexity: Segmentation can be more complex to implement and manage than paging. In particular, managing multiple segments per process can be challenging, and the
potential for segmentation faults can increase as a result.

Paging, Structure of the Page Table


The data structure that is used by the virtual memory system in the operating system of a computer in order to store the mapping between physical and logical addresses is
commonly known as Page Table.

As we had already told you that the logical address that is generated by the CPU is translated into the physical address with the help of the page table.

 Thus page table mainly provides the corresponding frame number (base address of the frame) where that page is stored in the main memory.

Some of the characteristics of the Page Table are as follows:

 It is stored in the main memory.


 Generally; the Number of entries in the page table = the Number of Pages in which the process is divided.
 PTBR means page table base register and it is basically used to hold the base address for the page table of the current process.
 Each process has its own independent page table

Some of the common techniques that are used for structuring the Page table are as follows:

1. Hierarchical Paging
2. Hashed Page Tables
3. Inverted Page Tables
. Virtual Memory: Introduction

Virtual memory is a memory management technique where secondary memory can be used as if it were a part of the main memory. Virtual memory is a common

technique used in a computer's operating system (OS).

Virtual memory uses both hardware and software to enable a computer to compensate for physical memory shortages, temporarily transferring data from random

access memory (RAM) to disk storage. Mapping chunks of memory to disk files enables a computer to treat secondary memory as though it were main memory.

Today, most personal computers (PCs) come with at least 8 GB (gigabytes) of RAM. But, sometimes, this is not enough to run several programs at one time. This is

where virtual memory comes in. Virtual memory frees up RAM by swapping data that has not been used recently over to a storage device, such as a hard drive or

solid-state drive (SSD). Virtual memory was developed at a time when physical memory -- also referenced as RAM -- was expensive. Computers have a finite amount

of RAM, so memory will eventually run out when multiple programs run at the same time. A system using virtual memory uses a section of the hard drive to emulate

RAM. With virtual memory, a system can load larger or multiple programs running at the same time, enabling each one to operate as if it has more space, without

having to purchase more RAM.

How virtual memory works

Virtual memory uses both hardware and software to operate. When an application is in use, data from that program is stored in a physical address using RAM. A

memory management unit (MMU) maps the address to RAM and automatically translates addresses. The MMU can, for example, map a logical address space to a

corresponding physical address.

Types of virtual memory

A computer's MMU manages virtual memory operations. In most computers, the MMU hardware is integrated into the central processing unit (CPU). The CPU also

generates the virtual address space. In general, virtual memory is either paged or segmented.

Paging divides memory into sections or paging files. When a computer uses up its available RAM, pages not in use are transferred to the hard drive using a swap file.

A swap file is a space set aside on the hard drive to be used as the virtual memory extension for the computer's RAM. When the swap file is needed, it is sent back to

RAM using a process called page swapping. This system ensures the computer's OS and applications do not run out of real memory. The maximum size of the page

file can be 1 ½ to four times the physical memory of the computer.


Demand Paging
Every process in the virtual memory contains lots of pages and in some cases, it might not be efficient to swap all the pages for the process at once. Because it might be
possible that the program may need only a certain page for the application to run. Let us take an example here, suppose there is a 500 MB application and it may need as little
as 100MB pages to be swapped, so in this case, there is no need to swap all pages at once.

The demand paging system is somehow similar to the paging system with swapping where processes mainly reside in the main memory(usually in the hard disk). Thus demand
paging is the process that solves the above problem only by swapping the pages on Demand. This is also known as lazy swapper( It never swaps the page into the memory
unless it is needed).

Swapper that deals with the individual pages of a process are referred to as Pager.

Demand Paging is a technique in which a page is usually brought into the main memory only when it is needed or demanded by the CPU. Initially, only those pages are loaded
that are required by the process immediately. Those pages that are never accessed are thus never loaded into the physical memory.

Figure: Transfer of a Paged Memory to the contiguous disk space.

Whenever a page is needed? make a reference to it;

 If the reference is invalid then abort it.


 If the page is Not-in-memory then bring it to memory.

Advantages of Demand Paging


The benefits of using the Demand Paging technique are as follows:

 With the help of Demand Paging, memory is utilized efficiently.


 Demand paging avoids External Fragmentation.
 Less Input/Output is needed for Demand Paging.
 This process is not constrained by the size of physical memory.
 With Demand Paging it becomes easier to share the pages.
 With this technique, portions of the process that are never called are never loaded.
 No compaction is required in demand Paging.

Disadvantages of Demand paging


Drawbacks of Demand Paging are as follows:
 There is an increase in overheads due to interrupts and page tables.
 Memory access time in demand paging is longer.

Pure Demand Paging


In some cases when initially no pages are loaded into the memory, pages in such cases are only loaded when are demanded by the process by generating page faults. It is then
referred to as Pure Demand Paging.

 In the case of pure demand paging, there is not even a single page that is loaded into the memory initially. Thus pure demand paging causes the page fault.
 When the execution of the process starts with no pages in the memory, then the operating system sets the instruction pointer to the first instruction of the process
and that is on a non-memory resident page and then in this case the process immediately faults for the page.
 After that when this page is brought into the memory then the process continues its execution, page fault is necessary until every page that it needs is in the memory.
 And at this point, it can execute with no more faults.
 This scheme is referred to as Pure Demand Paging: means never bring a page into the memory until it is required.

Copy-on-Write
The idea behind a copy-on-write is that when a parent process creates a child process then both of these processes initially will share the same pages in memory
and these shared pages will be marked as copy-on-write which means that if any of these processes will try to modify the shared pages then only a copy of these
pages will be created and the modifications will be done on the copy of pages by that process and thus not affecting the other process.
Suppose, there is a process P that creates a new process Q and then process P modifies page 3.
The below figures shows what happens before and after process P modifies page 3.

Page Replacement
Thrashing

thrashing occurs when a computer's virtual memory resources are overused, leading to a constant state of paging and page faults, inhibiting most application-level processing.
It causes the performance of the computer to degrade or collapse. The situation can continue indefinitely until the user closes some running applications or the active processes
free up additional virtual memory resources.

To know more clearly about thrashing, first, we need to know about page fault and swapping.

o Page fault: We know every program is divided into some pages. A page fault occurs when a program attempts to access data or code in its address space but is not
currently located in the system RAM.
o Swapping: Whenever a page fault happens, the operating system will try to fetch that page from secondary memory and try to swap it with one of the pages in RAM.
This process is called swapping.

Thrashing is when the page fault and swapping happens very frequently at a higher rate, and then the operating system has to spend more time swapping these pages. This
state in the operating system is known as thrashing. Because of thrashing, the CPU utilization is going to be reduced or negligible.

The basic concept involved is that if a process is allocated too few frames, then there will be too many and too frequent page faults. As a result, no valuable work would be done
by the CPU, and the CPU utilization would fall drastically.

The long-term scheduler would then try to improve the CPU utilization by loading some more processes into the memory, thereby increasing the degree of multiprogramming.
Unfortunately, this would result in a further decrease in the CPU utilization, triggering a chained reaction of higher page faults followed by an increase in the degree of
multiprogramming, called thrashing.
Memory-Mapped Files

A memory-mapped file contains the contents of a file in virtual memory. This mapping between a file and memory space enables an application, including multiple processes,
to modify the file by reading and writing directly to the memory. You can use managed code to access memory-mapped files in the same way that native Windows functions
access memory-mapped files, as described in Managing Memory-Mapped Files.

There are two types of memory-mapped files:

 Persisted memory-mapped files

Persisted files are memory-mapped files that are associated with a source file on a disk. When the last process has finished working with the file, the data is saved to the
source file on the disk. These memory-mapped files are suitable for working with extremely large source files.

 Non-persisted memory-mapped files

Non-persisted files are memory-mapped files that are not associated with a file on a disk. When the last process has finished working with the file, the data is lost and the
file is reclaimed by garbage collection. These files are suitable for creating shared memory for inter-process communications (IPC).

STORAGE MANAGEMENT:
Storage Management is defined as it refers to the management of the data storage equipment’s that are used to store the user/computer generated data. Hence
it is a tool or set of processes used by an administrator to keep your data and storage equipment’s safe. Storage management is a process for users to optimize
the use of storage devices and to protect the integrity of data for any media on which it resides and the category of storage management generally contain the
different type of subcategories covering aspects such as security, virtualization and more, as well as different types of provisioning or automation, which is
generally made up the entire storage management software market.
Storage management key attributes: Storage management has some key attribute which is generally used to manage the storage capacity of the system.
These are given below:
1. Performance
2. Reliability
3. Recoverability
4. Capacity
Feature of Storage management: There is some feature of storage management which is provided for storage capacity. These are given below:
1. Storage management is a process that is used to optimize the use of storage devices.
2. Storage management must be allocated and managed as a resource in order to truly benefit a corporation.
3. Storage management is generally a basic system component of information systems.
4. It is used to improve the performance of their data storage resources.
Advantage of storage management: There are some advantage of storage management which are given below:
 It becomes very simple to manage a storage capacity.
 It generally reduces the time consumption.
 It improves the performance of system.
 In virtualization and automation technologies, it can help an organization improve its agility.
Limitations of storage management:
 Limited physical storage capacity: Operating systems can only manage the physical storage space that is available, and as such, there is a limit to how much
data can be stored.
 Performance degradation with increased storage utilization: As more data is stored, the system’s performance can decrease due to increased disk access time,
fragmentation, and other factors.
 Complexity of storage management: Storage management can be complex, especially as the size of the storage environment grows.
 Cost: Storing large amounts of data can be expensive, and the cost of additional storage capacity can add up quickly.
 Security issues: Storing sensitive data can also present security risks, and the operating system must have robust security features in place to prevent
unauthorized access to this data.
 Backup and Recovery: Backup and recovery of data can also be challenging, especially if the data is stored on multiple systems or devices.

Disk Structure
Disk Structure In OS

Hard disk is secondary storage which stores the large amount of data. The Hard disk drive contains a dozens of disks. These disks
are also known as platters. These platters are mount over the spindle which rotates in any direction i.e. clockwise or anti-clockwise.
Lets look at hard disk structure in OS.
Platter
 The Platter is made of aluminum or iron oxide.
 Platter diameter range is 1.8 inches to 5.25 inches
 Each platter contains 2 surfaces and 2 Read/Write Head. One Read/Write head requires for one surface of the platter. So, other R/W head use
for other surface to store the information’s.
 Every platter holds the same no. of tracks.
 Multiple platters increase the storage capacity.
R/W Head
 R/W Heads moves forth and back over the platter surfaces to Read or Write the data on sectors.
 Read/Write heads does not touch to platters surface. The data written over the platter surface is done through magnetic field. If R/W Head touches
over the surface of platter then bad sectors may creates. Had disk may damage due to these bad sectors.
Tracks
 Circular areas of disk are known as tracks.
 There may be more than a 1000 tracks on a 3.5 inch hard disk and sector size. Track Numbering start with zero at outermost track.
Sectors

Tracks are further divided into number of small units; these small units are known as sectors. Sectors are the smallest physical
storage units on disk. Size of each sector is almost always 512 Bytes. Sector Numbering start with 1 at outermost tracks.
Cylinder
All Corresponding tracks with same radius of all platters in the Hard disk are known as cylinders. In simple words we say
“Each tack of all platters with same radius is called a cylinder”
So, Number of tracks in platter is always equal to number of cylinders. For example, a hard disk, where each platter contains 600
tracks then the number of cylinders will also be 600 in the hard disk.
Cylinder Numbering start with zero at outermost cylinder.
Cluster
Cluster is also known as blocks. Group of sectors makes a cluster. There may be 64 or sectors in a cluster. These clusters are used
by OS to Read/Write the data.
Disk Capacity
As we know there are number of platters in the hard disk. Each platter contains two R/W heads. There are number of cylinder/tracks
in the hard disk. Each track is divided into number of sectors. And each sector has some size but mostly size of sector is 512 Bytes.
Question 01: Let suppose there are 8 platters in hard disk drive. As each platters has two surfaces so 16 surfaces will be there in
hard drive. Therefore, required R/W head will also be 16. Suppose, there are 1,024 cylinders and 128 sectors in each track. The
sector size is 512 bytes.Then
A). Calculate Disk Size?
B). How many number of bits required to represent the disk size?
Part A. Solution
Size of Hard Disk = Cylinder x Heads X Sectors x Sector-Size
= 1,024 x 16 x 128 x 512 Bytes
= 210 + 24 + 27 + 29 Bytes = 230Bytes = 2GB
Part B. Solution
As 2GB = 230 So, 30 bits are required to represent 2GB hard disk.
Question-02: Find the size of Single platter if track size 1KB and there are 1024 cylinder?
Solution: As there is a single platter So, Heads requirement will be 2.
Size of Platter = Cylinder x Heads X track size (because, Track size = Sectors x Sector-Size)
= 210 + 21 + 210 Bytes
=21+220 Bytes = 2MB

Disk 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. Disk scheduling is
important because:
 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 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.
There are many Disk Scheduling Algorithms but before discussing them let’s have a quick look at some of the important terms:
 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 write. So the disk scheduling algorithm that
gives minimum average seek time is better.
 Rotational Latency: Rotational Latency is the time taken by the desired sector of 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 number of bytes to be transferred.
 Disk Access Time: Disk Access Time is:

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 of time spent by a request waiting to perform its I/O operation. Average Response time is the response
time of the all requests. Variance Response Time is measure of how individual request are serviced with respect to average response time. So the disk
scheduling algorithm that gives minimum variance response time is better.
Disk Scheduling Algorithms
1. FCFS: FCFS is the simplest of all the 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.
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:
 Every request gets a fair chance
 No indefinite postponement
Disadvantages:
 Does not try to optimize seek time
 May not provide the best possible service
1. SSTF: In SSTF (Shortest Seek Time First), requests having 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 system.Let us understand this with the help of
an example.
Example:
1. 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) =(50-43)+(43-24)+(24-16)+(82-16)+(140-
82)+(170-140)+(190-170) =208
Advantages:
 Average Response Time decreases
 Throughput increases
Disadvantages:
 Overhead to calculate seek time in advance
 Can cause Starvation for a request if it has a higher seek time as compared to incoming requests
 High variance of response time as SSTF favors only some requests
SCAN: In SCAN algorithm the disk arm moves in a particular direction and services the requests coming in its path and after reaching the end of the disk, it
reverses its direction and again services the request arriving in its path. So, this algorithm works as an elevator and is hence also known as an elevator
algorithm. As a result, the requests at the midrange are serviced more and those arriving behind the disk arm will have to wait.
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”.


Therefore, the total overhead movement (total distance covered by the disk arm) is calculated as:
1. =(199-50)+(199-16) =332

Advantages:
 High throughput
 Low variance of response time
 Average response time
Disadvantages:
 Long waiting time for requests for locations just visited by disk arm
1. CSCAN: In SCAN algorithm, the disk arm again scans the path that has been scanned, after reversing its direction. So, it may be possible that too many
requests are waiting at the other end or there may be zero or few requests pending at the scanned area.
These situations are avoided in CSCAN algorithm in which the disk arm instead of reversing its direction goes to the other end of the disk and starts servicing the
requests from there. So, the disk arm moves in a circular fashion and this algorithm is also similar to SCAN algorithm and hence it is known as C-SCAN (Circular
SCAN).
Example:
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”.


so, the total overhead movement (total distance covered by the disk arm) is calculated as:
=(199-50)+(199-0)+(43-0) =391 Advantages:
 Provides more uniform wait time compared to SCAN
1. LOOK: It is similar to the SCAN disk scheduling algorithm except for the difference that the disk arm in spite of going to the end of the disk goes only to the last
request to be serviced in front of the head and then reverses its direction from there only. Thus it 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”.

So, the total overhead movement (total distance covered by the disk arm) is calculated as:
1. =(190-50)+(190-16) =314

2. CLOOK: As LOOK is similar to SCAN algorithm, in similar way, CLOOK is similar to 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”

So, the total overhead movement (total distance covered by the disk arm) is calculated as:
1. =(190-50)+(190-16)+(43-16) =341
2. RSS– It stands for random scheduling and just like its name it is nature. It is used in situations where scheduling involves random attributes such as random
processing time, random due dates, random weights, and stochastic machine breakdowns this algorithm sits perfectly. Which is why it is usually used for
analysis and simulation.
3. LIFO– In LIFO (Last In, First Out) algorithm, the newest jobs are serviced before the existing ones i.e. in order of requests that get serviced the job that is
newest or last entered is serviced first, and then the rest in the same order.
Advantages
 Maximizes locality and resource utilization
 Can seem a little unfair to other requests and if new requests keep coming in, it cause starvation to the old and existing ones.
1. N-STEP SCAN – It is also known as the N-STEP LOOK algorithm. In this, a buffer is created for N requests. All requests belonging to a buffer will be serviced
in one go. Also once the buffer is full no new requests are kept in this buffer and are sent to another one. Now, when these N requests are serviced, the time
comes for another top N request and this way all get requests to get a guaranteed service
Advantages
 It eliminates the starvation of requests completely
1. FSCAN– This algorithm uses two sub-queues. During the scan all requests in the first queue are serviced and the new incoming requests are added to the
second queue. All new requests are kept on halt until the existing requests in the first queue are serviced.
Advantages
 FSCAN along with N-Step-SCAN prevents “arm stickiness” (phenomena in I/O scheduling where the scheduling algorithm continues to service requests at or
near the current sector and thus prevents any seeking)
Each algorithm is unique in its own way. Overall Performance depends on the number and type of requests.

Disk Management
Disk management of the operating system includes:
 Disk Format
 Booting from disk
 Bad block recovery
The low-level format or physical format:

Divides the disk into sectors before storing data so that the disk controller can read and write Each sector can be:
The header retains information, data, and error correction code (ECC) sectors of data, typically 512 bytes of data, but optional disks use the operating system’s own
data structures to preserve files using disks.
It is conducted in two stages:
1. Divide the disc into multiple cylinder groups. Each is treated as a logical disk.
2. Logical format or “Create File System”. The OS stores the data structure of the first file system on the disk. Contains free space and allocated space.
Operating system keeps its own data structures on disk before it use disk to store the files. It performs this with following two steps:
1. It partitions the disk into one or more groups of cylinders. Each partition is treated by OS as a separate disk.
2. Logical formatting: That means creation of file system.
In order to increase the efficiency, file system groups blocks in chunks called as clusters.
Some operating systems give special programs the ability to use a disk partition as a large sequential array of logical blocks, without any file-system data
structures. This array is sometimes called the raw disk, and I/O to this array is called as raw I/O.

Boot block:

 When the computer is turned on or restarted, the program stored in the initial bootstrap ROM finds the location of the OS kernel from the disk, loads the kernel
into memory, and runs the OS. start.
 To change the bootstrap code, you need to change the ROM and hardware chip. Only a small bootstrap loader program is stored in ROM instead.
 The full bootstrap code is stored in the “boot block” of the disk.

Swap-Space Management
Swapping is a memory management technique used in multi-programming to increase the number of processes sharing the CPU. It is a technique of removing a
process from the main memory and storing it into secondary memory, and then bringing it back into the main memory for continued execution. This action of
moving a process out from main memory to secondary memory is called Swap Out and the action of moving a process out from secondary memory to main
memory is called Swap In.
Swap-space management is a technique used by operating systems to optimize memory usage and improve system performance. Here are some advantages
and disadvantages of swap-space management:

Advantages:

1. Increased memory capacity: Swap-space management allows the operating system to use hard disk space as virtual memory, effectively increasing the
available memory capacity.
2. Improved system performance: By using virtual memory, the operating system can swap out less frequently used data from physical memory to disk, freeing up
space for more frequently used data and improving system performance.
3. Flexibility: Swap-space management allows the operating system to dynamically allocate and deallocate memory as needed, depending on the demands of
running applications.

Disadvantages:

Slower access times: Accessing data from disk is slower than accessing data from physical memory, which can result in slower system performance if too much
swapping is required.
Increased disk usage: Swap-space management requires disk space to be reserved for use as virtual memory, which can reduce the amount of available space
for other data storage purposes.
Risk of data loss: In some cases, if there is a problem with the swap file, such as a disk error or corruption, data may be lost or corrupted.
Overall, swap-space management is a useful technique for optimizing memory usage and im

RAID Structure
RAID stands for redundant array of independent disks. The name indicates that the disk drives are independent, and are multiple in number. How the data is distributed between these drives
depends on the RAID level used.
The main advantage of RAID, is the fact that, to the operating system the array of disks can be presented as a single disk.
RAID is fault tolerant because in most of the RAID level's data is redundant in multiple disks, so even if one disk fails,or even two sometimes, the data will be safe and the operating system will
not be even aware of the failure. DATA loss is prevented due to the fact that data can be recovered from the disk that are not failed.

File-System Interface
file system is the most obvious aspect of any operating system. This provides users the method for storage and access to data as well as programs of the operating system
where all the users of the computer system can use it.

The file system consists of 2 distinct parts:

 a collection of files, that store related data, and


 a directory structure, which organizes and provides information about all the files in the system.

In this chapter, you will learn about the different file tribute, concepts of file and its storage along with operations on files.

File Attributes
A file is named, for the ease of its users and is referred by its name. A name is usually a string of characters like filename.cpp, along with an extension which designates the file
format. Some systems (like Linux) distinguish between uppercase and lowercase characters in names, whereas other systems don't. When a file is given a name, it becomes
independent of the process, the user and also the system which created it. Let's suppose, one user might make the file filename.cpp, and another user might be editing that file
by deducing its name. The file's owner may write the file to a compact disk (CD) or send it via an e-mail or copy it across a network, and it could still be called filename.cpp on
the destination system.

Fundamental Components of A File


A file's attributes vary from one operating
A file's attributes vary from one operating system to another but typically consist of these:

 Name: Name is the symbolic file name and is the only information kept in human readable form.
 Identifier: This unique tag is a number that identifies the file within the file system; it is in non-human-readable form of the file.
 Type: This information is needed for systems which support different types of files or its format.
 Location: This information is a pointer to a device which points to the location of the file on the device where it is stored.
 Size: The current size of the file (which is in bytes, words, etc.) which possibly the maximum allowed size gets included in this attribute.
 Protection: Access-control information establishes who can do the reading, writing, executing, etc.
 Date, Time & user identification: This information might be kept for the creation of the file, its last modification and last used. These data might be useful for in
the field of protection, security, and monitoring its usage.

FILE OPERATTIONS
A file is an abstract data type. For defining a file properly, we need to consider the operations that can be performed on files. The operating system can provide system calls to
create, write, read, reposition, delete, and truncate files. There are six basic file operations within an Operating system. These are:

 Creating a file: There are two steps necessary for creating a file. First, space in the file system must be found for the file. We discuss how to allocate space for the file.
Second, an entry for the new file must be made in the directory.
 Writing a file: To write to a file, you make a system call specify about both the name of the file along with the information to be written to the file.
 Reading a file: To read from a file, you use a system call which specifies the name of the file and where within memory the next block of the file should be placed.
 Repositioning inside a file: The directory is then searched for the suitable entry, and the 'current-file-position' pointer is relocating to a given value. Relocating within a
file need not require any actual I/O. This file operation is also termed as 'file seek.'
 Deleting a file: For deleting a file, you have to search the directory for the specific file. Deleting that file or directory release all file space so that other files can re-use
that space.
 Truncating a file: The user may wish for erasing the contents of a file but keep the attributes same. Rather than deleting the file and then recreate it, this utility allows
all attributes to remain unchanged — except the file length — and let the user add or edit the file content.

Access Methods
There are three ways to access a file into a computer system: Sequential-Access, Direct Access, Index sequential Method.
1. Sequential Access –
It is the simplest access method. Information in the file is processed in order, one record after the other. This mode of access is by far the most common; for
example, editor and compiler usually access the file in this fashion.
Read and write make up the bulk of the operation on a file. A read operation -read next- read the next position of the file and automatically advance a file
pointer, which keeps track I/O location. Similarly, for the -write next- append to the end of the file and advance to the newly written material.
Key points:
 Data is accessed one record right after another record in an order.
 When we use read command, it move ahead pointer by one
 When we use write command, it will allocate memory and move the pointer to the end of the file
 Such a method is reasonable for tape.

Advantages of Sequential Access Method :


 It is simple to implement this file access mechanism.
 It uses lexicographic order to quickly access the next entry.
 It is suitable for applications that require access to all records in a file, in a specific order.
 It is less prone to data corruption as the data is written sequentially and not randomly.
 It is a more efficient method for reading large files, as it only reads the required data and does not waste time reading unnecessary data.
 It is a reliable method for backup and restore operations, as the data is stored sequentially and can be easily restored if required.
Disadvantages of Sequential Access Method :
 If the file record that needs to be accessed next is not present next to the current record, this type of file access method is slow.
 Moving a sizable chunk of the file may be necessary to insert a new record.
 It does not allow for quick access to specific records in the file. The entire file must be searched sequentially to find a specific record, which can be time-
consuming.
 It is not well-suited for applications that require frequent updates or modifications to the file. Updating or inserting a record in the middle of a large file can be a
slow and cumbersome process.
 Sequential access can also result in wasted storage space if records are of varying lengths. The space between records cannot be used by other records,
which can result in inefficient use of storage.
2.Direct Access –
Another method is direct access method also known as relative access method. A fixed-length logical record that allows the program to read and write record
rapidly. in no particular order. The direct access is based on the disk model of a file since disk allows random access to any file block. For direct access, the file is
viewed as a numbered sequence of block or record. Thus, we may read block 14 then block 59, and then we can write block 17. There is no restriction on the
order of reading and writing for a direct access file.
A block number provided by the user to the operating system is normally a relative block number, the first relative block of the file is 0 and then 1 and so on.

Advantages of Direct Access Method :


 The files can be immediately accessed decreasing the average access time.
 In the direct access method, in order to access a block, there is no need of traversing all the blocks present before it.
3.Index sequential method –
It is the other method of accessing a file that is built on the top of the sequential access method. These methods construct an index for the file. The index, like an
index in the back of a book, contains the pointer to the various blocks. To find a record in the file, we first search the index, and then by the help of pointer we
access the file directly.
Key points:
 It is built on top of Sequential access.
 It control the pointer by using index.

4.Relative Record Access –


Relative record access is a file access method used in operating systems where records are accessed relative to the current position of the file pointer. In this
method, records are located based on their position relative to the current record, rather than by a specific address or key value.
Key Points of Relative Record Access:
Relative record access is a random access method that allows records to be accessed based on their position relative to the current record.
This method is efficient for accessing individual records but may not be suitable for files that require frequent updates or random access to specific records.
Relative record access requires fixed-length records and may not be flexible enough for some applications.
This method is useful for processing records in a specific order or for files that are accessed sequentially.
Advantages of Relative Record Access:
Random Access: Relative record access allows random access to records in a file. The system can access any record at a specific offset from the current position
of the file pointer.
Efficient Retrieval: Since the system only needs to read the current record and any records that need to be skipped, relative record access is more efficient than
sequential access for accessing individual records.

Directory Structure
A directory is a container that is used to contain folders and files. It organizes files and folders in a hierarchical manner.
There are several logical structures of a directory, these are given below.
 Single-level directory –
The single-level directory is the simplest directory structure. In it, all files are contained in the same directory which makes it easy to support and understand.
A single level directory has a significant limitation, however, when the number of files increases or when the system has more than one user. Since all the files are in the same
directory, they must have a unique name. if two users call their dataset test, then the unique name rule violated.

Advantages:
 Since it is a single directory, so its implementation is very easy.
 If the files are smaller in size, searching will become faster.
 The operations like file creation, searching, deletion, updating are very easy in such a directory structure.
 Logical Organization: Directory structures help to logically organize files and directories in a hierarchical structure. This provides an easy way to navigate and manage files,
making it easier for users to access the data they need.
 Increased Efficiency: Directory structures can increase the efficiency of the file system by reducing the time required to search for files. This is because directory structures are
optimized for fast file access, allowing users to quickly locate the file they need.
 Improved Security: Directory structures can provide better security for files by allowing access to be restricted at the directory level. This helps to prevent unauthorized access to
sensitive data and ensures that important files are protected.
 Facilitates Backup and Recovery: Directory structures make it easier to backup and recover files in the event of a system failure or data loss. By storing related files in the same
directory, it is easier to locate and backup all the files that need to be protected.
 Scalability: Directory structures are scalable, making it easy to add new directories and files as needed. This helps to accommodate growth in the system and makes it easier to
manage large amounts of data.
Disadvantages:
 There may chance of name collision because two files can have the same name.
 Searching will become time taking if the directory is large.
 This can not group the same type of files together.
 Two-level directory –
As we have seen, a single level directory often leads to confusion of files names among different users. the solution to this problem is to create a separate directory for each user.
In the two-level directory structure, each user has their own user files directory (UFD). The UFDs have similar structures, but each lists only the files of a single user.

File-System Mounting

Operating system organises files on a disk using filesystem. And these filesystems differ with operating systems. We have greater number of
filesystems available for linux. One of the great benefits of linux is that we can access data on many different file systems even if these filesystems
are from different operating system. In order to access the file system in the linux first we need to mount it. Mounting refers to making a group of
files in a file system structure accessible to user or group of users. It is done by attaching a root directory from one file system to that of another.
This ensures that the other directory or device appears as a directory or subdirectory of that system.

Mounting may be local or remote. In local mounting it connects disk drivers as one machine such that they behave as single logical system, while
remote mount uses NFS(Network file system) to connect to directories on other machine so that they can be used as if they are the part of the
users file system. Opposite of mounting is unmounting [commands for the same will be discussed later] and it is removal of access of those
files/folders. It was the overview of what a mounting is.

In unix based system there is a single directory tree, and all the accessible storage must have an associated location in a single directory tree. And
for making the storage accessible mounting is used.

File Sharing, Protection


File sharing is the practice of distributing or providing access to digital files between two or more users or devices. While it is a convenient way to share information and collaborate
on projects, it also comes with risks such as malware and viruses, data breaches, legal consequences, and identity theft. Protecting files during sharing is essential to ensure
confidentiality, integrity, and availability. Encryption, password protection, secure file transfer protocols, and regularly updating antivirus and anti-malware software are all
important measures that can be taken to safeguard files. This article will explore the different types of file sharing, risks associated with file sharing, protection measures, and
best practices for secure file sharing.
Definition of file sharing
File sharing refers to the process of sharing or distributing electronic files such as documents, music, videos, images, and software between two or more users or computers.
Importance of file sharing
File sharing plays a vital role in facilitating collaboration and communication among individuals and organizations. It allows people to share files quickly and easily across different
locations, reducing the need for physical meetings and enabling remote work. File sharing also helps individuals and organizations save time and money, as it eliminates the
need for physical transportation of files.
Risks and challenges of file sharing
File sharing can pose several risks and challenges, including the spread of malware and viruses, data breaches and leaks, legal consequences, and identity theft. Unauthorized
access to sensitive files can also result in loss of intellectual property, financial losses, and reputational damage.
The need for file protection
With the increase in cyber threats and the sensitive nature of the files being shared, it is essential to implement adequate file protection measures to secure the files from
unauthorized access, theft, and cyberattacks. Effective file protection measures can help prevent data breaches and other cyber incidents, safeguard intellectual property, and
maintain business continuity.
Types of File Sharing
File sharing refers to the practice of distributing or providing access to digital files, such as documents, images, audio, and video files, between two or more users or devices.
There are several types of file sharing methods available, and each method has its own unique advantages and disadvantages.
 Peer-to-Peer (P2P) File Sharing − Peer-to-peer file sharing allows users to share files with each other without the need for a centralized server. Instead, users connect
to each other directly and exchange files through a network of peers. P2P file sharing is commonly used for sharing large files such as movies, music, and software.
 Cloud-Based File Sharing − Cloud-based file sharing involves the storage of files in a remote server, which can be accessed from any device with an internet connection.
Users can upload and download files from cloud-based file sharing services such as Google Drive, Dropbox, and OneDrive. Cloud-based file sharing allows users to easily
share files with others, collaborate on documents, and access files from anywhere.
 Direct File Transfer − Direct file transfer involves the transfer of files between two devices through a direct connection such as Bluetooth or Wi-Fi Direct. Direct file transfer
is commonly used for sharing files between mobile devices or laptops.
 Removable Media File Sharing − Removable media file sharing involves the use of physical storage devices such as USB drives or external hard drives. Users can copy
files onto the device and share them with others by physically passing the device to them.
Each type of file sharing method comes with its own set of risks and challenges. Peer-to-peer file sharing can expose users to malware and viruses, while cloud-based file
sharing can lead to data breaches if security measures are not implemented properly. Direct file transfer and removable media file sharing can also lead to data breaches if
devices are lost or stolen.
To protect against these risks, users should take precautions such as using encryption, password protection, secure file transfer protocols, and regularly updating antivirus and
antimalware software. It is also essential to educate users on safe file sharing practices and limit access to files only to authorized individuals or groups. By taking these steps,
users can ensure that their files remain secure and protected during file sharing.

Risks of File Sharing

File sharing is a convenient and efficient way to share information and collaborate on projects. However, it comes with several risks and challenges that can compromise the
confidentiality, integrity, and availability of files. In this section, we will explore some of the most significant risks of file sharing.
 Malware and Viruses − One of the most significant risks of file sharing is the spread of malware and viruses. Files obtained from untrusted sources, such as peer-to-peer
(P2P) networks, can contain malware that can infect the user's device and compromise the security of their files. Malware and viruses can cause damage to the user's
device, steal personal information, or even use their device for illegal activities without their knowledge.
 Data Breaches and Leaks − Another significant risk of file sharing is the possibility of data breaches and leaks. Cloud-based file sharing services and P2P networks are
particularly vulnerable to data breaches if security measures are not implemented properly. Data breaches can result in the loss of sensitive information, such as personal
data or intellectual property, which can have severe consequences for both individuals and organizations.
 Legal Consequences − File sharing copyrighted material without permission can lead to legal consequences. Sharing copyrighted music, movies, or software can result
in copyright infringement lawsuits and hefty fines.
 Identity Theft − File sharing can also expose users to identity theft. Personal information, such as login credentials or social security numbers, can be inadvertently shared
through file sharing if security measures are not implemented properly. Cybercriminals can use this information to commit identity theft, which can have severe
consequences for the victim.
To protect against these risks, users should take precautions such as using trusted sources for file sharing, limiting access to files, educating users on safe file sharing practices,
and regularly updating antivirus and anti-malware software. By taking these steps, users can reduce the risk of malware and viruses, data breaches and leaks, legal
consequences, and identity theft during file sharing.

File Sharing Protection Measures

 Encryption − Encryption is the process of converting data into a coded language that can only be accessed by authorized users with a decryption key. This can help
protect files from unauthorized access and ensure that data remains confidential even if it is intercepted during file sharing.
 Password protection − Password protection involves securing files with a password that must be entered before the file can be accessed. This can help prevent
unauthorized access to files and ensure that only authorized users can view or modify the files.
 Secure file transfer protocols − Secure file transfer protocols, such as SFTP (Secure File Transfer Protocol) and HTTPS (Hypertext Transfer Protocol Secure), provide
a secure way to transfer files over the internet. These protocols use encryption and other security measures to protect files from interception and unauthorized access
during transfer.
 Firewall protection − Firewall protection involves using a firewall to monitor and control network traffic to prevent unauthorized access to the user's device or network.
Firewalls can also be configured to block specific file sharing protocols or limit access to certain users or devices, providing an additional layer of protection for shared files.

Best Practices for Secure File Sharing

 Use trusted sources for file sharing − To reduce the risk of downloading malware or viruses, it is essential to use trusted sources for file sharing. Users should only
download files from reputable sources and avoid downloading files from unknown or suspicious websites.
 Limit access to files − To minimize the risk of data breaches or leaks, users should limit access to files only to authorized individuals or groups. This can be done by
using password protection, encryption, and other access control measures.
 Educate users on safe file sharing practices − Educating users on safe file sharing practices can help reduce the risk of security incidents. Users should be trained on
how to identify and avoid phishing scams, how to recognize suspicious files or emails, and how to securely share files.
 Regularly update antivirus and anti-malware software − To ensure maximum protection against malware and viruses, it is essential to regularly update antivirus and
anti-malware software. This will help to identify and remove any potential threats to the user's device or network.

You might also like