Professional Documents
Culture Documents
Unit05 - File Management & Memory Management
Unit05 - File Management & Memory Management
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.
• 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.
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 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.