0% found this document useful (0 votes)
54 views20 pages

Main Memory

This document discusses memory management techniques in computer systems. It introduces the concepts of logical and physical address spaces, and how they are mapped using base and limit registers or segment tables. It describes different strategies for allocating memory to processes, such as contiguous allocation, multiple partition allocation using first-fit and best-fit approaches, and how this can lead to internal and external fragmentation. It also discusses dynamic relocation of processes using swapping.

Uploaded by

S.M. SIAM
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)
54 views20 pages

Main Memory

This document discusses memory management techniques in computer systems. It introduces the concepts of logical and physical address spaces, and how they are mapped using base and limit registers or segment tables. It describes different strategies for allocating memory to processes, such as contiguous allocation, multiple partition allocation using first-fit and best-fit approaches, and how this can lead to internal and external fragmentation. It also discusses dynamic relocation of processes using swapping.

Uploaded by

S.M. SIAM
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/ 20

Presented by

Main Memory
Mohiuddin Ahmed
Lecturer
Department of CSE
RUET
 A pair of base and limit registers define the logical address space
 CPU must check every memory access generated in user mode to be sure it is between base and limit
for that user
 Programs on disk, ready to be brought into memory to execute form an input queue
 Without support, must be loaded into address 0000

 Inconvenient to have first user process physical address always at 0000


 How can it not be?

 Further, addresses represented in different ways at different stages of a program’s life


 Source code addresses usually symbolic
 Compiled code addresses bind to relocatable addresses
 i.e. “14 bytes from beginning of this module”
 Linker or loader will bind relocatable addresses to absolute addresses
 i.e. 74014
 Each binding maps one address space to another
 Address binding of instructions and data to memory addresses can happen at three
different stages
 Compile time: If memory location known a priori, absolute code can be generated; must
recompile code if starting location changes
 Load time: Must generate relocatable code if memory location is not known at compile time
 Execution time: Binding delayed until run time if the process can be moved during its execution
from one memory segment to another
 Need hardware support for address maps (e.g., base and limit registers)
 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 address space is the set of all logical addresses generated by a program
 Physical address space is the set of all physical addresses generated by a program
 Hardware device that at run time maps virtual to physical address
 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

 Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority
process is swapped out so higher-priority process can be loaded and executed
 Main memory must support both OS and user processes
 Limited resource, must allocate efficiently
 Contiguous allocation is one early method
 Main memory usually into two partitions:
 Resident operating system, usually held in low memory with
interrupt vector
 User processes then held in high memory
 Each process contained in single contiguous section of memory
 Multiple-partition allocation
 Degree of multiprogramming limited by number of partitions
 Variable-partition sizes for efficiency (sized to a given process’ needs)
 Hole – block of available memory; holes of various size are scattered throughout memory
 When a process arrives, it is allocated memory from a hole large enough to accommodate it
 Process exiting frees its partition, adjacent free partitions combined
 Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
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
 Produces the largest leftover hole

First-fit and best-fit better than worst-fit in terms of speed and storage utilization
 External Fragmentation – total memory space exists to satisfy a request, but it is
not contiguous
 Internal Fragmentation – allocated memory may be slightly larger than requested
memory; this size difference is memory internal to a partition, but not being used
 First fit analysis reveals that given N blocks allocated, 0.5 N blocks lost to
fragmentation
 1/3 may be unusable -> 50-percent rule
 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
 I/O problem
 Latch job in memory while it is involved in I/O
 Do I/O only into OS buffers
 Memory-management scheme that supports user view of memory
 A program is a collection of segments
 A segment is a logical unit such as:

main program
procedure
function
method
object
local variables, global variables
common block
stack
symbol table
arrays
1
1 4
2

3
4 2

user space physical memory space


 Logical address consists of a two tuple:
<segment-number, offset>,

 Segment table – maps two-dimensional physical addresses; each table entry has:
 base – contains the starting physical address where the segments reside in memory
 limit – specifies the length of the segment

 Segment-table base register (STBR) points to the segment table’s location in


memory

 Segment-table length register (STLR) indicates number of segments used by a


program;
segment number s is legal if s < STLR
 Protection
 With each entry in segment table associate:
 validation bit = 0  illegal segment
 read/write/execute privileges

 Protection bits associated with segments; code sharing occurs at


segment level
 Since segments vary in length, memory allocation is a dynamic storage-
allocation problem
 A segmentation example is shown in the following diagram

You might also like