L10 Lecture Memory

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Memory

Memory Management

 Program must be brought (from disk) into memory and placed


within a process for it to be run
 Main memory and registers are only storage CPU can access
directly
 Memory unit only sees a stream of addresses + read requests, or
address + data and write requests
 Register access in one CPU clock (or less)
 Main memory can take many cycles, causing a stall
 Cache sits between main memory and CPU registers
 Protection of memory required to ensure correct operation
Memory Management

Source: https://www.geeksforgeeks.org/levels-of-memory-in-operating-system/
Logical vs. Physical Address Space

- Run time mapping of logical to physical addresses is handled


by the memory-management unit, MMU.

- The base register is now termed a relocation register, whose


value is added to every memory request at the hardware level.
Contiguous Memory Allocation
RAM (Primary Memory)

 One approach to memory management


is to load each process into a
contiguous space.
 The operating system is allocated
space first, usually at either low or high
memory locations, and then the
remaining available memory is Operating System
allocated to processes as needed.
Memory Allocation

1. allocating contiguous memory is to divide all available memory into


equal sized partitions, and to assign each process to their own partition.
 This restricts both the number of simultaneous processes and the
maximum size of each process, and is no longer used.

2. Alternate approach is to keep a list of unused ( free ) memory blocks


( holes ), and to find a hole of a suitable size whenever a process needs to be
loaded into memory.
 First fit - Search the list of holes until one is found that is big enough to
satisfy the request
 Best Fit - Allocate the smallest hole that is big enough to satisfy the
request and
 Worst Fit - Allocate the largest hole available,
RAM (Primary Memory) HDD (Secondary Storage)
RAM (Primary Memory) HDD (Secondary Storage)

Operating System
RAM (Primary Memory) HDD (Secondary Storage)

Teams

Words

Operating System
RAM (Primary Memory) HDD (Secondary Storage)
NEW PROCESS Available Segment
Teams
Chrome

Words
CANNOT FIT,
INSUFFUCIENT
RAM SPACE
Operating System
HOW??
RAM (Primary Memory) HDD (Secondary Storage)
NEW PROCESS Available Segment
Teams
Chrome
SWAP OUT
Idle Process will be
Words moved out of the
CANNOT FIT,
INSUFFUCIENT memory
RAM SPACE
Operating System
HOW??
RAM (Primary Memory) HDD (Secondary Storage)
NEW PROCESS Available Space
Teams
Chrome

Words
Available Space

Operating System
RAM (Primary Memory) HDD (Secondary Storage)
NEW PROCESS Available Space

Spreadsheet Teams

Words
Available Space

Operating System
RAM (Primary Memory) HDD (Secondary Storage)
NEW PROCESS Available Space

Spreadsheet Teams

Words
Available Space

Operating System
External Fragmentation
available memory is broken up into lots of little pieces, none of which is big enough to satisfy
the next memory requirement, although the sum total could.
In other words, the total memory space exists to satisfy a request, but it is not contiguous
Segmentation (Non-Contiguous Memory Allocation)
 Most users ( programmers ) do
not think of their programs as
existing in one continuous
linear address space.
 Memory in multiple segments,
each dedicated to a particular
use, such as code, data, the
stack, the heap, etc.
 Memory segmentation supports
this view by providing addresses
with a segment number
( mapped to a segment base
address ) and an offset from the
beginning of that segment.
RAM (Primary Memory) HDD (Secondary Storage)
NEW PROCESS Available Segment 1000
1200
Spreadsheet Teams

Words
Available Segment 2000

2400
(Segment Table) Operating System

Seg. Limit Base


0 200 1000
1 400 2000
RAM (Primary Memory) HDD (Secondary Storage)
NEW PROCESS Available Segment 1000
1200
Games Teams
(Single Segment)

Words
Available Segment 2000

Cannot fit, 2400


Operating System
External Fragmentation
Paging
 Paging is a memory management scheme that allows processes
physical memory to be discontinuous, and
 which eliminates problems with fragmentation by allocating
memory in equal sized blocks known as pages.
 Paging eliminates most of the problems of the other methods
discussed previously,
 and is the predominant memory management
technique used today.
RAM (Primary Memory) HDD (Secondary Storage)
PHYSICAL MEMORY LOGICAL MEMORY
VRAM
RAM (Primary Memory) HDD (Secondary Storage)
PHYSICAL MEMORY Page LOGICAL MEMORY
Table VRAM
Segmentation vs Paging
 Segmentation memory makes an entire block of code available to processor
which allows fast access
 Segmentation can lead to fragmentation of free space
 With segmented memory, large processes may not get access to the memory very
often
 Paged memory can lead to fragment processes which run more slowly
 Paged memory makes better use of free space
 Windows uses paged memory, segmentation is not as common
 Some processors support a hybrid of pages and segmented memory management
in which each segment consist of several fixed size blocks

You might also like