Chapter 5
Chapter 5
and
Memory Management
1
File System
2
Introduction
All computer applications need to
store and retrieve information.
Several storage media such as
magnetic disk, tapes.
To store information on disks and
other external media in units called
“File”.
Files are managed by OS.
3
File Extensions
.ppt
.doc
.c
.xls
.pdf
.html
.db
.obj
.mp3
4
Attributes of Files
Name
Identifier
Type
Location
Size
Protection
Time, date and user identification
Password
Creator or Owner
5
Operations on Files
Create
Open
Close
Write
Read
Append
Delete
Seek
Rename
6
File Types
Following types of files are available in
OS
Simple file system (Regular files)
Basic file system (Directories)
Character special files (Logical files)
Block special files (Physical files)
7
File System Structure
Byte Sequence
Record Sequence
Tree of Records
8
Access Methods
There are several ways that the information
in the file can be accessed.
1. Sequential Access
2. Direct Access
9
1. Sequential Access
Information in the file is processed in
order , one record after the other.
Disadvantages
Wastage of memory.
Performance is poor.
11
2.Direct Access
Direct access allows random access to
any file or block.ods
12
Advantages
Veryfast direct access.
Hashing is used.
Disadvantages
It has not particular sequence
13
File Allocation Methods
On secondary storage a file consists
of a collection of blocks.
File management system is
responsible for allocating blocks of
files.
Allocate the space to files effectively
utilized and files can be quickly
accessed.
14
Methods of allocating disk space
1. Contiguous
2. Linked
3. Indexed
15
1.Contiguous
This method requires each file to
occupy a set of contiguous address on
the disk.
Disk addresses define a linear
ordering on the disk.
The number of disk seeks required to
access blocks.
16
Fig. Contiguous file allocation
17
Advantages
Even direct access is fast.
Quick and easy calculation of block.
Disadvantages
There
is no best place to put a new file.
Compaction may be required.
18
2.Linked allocation
In this type of allocation each file is
a linked list of disk blocks.
The disk blocks may present
anywhere on the disk.
The directory contains a pointer to
the first as well as last block of the
file.
19
Fig. Linked allocation
20
Advantages
Starting and ending of file can be easily
found.
It is used for sequential access.
Disadvantages
Pointer is needed.
Not effective for direct access.
21
3.Indexed allocation
Index allocation brings all pointers
together into one location called as
indexed block.
When the file is created all the
pointers in the indexed block will be
set to null.
Index support direct access.
22
Fig. Indexed allocation
23
Advantages
Block creates the set of pointer at one
location
Accessing index block is easy.
Disadvantages
Decide the block size for each file is
complicated.
Storing many addresses i.e pointers
becomes an overhead.
24
Directory Structure
To keep track of files , file system
normally have directories or folders.
There are several of directory
system.
1. Single level directory system.
2. Two level directory system.
25
1.Single level Directory
Root Directory
A B C
26
2.Two level Directory System
Root Directory
C D
A
B
27
Introduction
Memory either can be volatile
memory and non-volatile memory.
Memory consist of large array of
words or bytes each with its own
address.
Memory that the processors directly
access for instructions and data.
28
Functions of Memory Management
Keeping track of the status of each
memory location.
Determine the allocation and
deallocation technique and policy.
CPU fetches the instructions from
memory according to the value of
PC.
29
User 1
30
Memory Partitioning
The method of dividing the memory into
several small parts, these parts are called
as partitions.
Mainly two types of methods are used for
partitioning.
1. Fixed Partitioning(Static Memory
Partitioning)
2. Variable Partitioning(Dynamic Memory
Partitioning)
31
1. Fixed Partitioning
The partition made in this method are of
fixed size.
8M 8M
8M 2M
8M 4M
8M 6M
8M 8M
8M 8M
8M 12 M
8M 9M
8M 16 M
Disadvantages
Wastageof memory.
Memory is not fully utilized.
33
2.Variable Partitioning.
This is also called as dynamic memory
partitioning.
8 MB 8 MB 8 MB
Process 1 20 MB Process 1 20MB
56 MB
Process 2 26MB
36 MB
10MB
34
Free Space Management Techniques
To keep track of free disk space , the
system maintains a free space list.
In free space management technique
mainly two methods are as follows.
1. Bitmap.
2. Linked List.
35
Bitmap
The memory is divided into number
of allocation units.
Each unit is then further divided into
bits.
‘0’ indicates that unit is free.
‘1’ indicates that unit is allocated.
36
Bitmap :- 000011100111110………
0123456789 15
Memory
Free Allocated
38
F 0 4 A 4 3 F 7 2
F 9 5 A 14 2 F 16 1
A 17 3 F 20 4 A 24 1 *
39
Compaction
Compaction shuffles the free memory
locations together in one large block.
If static memory reallocation is done then
it is not possible to implement compaction
due to it’s difficult to relocate internal
addresses.
1. First fit
2. Best fit
3. Worst fit
40
Paging
Dynamic memory partitioning
suffers from external fragmentation.
To overcome this we can use
compaction or paging.
It allows a program to be allocated
physical memory wherever it is
available.
41
Paging……
In paging physical memory is broken into
fixed size blocks called “frames.”
Also logical memory is broken into fixed
size blocks called as “pages.”
The logical address is in the following
form.
42
Physical
Address
Logical
Address
CPU p d f d Physical
Memory
p
f
Page Table
45
Demand Paging
Disk
Program A 0 1 2
Swap Out
3 4 5
6 7 8
Program B Swap In 9 10 11
Main Memory 46
Page Replacement
1. FIFO page Replacement
2. Optimal page Replacement
3. LRU Page Replacement
47
Virtual Memory
Virtual memory is the memory generated
from the physical memory devices like disk
when less amount of main memory is
available.
It is separation of logical memory from
physical memory.
Large virtual memory can be provided for
programmers on a smaller physical
memory.
48
Page 0
Page 1
Page 2
Disk
Memory map
Page n
Physical Memory
Virtual Memory
49
Memory address generated by the
computer system is called as
virtual address.
It does not go directly to the
memory bus, they go to MMU.
MMU maps the virtual addresses
onto the physical memory
addresses.
50
CPU Sends virtual addresses to
MMU
CPU
Package
CPU
Memory Disk
M Controller
M
U
52
Thank You
53