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

Memory Management

The document discusses memory management concepts in operating systems. It describes main memory as volatile RAM that processes can access in any order. Common RAM types include DRAM which requires refresh, and SRAM which does not. It also discusses secondary storage, buses, logical vs physical addresses, and memory management models like monoprogramming without swapping, monoprogramming with swapping, and multiprogramming with fixed tasks. It explains how partitions, base/limit registers, and fence addresses provide protection between processes in memory.

Uploaded by

MCS 2-E
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Memory Management

The document discusses memory management concepts in operating systems. It describes main memory as volatile RAM that processes can access in any order. Common RAM types include DRAM which requires refresh, and SRAM which does not. It also discusses secondary storage, buses, logical vs physical addresses, and memory management models like monoprogramming without swapping, monoprogramming with swapping, and multiprogramming with fixed tasks. It explains how partitions, base/limit registers, and fence addresses provide protection between processes in memory.

Uploaded by

MCS 2-E
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Operating System

(Shahid Hussain Rathore)

Memory Management
&
Storage Management
Operating System, Shahid H. Rathore (All rights reserved)
MEMORY MANAGEMENT
Memory Management
 Concepts

Operating System, Shahid H. Rathore (All rights reserved)


Memory Management
 Introduction
 Main memory consists of volatile random access
memory (RAM)
 Processes can access data locations in any
order
 Common forms of RAM include:
• Dynamic RAM (DRAM) - requires
refresh circuit
• Static RAM (SRAM) - does not require
refresh circuit

Operating System, Shahid H. Rathore (All rights reserved)


Memory Management
 Concepts
 Main memory consists of volatile random access
memory (RAM)
 Processes can access data locations in any
order
 Common forms of RAM include:
• Dynamic RAM (DRAM) - requires
refresh circuit
• Static RAM (SRAM) - does not require
refresh circuit

Operating System, Shahid H. Rathore (All rights reserved)


Memory Management
 Concepts
 Secondary storage
 Secondary storage stores large quantities of
persistent data at low cost
• Secondary storage stores large quantities of
persistent data at low cost
 Mechanical movement of read/write head
 Rotational latency
 Transfer time

Operating System, Shahid H. Rathore (All rights reserved)


Memory Management
 Concepts
 Buses: a collection of traces
 Traces are thin electrical connections that
transport information between hardware
devices
 A port is a bus that connects exactly two
devices
 An I/O channel is a bus shared by several
devices to perform I/O operations
e.g. the frontside bus (FSB) connects a
processor to main memory

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Also known as Random Access Memory (RAM) and
volatile storage.
 CPU can only access data which brought up into main
memory.
 The concept of a logical address space that is bound to
a separate physical address space is central to proper
memory management
 Logical address: generated by the CPU; also referred to
as virtual address
 scheme
Operating System, Shahid H. Rathore (All rights reserved)
Main (Primary) Memory
 Physical address: address seen by the memory unit
 Logical and physical addresses are the same in
compile-time and load time address-binding schemes;
logical (virtual) and physical addresses differ in
execution-time address-binding scheme
 Common form of RAMs:-
 Dynamic RAM (DRAM): Require refresh circuit
 Static RAM (SRAM): Doesn’t require refresh
circuit.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
Computer can be:
 Special Purpose: e.g. Medical equipment machines,
Weapon control machines etc.
 Bare machine: Single partition allocation
 No protection, no utilities, no overhead
 Its simplest form of memory
management
 logical == physical
 User can have complete control.
Commensurably, the operating system
has none

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 General purpose: e.g. Computer in use now days. Uses
resident monitor memory model.
 Definition of partitions:
 Division of physical memory into fixed sized
regions
 The number of partitions determines the level of
multiprogramming. Partition is given to a
process when it's scheduled
 Protection around each partition determined by
bounds ( upper, lower ) base / limit
 These limits are done in hardware.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Resident Monitor:
 This model suggests that a part of OS always
should reside in memory and other modules may
be loaded on demand basis. For instance, device
driver e.g. printer driver may be loaded when
printing is required.
 User area posses user data and applications
 Monoprogramming without swapping or paging
(Single User):
 The “good old days” when everything was
easy.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Monoprogramming without swapping or
paging (Single User):
 OS area requires security from User Area
programs. User programs should not access OS
portion whereas OS should be allowed to
access User area.
 Hence, a fence address is used.
 Any user program access memory address less
than fence address then illegal access.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Monoprogramming without swapping or
paging (Single User):
 Software based Fence Addr.: Less efficient,
variable partitions permissible.
 Hardware based Fence Addr.: More robust
approach in performance but OS memory
partition size is fixed and unupgradable.
 Fence addr should be fixed or variable
(Hardware / Software) based?
 Fence addr should be variable hardware based.
The approach is implemented using a register
called Fence Register (FR).

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Monoprogramming without swapping or
paging (Single User):

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Monoprogramming with swapping or paging
(Single User):
 The model must be modified with swapping for
multiprogramming or multi-user.
 Swap-in: Job coming to primary memory
 Swap-out: Job going to secondary storage.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Monoprogramming with swapping or paging
(Single User):
 Drawback: Such model requires lots of
swapping (secondary storage), consequently
degradation in efficiency.
 Improved Model:

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Monoprogramming with swapping or paging
(Single User):
 User Area: contains program in execution.
 Buff 2: Loads next job to be executed.
 Buff 1: Temp Storage.
 Operational behavior as follows:-
 When a user area job stop execution, it
moves to Buff 1
 Job from Buff 2 moves to User Area (as
Primary Memory access time is much lesser
than secondary storage)
 Later Buff 1 (Stop executed) job is moved to
Secondary storage

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Monoprogramming with swapping or paging
(Single User):
 Consequently, the CPU utilization improves.
 Problem: As User area program has to access
memory as well as Buff 1& Buff 2 resident
programs so how to ensure protection among
each other?
 Fence address moving to upper partition.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with fixed number of
Tasks/Partitions(MFT):-
 One area is reserved for OS and remaining
partition is divided into fixed or variable sized
sub-portions.
 Degree of multiprogramming is decided by the
number of partitions in main memory,
consequently, number of processes/ jobs.
 If number of tasks/ partitions in memory is
fixed then number of processes (degree of
multiprogramming) is also fixed.
 Every job would be ready for execution.
 Switching from job1 to jobn will be change in
instruction pointer context.
 Increase in performance as extra Swap-in and
Swap-out has been eliminated
Operating System, Shahid H. Rathore (All rights reserved)
Main (Primary) Memory
 Multiprogramming with fixed number of
Tasks/Partitions(MFT):-
 Protection a Job area from access of other job
area would require two registers:-
 Upper bound register (UBR):
 Lower bound register (LBR):

Fig.: MFT job protection with Upper and Lower bound registers
Operating System, Shahid H. Rathore (All rights reserved)
Main (Primary) Memory
 Multiprogramming with fixed number of
Tasks/Partitions(MFT):-
 If CPU generate an address less than (<) LBR
and greater than (>) UBR.
 It means process trying to access area allocated
to another Job.
 Then a trap would be generate to handle this.
 LBR and UBR approach can be implemented
with two registers i) Base Register and
ii) Limit Register

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with fixed number of
Tasks/Partitions(MFT):-

Fig.: Protection with base and limit


Operating System, Shahid H. Rathore (All rights reserved)
Main (Primary) Memory
 MFT has two variants :-
 MFT with Fixed Size Partitions:-

Fig.: MFT job protection with fixed size partitions


Operating System, Shahid H. Rathore (All rights reserved)
Main (Primary) Memory
 MFT has two variants :-
 MFT with Variable Size Partitions:-
 One partition size adjusted
once and become fixed

Fig.: MFT with


variable size
partitions

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 MFT with Variable Size Partitions:-
 Variable Algorithms used to allocate a job to a
Partitions, e.g.:-
 First Fit Algorithm: First available partition
≥ job required area will allocate.
• E.g. Job1 require size 50Kb will be
allocated to first 100Kb size partition
• Job can have one partition and a partition
can have one job only.
• In above case, 50% of the 100KB size
partition will be wasted
• Internal Fragmentation: Part of a
memory which is allocated but not used
and can’t be allocated to any other job.
Operating System, Shahid H. Rathore (All rights reserved)
Main (Primary) Memory
 MFT with Variable Size Partitions:-
 Variable Algorithms used to allocate a job to a
Partitions, e.g.:-
 Best Fit Algorithm: First partition of same
size as job or closest will be allocated.
• More complexity.
• External Fragmentation: A job has
higher memory requirement than largest
partition available and many partition are
still empty. This kind of fragmentation is
called external fragmentation.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 MFT with Variable Size Partitions:-
 Variable Algorithms used to allocate a job to a
Partitions, e.g.:-
 Best Fit Algorithm: First partition of same
size as job or closest will be allocated.
• E.g: Job2 requires 120KB of memory
whereas largest partition size is 100KB.
Although the 100KB and some other
partitions are available but the Job 2
can’t fit in any of partition.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-
 Partitions are created of appropriate size when
they needed.
 Degree of multiprogramming is decided by the
number of Jobs/ processes.
 If number of tasks/ partitions in memory is
variable then number of processes (degree of
multiprogramming) is also variable.
Operating System, Shahid H. Rathore (All rights reserved)
Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-

Processes scheduled to CPU as: J2<J1<J3<J4<J5<J6

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-

 Free partition (26KB) will be external


fragmentation.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-
 After 5BT (competition of Job J2):

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-
 After free partition allocation of 100KB to job
J4 (70K).
 Unused part of the above 100KB partition will
be internal fragmentation.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-
 Now free partitions are 30K & 26K total of
which equals to 56K where as next job J5
requires 50K.

 But these partitions are not contiguous so can’t


allocate to a single job.

 Memory Compaction: Rearranging memory


partition is called memory compaction.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-
 After memory compaction.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-
 Free Partition of 56KB will be allocated J5
(50KB):
 Unallocated Free partition of 6KB will be
external fragmentation.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-
 After more 10BT; J1 will be competed and new
memory status will be as follows:

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-
 J6 will be allocated to first free partition and
status will change as follows:

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-
 Allocated Partition Table: Contains information
of allocated/ used memory partitions.
 Start Location
 Size
 Status:
 When allocated
 To whom
 Free Partition Table: Contains information
related free partitions.
 Starting location
 Size
Operating System, Shahid H. Rathore (All rights reserved)
Main (Primary) Memory
 Multiprogramming with Variable number of
Tasks/Partitions(MVT) :-

 Small amount of internal fragmentation be


allowed to avoid casing problem. i.e maintain
extra very small entries in free area table and
their management.

 Memory compaction is costly solution because


it heavily engages CPU.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Paged Memory Management
 The technique eliminates compaction.
 Every process is divided into no. of pages
(logical address space).
 Physical memory is also divided into frames
having similar size as of job/ process size pages
in logical address space.
 All pages size would be same except last page.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Paged Memory Management

Local Address Main Memory


Space of a job (Physical Addr.)

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Paged Memory Management
 P = Page Size
 L = Local Address
L = p, d
 p = Page No. of local address
= L (integer division) P
 d = Offset within a page
= L (mod) P

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Paged Memory Management
 Mapping:
 Page map table is used to map logical
address of a page to physical location in
memory
 First entry of a page map table contains the
first address location in main memory and
so on.
 Nth entry in page map table contains nth
frame location in memory.

Operating System, Shahid H. Rathore (All rights reserved)


Main (Primary) Memory
 Paged Memory Management
 Example:
 Total Memory = 256KB
 OS partition = 40KB
 L = 12
 Page size = 10
 p = L (integer division) P (e.g. 12 / 10 = 1)
 d = L (mod) P (e.g. 12 mod 10 = 2)
 So, p = 1 and d (offset)= 2
Operating System, Shahid H. Rathore (All rights reserved)
Main (Primary) Memory
 Paged Memory Management
 Example:

Operating System, Shahid H. Rathore (All rights reserved)


THANKS

Operating System, Shahid H. Rathore (All rights reserved)

You might also like