Topic 3
Topic 3
MEMORY MANAGEMENT
Memory Management Of
Operating System
List of content
3.1 Understand Memory Management
3.1.1 Compare between resident and 3.2.2 Discover the following related to
transient routines. memory management terminologies
3.1.2 Relate virtual memory and Cache a. Fixed – partition memory
memory technique. management
3.1.3 Explain terms of Paged Virtual b. Dynamic memory management
Memory
c. Segmentation
a. Page Tables
d. Paging
b. Dynamic Address Translation
c. Paging Supervisor
3.2.3 Apply cache operation to perform in
operating system
3.2 Apply Virtual Memory and Cache a. CPU cache
Memory Management
b. Disk cache
3.2.1 Illustrate a Model of Virtual Memory
c. Web cache
a. Demand Paging
b. Swapping
c. Shared Virtual Memory
Part 1
3.1 Understand Memory Management
Cost per
bit The system must
increases first move programs
SECONDARY AND TERTIARY STORAGE and data to main
Capacity memory before a
decreases processor may
reference them.
Example of secondary storage – tape or disk
Function of Memory Manager
• The memory manager function is to keep track of which
parts of memory are in use and which part are not use.
• Coordinate how memory hierarchy is used
• The memory manager is an operating system component
concerned with the system’s memory organization
scheme and memory management strategies.
• Determines how available memory space is allocated to
process.
• And how to respond to changes in a process memory
usages.
• It’s also interact with special purpose memory
management hardware to improve performance.
Memory Management Strategy
Divided into
• Fetch strategies
• Placement strategies
• Replacement strategies
a) Fetch strategies
• Determine when to move the next piece of a program or data to main
memory from secondary storage.
• Divide into two types
• Demand fetch strategies
• Conventional
• System places the next piece of program or data in main
memory when running program references it.
• Anticipatory fetch strategies
• Attempt to load a piece of program or data into memory before it
is referenced.
b) Placement strategies
c) Replacement Strategy
Example: routine that control physical Example: routine that formats disks, any
I/O, antivirus, clock & time program/ software/application/web
browser
Cont…
• Generally, the operating
system occupies low memory
beginning with address 0.
• Key control information
comes first followed by the
various resident operating
system routines.
• The remaining memory,
called the transient area, is
• where application programs
and transient operating
system routines are loaded.
Virtual vs Physical addresses
•“virtual addresses”used by the program
•“physical addresses”that represent places in the
machine’s “physical”memory.
Address Translation
• Logical Addresses
• With a virtual memory system, the main memory can be viewed as a
local store for a cache level whose lower level is a disk. Since it is
fully associative there is no need for a set field. The address just
decomposes into an offset field and a page number field. The number
of bits in the offset field is determined by the page size. The remaining
bits are the page number.
• An Example
• A computer uses 32-bit byte addressing. The computer uses paged
virtual memory with 4KB pages. Calculate the number of bits in the
page number and offset fields of a logical address.
• Answer
• Since there are 4K bytes in a cache block, the offset field must
contain 12 bits (212 = 4K). The remaining 20 bits are page number
bits. Thus a logical address is decomposed as shown below.
32 bit
20 bit 12 bit
page number offset
Page Tables
• Virtual memory address translation
uses page tables. These are simple
arrays in memory indexed by page
number. A page table base register
(PTBR) holds the base address for
the page table of the current process.
• Each page table entry contains
information about a single page. The
most important part of this
information is a frame number —
where the page is located in physical
memory.
• Address translation combines the
frame number with the offset part of a
logical address to form a physical
address.
Dynamic address translation
• Dynamic address translation, or DAT, is the process of
translating a virtual address during a storage reference
into the corresponding real address.
• If the virtual address is already in central storage, the DAT
process may be accelerated through the use of a
translation lookaside buffer. If the virtual address is not in
central storage, a page fault interrupt occurs, z/OS® is
notified and brings the page in from auxiliary storage.
Paging Supervisor
• In a VS operating system, all non-resident programs exist in
complete form only on auxiliary storage, which is where the OS
loads them first. and the total virtual storage size of all
executing programs usually exceeds the size of the real
storage of the computer.
• In OS/390, both virtual and real storage are divided into 4096-
byte chunks. The chunks are called pages on auxiliary storage,
and page frames in real RAM.
• Paging is the name of the mechanism used to maintain the
contents of real memory:
• When a program is first loaded, it is copied into contiguous
virtual storage pages on auxiliary storage, not into real storage
page frames in RAM.
• From that initial DASD storage location, a page is copied as
needed into a real storage page frame by the OS/390 Paging
Supervisor.
PART 2
3.2 Apply Virtual Memory and Cache Memory Management
3.2.1 Illustrate a Model of Virtual Memory
a. Demand Paging
b. Swapping
c. Shared Virtual Memory
3.2.2 Discover the following related to memory management terminologies
a. Fixed – partition memory management
b. Dynamic memory management
c. Segmentation
d. Paging
VIRTUAL MEMORY
• If I can see it and I can touch it,
it’s real.
• If I can’t see it but I can touch it,
it’s invisible.
• If I can see it but I can’t touch it,
it’s virtual.
• And if I can’t see it and I can’t
touch it’s…gone!
Virtual Memory :Analogy
Disadvantages
• Number of tables and the amount of processor overhead
for handling page interrupts are greater than in the case
of the simple paged management techniques.
Swapping
• When you load a file or program, the file is stored in the
random access memory (RAM).
• Since RAM is finite, some files cannot fit on it.
• These files are stored in a special section of the hard
drive called the "swap file". "Swapping" is the act of using
this swap file.
• A swapping is a mechanism in which a process can be
swapped temporarily out of memory to a backing store
and then brought back into memory for continued
execution.
Memory Swapping Technique
• A process can be swapped temporarily out of memory to a
backing store, and then brought back into memory for
continued execution
Operating System
1. First Fit
2. Best Fit
3. Worst Fit
First Fit
• Allocate the first free block that is large enough for the new
process.
• This a fast algorithm.
Example:
Program Allocation size for a program to process
357 200 400 600 500 300 250
210
460
491
Example:
Program Allocation size for a program to process
357 200 400 600 500 300 250
210
460
491
- put 357 into 600 space, it will have 243 unused space.
- next put 210 into 500 space, it will have 290 unused space.
- next put 460 into 400 space, but cannot fit.
- Lastly put 491 into 300,also cannot fit to proceed the
process. So it only 2 programs will be process.
Compaction: • Method to overcome the external
fragmentation problem.
• All free blocks are brought together as
one large block of free space.
• For example, that a 640K program has
just finished executing.If there are no
640K programs available, the system
might load a 250K program and a 300K
program, but note that 90K remains
unallocated.If there are no 90K or
smaller programs available, the space
will simply not be used. The little
chunks of unused space will be spread
throughout memory, creating a
fragmentation problem.
Non-Contigous Memory Allocation
• to resolve the problem of external fragmentation and to
enhance the degree of multiprogramming to greater
extent, it was decided to sacrifice the simplicity of
allocating contiguous memory to every process.
• It was decided to have un contiguous physical address
space of a process so that a process could be allocated
memory wherever it was available.
Basket
case
Student A ask for book, librarian get it from book rack
Student A return a book, librarian put back in basket case
Student B borrow a same book, librarian get it from basket
case
CPU Cache