Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

O P E R AT I N G S Y S T E M

File Management & Memory


Management
B Y: Aniruddha Halder
Wo m e n ’s P o l y t e c h n i c , C h a n d a n n a g a r

Courtesy: https://www.tutorialspoint.com/operating_system/
https://www.geeksforgeeks.org/
https://www.javatpoint.com/
File Management
Define File: A file is a named collection of related information that is recorded on secondary
storage such as magnetic disks, magnetic tapes and optical disks. In general, a file is a
sequence of bits, bytes, lines or records whose meaning is defined by the files creator and
user.
Attributes of the File:
• Name • Identifier • Type • Location • Size
Every
Alongfile carries
with thea name
Inname,byEach
a File whichFilethehas
System, Filesitsareown
classified The Size of the File is one of its most
In the File System, there are several
the extension
file is recognized in thethefile
which identifies
in different types
type ofsuch
the as
file.video
For important attribute. By size of the file,
locations on files,
which, the files can be
system.
example,One adirectory
text file cannot
audio the have
has files,extension .txt, A
text files,stored.
executable
video files, we mean the number of bytes acquired
Each file carries its location as its
two file
filescan
with thethe
have same name.
extension .mp4,
etc. etc attribute. by the file in the memory.

• Protection • Time and Date


The Admin of the computer mayEvery want file
the carries a time stamp which contains the
different protections for the different
time and
files.date on which the file is last modified.
Therefore each file carries its own set of
permissions to the different group of Users.
File Management
Operations on the File: A file is a collection of logically related data that is recorded on the
secondary storage in the form of sequence of operations. The content of the files are defined by its creator who is
creating the file. The various operations which can be implemented on a file such as read, write, open and close
etc. are called file operations. These operations are performed by the user by using the commands provided by
the operating system.
• Re-position or Seek
• Create • Open  • Write • Read operation:
This
The operation
seek system is used
call to
re-positions This
create a file operation
theinfile
thepointers reads
fromthe
file system. iscontents
Itthe the mostfrom
current a file.
widely
position used
to aAspecific
Read pointer
operation is
performed
place on the
in the file i.e.
file
Thissystem.
forward
This To create
operation is
is the
or backward
operation atonew
usedcommon
dependingfile
write ofmaintained
upon
the a particular
operation byinto
theperformed
user's
information theon
type aOS,
the
requirement.
file. pointing
file. Onceto
theassociated
This
A system thefile
the
operation
call position
application up toitthat
program
isiscreated,
write isgenerally
issued which
calls
must bethe
the
performed file
opened
specifies system.
with
the before
those
name
This
file
of file
performingsystem
management
the file the allocates
and file
systems
the length space
processing
that to data
the
support
of the has
datafile.
operations. been
hasAs
directWhenberead.
the file
toaccess thesystem
usertowants
files.
written knowstothe
the file.openformat ofthe
a file,
Whenever itdirectory
provides structure,
a file
file length is nameso entry of
to open
increased by
this
thenew
specified file
particular is made
value file into
andinthe the
thefile appropriate
filepointer directory.
system.is Itrepositioned
tells the operating
after thesystem to written..
last byte invoke the open system call and passes the
file name to the file system.
• Delete • Truncate • Close
Deleting
When
Truncatingthethe isfile will deleting
processing
simply not only
of the delete
file is file
the all the data
complete,
except storedattributes.
itdeleting
should beinside theThe
closed sofile it all
that
fileisisalso
the used so that
not changes made
completely disk space
permanent
deleted occupied
and the
although all
by
the itresources
is freed.stored
information In order
occupied to delete
should
inside the bethe
file specified
released.
gets Onfile
replaced. the directory
closing is searched.
it deallocates When the
all the internal directorythat
descriptors entry is located,
were created
all
whenthetheassociated
file was file space and the directory entry is released.
opened.

• Append • Rename
File Management
File Structure: A File Structure should be according to a required format that the operating
system can understand.
• A file has a certain defined structure according to its type.
• A text file is a sequence of characters organized into lines.
• A source file is a sequence of procedures and functions.
• An object file is a sequence of bytes organized into blocks that are understandable by the
machine.
• When operating system defines different file structures, it also contains the code to support
these file structure. Unix, MS-DOS support minimum number of file structure.

File Type: File type refers to the ability of the operating system to distinguish different types
of file such as text files source files and binary files etc. Many operating systems support
many types of files.
Ordinary files:
Directory files: ••• These
Thesearefiles contain
the files list of
that contain userfile namesfiles.
information. and other information related to
Device files: These
• These files
may are also known as Special
have text, databases or executable program.
these files.
• These files represent physical device like disks, terminals, printers,
• The user can apply various operations on such files like add, modify, delete or even
networks,
remove tapefile.
the entire drive etc.
File Management
File Access Mechanisms
File access mechanism refers to the manner in which the records of a file may be accessed.
Direct/Random access Indexed sequential access
Sequential access • Random access file • This mechanism is built up on
A sequential access is that organization provides, base of sequential access.
in which the records are accessing the records directly.
accessed in some • Each record has its own • An index is created for each file
sequence, i.e., the address on the file with by the which contains pointers to various
information in the file is help of which it can be directly blocks.
processed in order, one accessed for reading or
record after the other. This writing. • Index is searched sequentially and
access method is the most • The records need not be in any its pointer is used to access the file
primitive one. Example: sequence within the file and directly.
Compilers usually access they need not be in adjacent
files in this fashion. locations on the storage
medium.
File Management
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.

 H/T : An 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. How much time will be required for transferring in and
out ?
File Management
Space Allocation Methods
Files are allocated disk spaces by operating system. Operating systems deploy following three
main ways to allocate disk space to files.
Contiguous Allocation Linked Allocation Indexed Allocation
• Each file occupies a • Each file carries a list of • Provides solutions to problems
contiguous address space links to disk blocks. of contiguous and linked
on disk. • Directory contains link / allocation.
• Assigned disk address is in pointer to first block of a • A index block is created having
linear order. file. all pointers to files.
• Easy to implement. • No external fragmentation. • Each file has its own index block
• External fragmentation is a • Effectively used in which stores the addresses of
major issue with this type sequential access file. disk space occupied by the file.
of allocation technique. • Inefficient in case of direct • Directory contains the addresses
access file. of index blocks of files.
File Management
Structures of Directory in Operating System
A directory is a container that is used to contain folders and files. It organizes files and folders in a
hierarchical manner. 
Single-level directory Two-level directory Tree-structured directory
The single-level directory is the • In the two-level directory structure, • A tree structure is the most common
simplest directory structure. In it, all each user has their own user files
directory structure. The tree has a root
files are contained in the same directory (UFD). The UFDs have
directory, and every file in the system
directory which makes it easy to similar structures, but each lists
has a unique path.
support and understand.  only the files of a single user.
A single level directory has a system’s master file directory
significant limitation, however, (MFD) is searches whenever a new
when the number of files increases user id’s logged in. The MFD is
or when the system has more than indexed by username or account
one user. Since all the files are in the number, and each entry points to
same directory, they must have a the UFD for that user.
unique name. if two users call their
dataset test, then the unique name
rule violated.

H/T: Comparative study between the three


Directory Structure.
Contiguous
Basic Memory Management
Memory partitioning
Memory partitioning is the process by which memory is divided up into sections for use by the resident
programs. Memory Management Techniques are basic techniques that are used in managing the memory in operating
system. Memory Management Techniques are basically classified into two categories:
Contiguous Non Contiguous
In the fixed partition scheme, memory is divided In the variable partition scheme, initially memory will
into fixed number of partitions. Fixed means be single continuous free block. Whenever the request
number of partitions are fixed in the memory. In by the process arrives, accordingly partition will be
made in the memory. If the smaller processes keep on
the fixed partition, in every partition only one
coming then the larger partitions will be made into
process will be accommodated. Degree of multi- smaller partitions.
programming is restricted by number of partitions
in the memory. Maximum size of the process is
restricted by maximum size of the partition. Every
partition is associated with the limit registers.

Moving all the processes toward the top or towards the bottom to make free available memory in a single
continuous place is called as compaction. Compaction is undesirable to implement because it interrupts all the
running processes in the memory.
Basic Memory Management
Physical / Logical Addressing in Operating System
Logical Address is generated by CPU while a program is running. The logical address is virtual address as it
does not exist physically, therefore, it is also known as Virtual Address. This address is used as a reference to
access the physical memory location by CPU. The term Logical Address Space is used for the set of all logical
addresses generated by a program’s perspective. 

The hardware device called Memory-Management Unit (MMU) is used for


mapping logical address to its corresponding physical address. 

Physical Address identifies a physical location of required data in a


memory. The user never directly deals with the physical address but
can access by its corresponding logical address.

The user program generates the logical address and thinks that the program is running in this logical address but
the program needs physical memory for its execution, therefore, the logical address must be mapped to the
physical address by MMU before they are used. The term Physical Address Space is used for all physical
addresses corresponding to the logical addresses in a Logical address space. 
H/T : Distinguish between Physical and logical Addressing. 
Basic Memory Management
PAGING in Operating System
Paging is a computer memory management function that presents storage locations to the computer's CPU as
additional memory, called virtual memory. Segmentation is a virtual process that creates variable-sized address spaces
in computer storage for related data, called segments.
Address generated by CPU is divided into:
The mapping from virtual to physical address is done by • Page number(p): Number of bits required to represent the
the memory management unit (MMU) which is a hardware pages in Logical Address Space or Page number
device and this mapping is known as paging technique. • Page offset(d): Number of bits required to represent
particular word in a page or page size of Logical Address
Space or word number of a page or page offset.
• The Physical Address Space is conceptually divided
into a number of fixed-size blocks, called frames.
• The Logical address Space is also splitted into fixed- Physical Address is divided into:
size blocks, called pages. • Frame number(f): Number of bits required to represent the
• Page Size = Frame Size frame of Physical Address Space or Frame number.
• Frame offset(d): Number of bits required to represent
particular word in a frame or frame size of Physical Address
Example: Problem: Theor problem is register size
Space word number of a frame or is small
frame (in practical, it can
offset.
Physical Address = 12 bits, then Physical Address Space =accommodate maximum of 0.5k to 1k page table entries) and process
4 K words size may be big hence the required page table will also be big (lets say
Logical Address = 13 bits, then Logical Address Space = this
8 page table contains 1M entries), so registers may not hold all the
K words PTE’s of Page table. So this is not a practical approach. 
Assume that Page size = frame size = 1 K words
Basic Memory Management
PAGING in Operating System
To overcome this problem a high-speed cache is set up for page
table entries called a Translation Lookaside Buffer (TLB).
Translation Lookaside Buffer (TLB) is nothing but a special
cache used to keep track of recently used transactions. TLB
contains page table entries that have been most recently used.
Given a virtual address, the processor examines the TLB if a
page table entry is present (TLB hit), the frame number is
retrieved and the real address is formed. If a page table entry is
not found in the TLB (TLB miss), the page number is used as
index while processing page table. TLB first checks if the page
is already in main memory, if not in main memory a page fault
is issued then the TLB is updated to include the new page entry. 
Basic Memory Management
Page Fault
Page fault dominates more like an error. It mainly occurs when any program tries to access the data or the code
that is in the address space of the program, but that data is not currently located in the RAM of the system.

• So, basically when the page referenced by the CPU is not found in the
main memory then the situation is termed as Page Fault.
• Whenever any page fault occurs, then the required page has to be
fetched from the secondary memory into the main memory.

Page Fault Handling


• First of all, internal table(that is usually the process control block) for
this process in order to determine whether the reference was valid or
invalid memory access.
• If the reference is invalid, then we will terminate the process. If the
reference is valid, but we have not bought in that page so now we just
page it in.
• Then we locate the free frame list in order to find the free frame.

• Now a disk operation is scheduled in order to read the desired page into


the newly allocated frame.
• When the disk is completely read, then the internal table is modified that is kept with the process, and the page table that
mainly indicates the page is now in memory.
• Now we will restart the instruction that was interrupted due to the trap. Now the process can access the page as though it had
Basic Memory Management
Page Replacement Algorithms
First In First Out (FIFO):
This is the simplest page replacement algorithm. In this algorithm, the
operating system keeps track of all pages in the memory in a queue, the oldest
page is in the front of the queue. When a page needs to be replaced page in the
front of the queue is selected for removal. 

Optimal Page Replacement (OPR):


In this algorithm, pages are replaced which would not be
used for the longest duration of time in the future. 

Optimal page replacement is perfect, but not possible in


practice as the operating system cannot know future
requests. The use of Optimal Page replacement is to set up
a benchmark so that other replacement algorithms can be
analyzed against it.

Least Recently Used(LRU):


In this algorithm page will be replaced which is least
recently used. 

You might also like