Docsity

Memory Management - Lecture Slides | CS 4414, Study notes of Operating Systems

Toggle sidebar
bg1
1
CS414: Operating Systems
Today’s Class
•Last time
Deadlock (chapt 8)
Memory management (chapt 9)
PA#3 Discussion
PA#5 out
•This time
Memory management (chapt 9)
Virtual memory (chapt10)
PA#3 back
•Next time (Tues Nov 6)
Virtual memory (chapt 10)
•Extra class – Thurs/Fri of NEXT week
CS414: Operating Systems
Schedule
Sun Tues Thurs Fri
30 1
Deadlock
Memory management
PA#5 out
Memory management
Virtual memory
No class – marty
at conference
Virtual memory
6 8
13 15
20 22
protection, security
PA#6 due, PA#7 out
27 29
protection, security
4
protection,
security
File systems
File sys, I/O sys
File sys
I/O sys 9
No class – marty
at conference
I/O sys,Mass-storage
PA#5 due, PA#6 out No class –
Thanksgiving
14
Final exam
10:00-noon
6
Wrap-up
PA#7 due
protection, security
protection,
security
30
CS414: Operating Systems
Basic Memory Management Terminology
•[Segment] A chunk of memory
assigned to a process
•[Page] Memory may be divided
into fixed size pages to which
the OS assigns processes
•[Physical Address] A real
address in memory (from 0 to
the size of memory)
•[Virtual Address] A program
address that may or may not
have an equivalent in memory.
Virtual address space may be
larger than the actual memory.
OS or architecture translates the
virtual address to a physical
address.
•Physical vs. Logical Memory is a
Crucial Concept!
CS414: Operating Systems
Contiguous Memory Allocation
•As processes enter the system, execute, and terminate, the OS must kee p track
of which memory is available and utilized
•[Allocatable “Chunk”] contiguous memory, either fixed-partition (e.g., 3M
process into 4M allocatable unit– internal fragmentation!) or variable-sized (can
lead to external fragmentation!)
•[Holes] pieces of free memory (shaded in the figure)
•PROBLEM: Given a list of holes the OS must allocate processes to holes
CS414: Operating Systems
Memory Management:
Memory Allocation Strategies
•First-fit
•Next-fit: circular-list variation of first-fit
•Best-fit: leaves the smallest leftover hole
•Worst-fit: leaves the largest leftover hole
•Simulation studies show that first-fit and best-fit yield
better utilization than worst-fit, and that first-fit is
generally faster than best-fit
CS414: Operating Systems
Allocating Variable Partitions: Compaction
(Approach: Merge holes “every once in a while”)
pf3

Partial preview of the text

Download Memory Management - Lecture Slides | CS 4414 and more Study notes Operating Systems in PDF only on Docsity!

CS414: Operating Systems

Today’s Class

  • Last time

Deadlock (chapt 8)

Memory management (chapt 9)

PA#3 Discussion

PA#5 out

  • This time

Memory management (chapt 9)

Virtual memory (chapt10)

PA#3 back

  • Next time (Tues Nov 6)

Virtual memory (chapt 10)

  • Extra class – Thurs/Fri of NEXT week CS414: Operating Systems

Schedule

Sun Tues Thurs (^) Fri

30 1

Deadlock Memory management PA#5 out

Memory management Virtual memory

No class – marty at conference

Virtual memory 6 8

13 15

(^20 ) protection, security PA#6 due, PA#7 out 27 29

protection, security

4

protection, security

File systems

File sys, I/O sys

File sys I/O sys 9 No class – marty at conference I/O sys,Mass-storage PA#5 due, PA#6 out

No class – Thanksgiving

14

Final exam 10:00-noon

6

Wrap-up PA#7 due

protection, security

protection, security 30

CS414: Operating Systems

Basic Memory Management Terminology

  • [Segment] A chunk of memory assigned to a process
  • [Page] Memory may be divided into fixed size pages to which the OS assigns processes
  • [Physical Address] A real address in memory (from 0 to the size of memory)
  • [Virtual Address] A program address that may or may not have an equivalent in memory. Virtual address space may be larger than the actual memory. OS or architecture translates the virtual address to a physical address.
  • Physical vs. Logical Memory is a Crucial Concept!

CS414: Operating Systems

Contiguous Memory Allocation

  • As processes enter the system, execute, and terminate, the OS must keep track of which memory is available and utilized
  • [Allocatable “Chunk”] contiguous memory, either fixed-partition (e.g., 3M process into 4M allocatable unit– internal fragmentation!) or variable-sized (can lead to external fragmentation! )
  • [Holes] pieces of free memory (shaded in the figure)
  • PROBLEM: Given a list of holes the OS must allocate processes to holes

CS414: Operating Systems

Memory Management:

Memory Allocation Strategies

  • First-fit
  • Next-fit: circular-list variation of first-fit
  • Best-fit: leaves the smallest leftover hole
  • Worst-fit: leaves the largest leftover hole
  • Simulation studies show that first-fit and best-fit yield

better utilization than worst-fit, and that first-fit is generally faster than best-fit

CS414: Operating Systems

Allocating Variable Partitions: Compaction

(Approach: Merge holes “every once in a while”)

CS414: Operating Systems

Dynamic Address Relocation

  • Static Relocation

 At load time, OS adjusts the addresses in a process to reflect its position in memory (Similar to when the linker determines where procedures go with a separate compilation.)  Once a process is assigned a place in memory and starts executing it, the OS cannot move it.

  • Dynamic Relocation

 Hardware adds relocation register (base) to logical address to get a physical address

  • Hardware compares address with relocation register and hardware compares address with limit register

CS414: Operating Systems

Relocation

  • Advantages

OS can move a process easily during execution

If the process grows, OS just changes limit register or moves it

Simple, fast HW (two special registers, an add, and two compares)

  • Disadvantages

Process may have to be moved if it grows

HW is an added overhead for every memory reference (in 60s this

was a huge problem)

Hard to share between programs (Two programs using Emacs, for

example); Why?

Program is still limited to physical memory size

Complicates memory management!

CS414: Operating Systems

Swapping

  • If a process is blocked, it (code,data,stack) can be swapped temporarily

out of memory to backing store

  • When process becomes active again, the OS must reload it in memory, either using a static relocation or a dynamic relocation
  • How could or should swapping interact with CPU scheduling?

CS414: Operating Systems

Virtual Memory Introduction

  • Allows process to execute when only part of its address space is loaded into physical memory
  • If virtual address generated (each instruction or data) does not have a corresponding physical address,

combination of HW and SW is used to:

set up a mapping from virtual address to physical address, and

 retry the instruction

CS414: Operating Systems

Two Main Approaches for

Implementing Virtual Memory

  • segmentation: use of relocation-limit registers and bounds-checking blocks of memory variable-sized (logical) segments, defined by user (or compiler) virtual address: { <segment number, offset> ) pure segmentation: whole segments are transferred back and forth between primary and secondary memory
  • paging: virtual address space: flat (linear) sequence

lacking (as in segmentation): VM system in OS has little knowledge of logical segment instead of variable-sized chunk, fixed-sized unit of transfer (the page) memory manager selectively allocates pages to frames in memory and manages (moves, removes, reallocates) pages in memory

  • Overall: segmentation is probably better suited to behavior of process, although it can be harder to use and harder to implement

CS414: Operating Systems

Motivation and Features of Paging

  • A version of the 90/10 rule:

Processes spend 90% of their

time accessing 10% of their

virtual address space.

 We only want to keep those parts of a process in memory that are actually being used. Pages greatly simplify the hole- fitting problem. The logical memory of the process is contiguous, but pages need not be allocated contiguously in memory.

  • What about External

Fragmentation? Internal

Fragmentation?