Unit 4-3
Unit 4-3
VIRTUAL MEMORY
What is Virtual Memory in OS (Operating System)?
Virtual memory in an operating system is a memory
management technique that creates an illusion of a large block
of contiguous memory for users. It uses both physical
memory (RAM) and disk storage to provide a larger virtual
memory space, allowing systems to run larger applications and
handle more processes simultaneously. This helps
improve system performance and multitasking efficiency.
File system
What is a file system?
A file system is a method an operating system uses
to store, organize, and manage files and directories
on a storage device. Some common types of file
systems include:
FAT (File Allocation Table): An older file
system used by older versions of Windows and
other operating systems.
NTFS (New Technology File System): A
modern file system used by Windows. It
supports features such as file and folder
permissions, compression, and encryption.
ext (Extended File System): A file system
commonly used on Linux and Unix-based
operating systems.
HFS (Hierarchical File System): A file system
used by macOS.
APFS (Apple File System): A new file system
introduced by Apple for their Macs and iOS
devices.
A file is a collection of related information that is
recorded on secondary storage. Or file is a
collection of logically related entities. From the
user’s perspective, a file is the smallest allotment of
logical secondary storage.
The name of the file is divided into two parts as
shown below:
Name
Extension, separated by a period.
File Attributes
File attributes are configuration and information
related to files. These attributes grant/deny requests
of a user/process for access, modifying, relocating,
or deleting it.
Name- This is the only information stored in a
human-readable format. A name is given to
each file. One directory cannot contain two files
with the same name.
Extension- This attribute is required for
systems that support different file types. For
example, a text file has a .txt extension and a
video file has a .mp4 extension.
Location- Refers to the location of the file on
the device. The file system has several places
where you can save your files. Each file
contains its location as an attribute.
Size-File- size means the number of bytes
captured by the file in memory.
Identifier- Each file is identified by a unique
tag number within the file system called an
identifier.
Protection- This attribute assigns and controls
access to read, write, and execute files.
Computer administrators may need different
protection for each file. Therefore, each file has
its own permissions on different user groups.
Compression- It tells the type of compression
there is.
Created/Modified date- Each file has a
timestamp that includes the date and time the
file was last modified.
File Operations
Creating- Creating a file involves two steps. First,
check if there is free space. You must create a new
directory file entry if you have enough space.
Opening- This is a common operation performed
on a file. After you create a file, you need to open it
before you can perform any file processing
operations. If the user wants to open the file, call a
system call to instruct the operating system to open
the file and pass the file name to the file
Writing- To write a file, you need to know two
things. One is the name of the file and the other is
the information or data written to the file
Deleting- To delete a file, first browse the directory
of the named file, then free up the file area and
delete the directory entry.
Truncating- To truncate a file, delete only the
contents of the file, but don’t delete its file structure.
Close File- After editing the file, you need to close
the file to free up any permanent changes made and
occupied resources. Finally, the internal descriptor
created when the file was opened is released.
File Types
File Structure
A file is a logical unit of information. They are produced by
processes. The operating system manages files. While creating
a file, a name is assigned to it. After this process has
terminated, the file exists and remains accessible to other
processes. The name of a file has two parts, separated by a dot.
Example, code.cpp is a c++ program file with name code and
extension cpp. The name of the file before the dot is a label for
the file's identification, while the part after the dot is called the
file extension which indicates the type of the file.
File Access Methods
There are three ways to access a file in a computer system:
Sequential-Access
Direct Access
Index sequential Method
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, the 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- reads the next position of the file
and automatically advances a file pointer, which keeps track of
the I/O location. Similarly, for the -write next- append to the
end of the file and advance to the newly written material.
Advantages
Implementation is very simple.
If the sizes of the files are very small then the searching
becomes faster.
File creation, searching, deletion is very simple since we
have only one directory.
Disadvantages
We cannot have two files with the same name.
The directory may be very big therefore searching for a
file may take so much time.
Protection cannot be implemented for multiple users.
There are no ways to group same kind of files.
Choosing the unique name for every file is a bit complex
and limits the number of files in the system because most
of the Operating System limits the number of characters
used to construct the file name.
2. Two – Level Directory
In two level directory systems, we can create a separate
directory for each user. There is one master directory which
contains separate directories dedicated to each user. For each
user, there is a different directory present at the second level,
containing group of user's file. The system doesn't let a user to
enter in the other user's directory without permission.
Advantages
The main advantage is there can be more than two files with
same name, and would be very helpful if there are multiple
users.
A security would be there which would prevent user to access
other user’s files.
Searching of the files becomes very easy in this directory
structure.
Disadvantage:
• Users cannot create their own sub-directories.
Advantages:
Contiguous Allocation
Linked Allocation
Indexed Allocation
The main idea behind these methods is to provide:
Efficient disk space utilization.
Fast access to the file blocks.
All the three methods have their own advantages and
disadvantages as discussed below:
1. Contiguous Allocation
In this scheme, each file occupies a contiguous set of blocks on
the disk. For example, if a file requires n blocks and is given a
block b as the starting location, then the blocks assigned to the
file will be: b, b+1, b+2,……b+n-1. This means that given the
starting block address and the length of the file (in terms of
blocks required), we can determine the blocks occupied by the
file.
The directory entry for a file with contiguous allocation
contains
Address of starting block
Length of the allocated portion.
The file ‘mail’ in the following figure starts from the block 19
with length = 6 blocks. Therefore, it occupies 19, 20, 21, 22, 23,
24 blocks.
Advantages:
Both the Sequential and Direct Accesses are supported by this.
For direct access, the address of the kth block of the file which
starts at block b can easily be obtained as (b+k).
This is extremely fast since the number of seeks are minimal
because of contiguous allocation of file blocks.
Disadvantages:
This method suffers from both internal and external
fragmentation. This makes it inefficient in terms of memory
utilization.
Increasing file size is difficult because it depends on the
availability of contiguous memory at a particular instance.
2. Linked List Allocation
In this scheme, each file is a linked list of disk blocks which
need not be contiguous. The disk blocks can be scattered
anywhere on the disk.
The directory entry contains a pointer to the starting and the
ending file block. Each block contains a pointer to the next
block occupied by the file.
The file ‘jeep’ in following image shows how the blocks are
randomly distributed. The last block (25) contains -1 indicating
a null pointer and does not point to any other block.
Advantages:
Advantages:
This supports direct access to the blocks occupied by the file
and therefore provides fast access to the file blocks.
It overcomes the problem of external fragmentation.
Disadvantages:
The pointer overhead for indexed allocation is greater than
linked allocation.
For very small files, say files that expand only 2-3 blocks, the
indexed allocation would keep one entire block (index block)
for the pointers which is inefficient in terms of memory
utilization. However, in linked allocation we lose the space of
only 1 pointer per block.
File system structure