CH 7Memory$Device MNGT
CH 7Memory$Device MNGT
06/02/2025
Main Memory
2
• Background
• Swapping
• Contiguous Memory Allocation
• Segmentation
• Paging
06/02/2025
Objectives
3
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
06/02/2025
7
06/02/2025
8
06/02/2025
Cont…
9
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
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
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
06/02/2025
58
06/02/2025
Further Readings…
78
• Segmentation
• Virtual Memory
• Page Replacement
• Thrashing
• Operating System Examples
06/02/2025