0% found this document useful (0 votes)
12 views64 pages

CH 7Memory$Device MNGT

The document provides an overview of memory and device management, focusing on various memory organization techniques such as swapping, contiguous memory allocation, segmentation, and paging. It discusses the importance of address binding, memory management units, and the challenges of fragmentation. Additionally, it covers methods for dynamic storage allocation and the implementation of paging to manage memory efficiently.

Uploaded by

hirpaadugna1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views64 pages

CH 7Memory$Device MNGT

The document provides an overview of memory and device management, focusing on various memory organization techniques such as swapping, contiguous memory allocation, segmentation, and paging. It discusses the importance of address binding, memory management units, and the challenges of fragmentation. Additionally, it covers methods for dynamic storage allocation and the implementation of paging to manage memory efficiently.

Uploaded by

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

1

Memory and Device


Management

06/02/2025
Main Memory
2

• Background
• Swapping
• Contiguous Memory Allocation
• Segmentation
• Paging

06/02/2025
Objectives
3

• To provide a detailed description of various ways


of organizing memory hardware
• To discuss various memory-management
techniques, including paging and segmentation

06/02/2025
Background
• 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
Address Binding
5

• Usually, a program resides on a disk as a binary


executable file.
• To run, the program must be brought into memory and
placed within the context of a process, where it
becomes eligible for execution on an available CPU.
• As the process executes, it accesses instructions and
data from memory.
• Eventually, the process terminates, and its memory is
reclaimed for use by other processes.
06/02/2025
6

06/02/2025
7

06/02/2025
8

06/02/2025
Cont…
9

• In most cases, a user program goes through several


before being executed
• A compiler typically binds symbolic addresses to
relocatable addresses
• The linker or loader in turn binds the relocatable
addresses to absolute addresses.
• Each binding is a mapping from one address space to
another.
• Address-binding Schemes
• Compile Time. 06/02/2025
• Load Time
10

06/02/2025
11

06/02/2025
Logical vs. Physical
Address Space
• 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
• 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
• Logical address space is the set of all logical addresses
generated by a program
• Physical address space is the set of all physical addresses
Memory-Management
Unit (MMU)
• Hardware device that at run time maps virtual to physical
address
• Many methods possible, covered in the rest of this chapter
• To start, consider simple scheme where the value in the
relocation register is added to every address generated by a
user process at the time it is sent to memory
• Base register now called relocation register
• MS-DOS on Intel 80x86 used 4 relocation registers
• The user program deals with logical addresses; it never sees
the real physical addresses
• Execution-time binding occurs when reference is made to
location in memory
16

06/02/2025
Swapping
• Process instructions and the data they
operate on must be in memory to be
executed.
• A process can be swapped temporarily
out of memory to a backing store, and
then brought back into memory for
continued execution
• Total physical memory space of processes
can exceed physical memory
• Increasing the degree of
multiprogramming in a system.
Swapping (Cont.)
18
• Backing store – fast disk large enough to
accommodate copies of all memory images for all
users; must provide direct access to these
memory images
• Swap Out, Swap In – swapping variant used for
priority-based scheduling algorithms; lower-
priority process is swapped out so higher-priority
process can be loaded and executed

06/02/2025
Swapping (Cont.)
• Does the swapped out process need to swap
back in to same physical addresses?
• Depends on address binding method
• Plus consider pending I/O to / from process
memory space
• Modified versions of swapping are found on
many systems (i.e., UNIX, Linux, and
Windows)
• Swapping normally disabled
• Started if more than threshold amount of
memory allocated
• Disabled again once memory demand reduced
Contiguous Memory
Allocation
• Main memory must support both OS and user
processes
• Memory is a limited resource; hence, must allocate
efficiently
• Contiguous allocation is one early method
• Main memory usually into two partitions (one for
the operating
• system and one for the user processes):
• Resident operating system, usually held in low
memory with interrupt vector
• User processes then held in high memory
21

06/02/2025
22

06/02/2025
23

06/02/2025
24

06/02/2025
Contiguous Allocation (Memory
Protection)
• Relocation registers used to protect user
processes from each other, and from
changing operating-system code and data
• Base register contains value of smallest
physical address
• Limit register contains range of logical
addresses – each logical address must be less
than the limit register
• MMU maps logical address dynamically
• The relocation-register scheme provides
an effective way to allow the operating
Dynamic Storage-Allocation
Problem

How to satisfy a request of size n from a list of free holes?


• First-fit: Allocate the first hole that is big
enough
• Best-fit: Allocate the smallest hole that is big
enough; must search entire list, unless ordered
by size
• Produces the smallest leftover hole
• Worst-fit: Allocate the largest hole; must
also search entire list
27

06/02/2025
Fragmentation
• As processes are loaded and removed from
memory, the free memory space is broken into little
pieces. Memory fragmentation can be internal as
well as external.
• External Fragmentation – exists when there is
enough total memory space to satisfy a request but
the available spaces are not contiguous:
• storage is fragmented into a large number of small
holes.
• Internal Fragmentation – allocated memory may
be slightly larger than requested memory; this size
29

06/02/2025
30

06/02/2025
Fragmentation (Cont.)
• Reduce external fragmentation by compaction
• Shuffle memory contents to place all free memory
together in one large block.
• Compaction is possible only if relocation is dynamic,
and is done at execution time
• Another possible solution to the external-
fragmentation problem is to permit the logical
address space of processes to be noncontiguous
(Paging)
• Fragmentation is a general problem in computing
that can occur wherever we must manage blocks
32

06/02/2025
Paging
• Physical address space of a process can be
noncontiguous; process is allocated physical
memory whenever the latter is available
• Avoids external fragmentation
• Avoids problem of varying sized memory
chunks
• Paging is implemented through cooperation
between the operating system and the
computer hardware.
Paging (Basic Method)
39

The basic method for implementing paging involves


• Divide physical memory into fixed-sized blocks called
frames
• Size is power of 2, between 512 bytes and 16 Mbytes
• Divide logical memory into blocks of same size called
pages
• Keep track of all free frames
• To run a program of size N pages, need to find N free
frames and load program
• Set up a page table to translate logical to physical
06/02/2025
addresses
Paging Model of Logical and Physical
Memory
Paging Example

n=2 and m=4 32-byte memory and 4-byte pages


43

06/02/2025
56
Example-1Consider page reference string 1, 3, 0,
3, 5, 6 with 3 page frames.Find number of page
faults.

06/02/2025
57

Initially all slots are empty, so when 1, 3, 0 came


they are allocated to the empty slots —> 3 Page
Faults.
when 3 comes, it is already in memory so —> 0
Page Faults.
Then 5 comes, it is not available in memory so it
replaces the oldest page slot i.e 1. —>1 Page
Fault.
6 comes, it is also not available in memory so it
replaces the oldest page slot i.e 3 —>1 Page
Fault.
Finally when 3 come it is not avilable so it replaces
0 1 page fault

06/02/2025
58

06/02/2025
Further Readings…
78

• Segmentation
• Virtual Memory
• Page Replacement
• Thrashing
• Operating System Examples

06/02/2025

You might also like