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

06-07 - Memory Management

memory mgmt

Uploaded by

coxopi7544
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)
14 views

06-07 - Memory Management

memory mgmt

Uploaded by

coxopi7544
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/ 42

Rehan Azmat

Lecture 06 and 07
Memory Management
 Cache Memory
 Cache Memory Design
◦ Cache block size (line size)
◦ Total cache size
◦ Mapping function
◦ Replacement method
◦ Write policy
◦ Numbers of caches:
 Single, two-level, or three-level cache
 Unified vs. split cache
 Memory Management
◦ Swapping
◦ Partitioning
◦ Paging
 Uni-program
◦ Memory split into two
◦ One for Operating System (monitor)
◦ One for currently executing program
 Multi-program
◦ “User” part is sub-divided and shared among active
processes
Swaping
 Problem: I/O is so slow compared with CPU
that even in multi-programming system, CPU
can be idle most of the time
 Solutions:
◦ Increase main memory
 Expensive
 Leads to larger programs
◦ Swapping
 Long term queue of processes stored on disk
 Processes “swapped” in as space becomes
available
 As a process completes it is moved out of
main memory
 If none of the processes in memory are ready
(i.e. all I/O blocked)
◦ Swap out a blocked process to intermediate queue
◦ Swap in a ready process or a new process
◦ But swapping is an I/O process…
Partitioning
 Splitting memory into sections to allocate to
processes (including Operating System)
 Fixed-sized partitions
◦ May not be equal size
◦ Process is fitted into smallest hole that will take it
(best fit)
◦ Some wasted memory
◦ Leads to variable sized partitions
 Allocate exactly the required memory to a
process
 This leads to a hole at the end of memory,
too small to use
◦ Only one small hole - less waste
 When all processes are blocked, swap out a
process and bring in another
 New process may be smaller than swapped
out process
 Another hole
 Eventually have lots of holes (fragmentation)
 Solutions:
◦ Coalesce - Join adjacent holes into one large hole
◦ Compaction - From time to time go through
memory and move all hole into one free block (c.f.
disk de-fragmentation)
 No guarantee that process will load into the
same place in memory
 Instructions contain addresses
◦ Locations of data
◦ Addresses for instructions (branching)
 Logical address - relative to beginning of
program
 Physical address - actual location in memory
(this time)
 Automatic conversion using base address
Paging
 Split memory into equal sized, small chunks -page frames
 Split programs (processes) into equal sized small chunks -
pages
 Allocate the required number page frames to a process
 Operating System maintains list of free frames
 A process does not require contiguous page frames
 Use page table to keep track
 The operating system (OS) is responsible for:
◦ Maintaining a list of free frames.
◦ Using a page table to keep track of the mapping between pages and page
frames.
 Memory Management
◦ Swapping
◦ Partitioning
◦ Paging
◦ Virtual Memory
 Demand Paging
 Page Replacement Algorithm
 Page Table
◦ Translation Lookaside Buffer (TLB)
◦ Segmentation
Virtual Memory
 The physical main memory (RAM) is very limited in space.
 It may not be big enough to store all the executing
programs at the same time.
 Some program may need memory larger than the main
memory size, but not all the program need to be
maintained in the main memory at the same time.
 Virtual Memory takes advantage of the fact that at any
given instant of time, an executing program needs only a
fraction of the memory that the whole program occupies.
 The basic idea: Load only pieces of each executing
program which are currently needed.
 Demand paging
◦ Do not require all pages of a process in memory.
◦ Bring in pages as required.
 Page fault
◦ Required page is not in memory.
◦ Operating system must swap in the required page.
◦ May need to swap out a page to make space.
◦ Select page to throw out based on recent history.
 To provide the user/programmer with a much bigger memory
than the main memory with the help of the operative system.
 Virtual memory >> real memory
 When accessing a VM page which is not in the main memory,
a page fault occurs. The page must then be loaded from the
secondary memory into the main memory by the OS.
 When a page fault occurs and all page frames are occupied,
one of them must be replaced.
 If the replaced page has been modified during the time it
resides in the main memory, the updated version should be
written back to the secondary memory.
 Our wish is to replace the page which will not be accessed in
the future for the longest amount of time.
 Problem —We don’t know exactly what will happen in the
future.
 Solution —We predict the future by studying the access
patterns up till now (“learn from history”).
 FIFO (First In First Out) — To replace the one in MM
the longest of time.
 LRU (Least Recently Used) — To replace the one
that has not be accessed the longest time.
 LFU (Least Frequently Used) — To replace the one
that has the smallest number of access during the
latest time period.
 Too many processes in too little memory
 Operating System spends all its time
swapping
 Little or no real work is done
 Disk light is on all the time

 Solutions
◦ Good page replacement algorithms
◦ Reduce number of processes running
◦ Fit more memory
 We do not need all of a process in memory
for it to run
 We can swap in pages as required
 So - we can now run processes that are
bigger than total memory available!

 Main memory is called real memory


 User/programmer sees much bigger memory
- virtual memory
 Every virtual memory reference causes two
physical memory access
◦ Fetch page table entry
◦ Fetch data
 Use special cache for page table
◦ TLB
Segmentation
 Paging is not (usually) visible to the
programmer
 Segmentation is visible to the programmer
 Usually different segments allocated to
program and data
 May be a number of program and data
segments
 Simplifies handling of growing data
structures
 Allows programs to be altered and
recompiled independently, without re-linking
and re-loading
 Lends itself to sharing among processes
 Lends itself to protection
 Some systems combine segmentation with
paging
End of the Lecture

You might also like