Operatin
g
Systems:
Internals Lecture 7
and Memory
Design
Principles Management
Joram M. Makasa
Table 7.1
Memory Management Terms
Memory Management
Requirements
Memory management is intended to
satisfy the following requirements:
Relocation
Protection
Sharing
Logical organization
Physical organization
1.Relocatio
n
Programmers typically do not know in advance which other
programs will be resident in main memory at the time of
execution of their program
Active processes need to be able to be swapped in and out
of main memory in order to maximize processor utilization
Specifying that a process must be placed in the same
memory region when it is swapped back in would be
limiting
may need to relocate the process to a different area
of memory
The reference
contains the
address of
the data – the
address in
the code has
to be
translated to
the physical
location
Execution
stack
2.Protection
Processes need to acquire permission to reference memory
locations for reading or writing purposes (protection against
accidental or intentional)
Location of a program in main memory is unpredictable-
satisfying relocation makes it hard to satisfy protection
Memory references generated by a process must be
checked at run time in order to refer to only memory space
allocated to the process at run time
Mechanisms that support relocation also support protection
Memory protection requirement is satisfied by the processor
but not the OS , it cannot anticipate future memory
references this could be time consuming e.g. by aborting a
3.Sharing
Advantageous to allow each process access to the
same copy of the program rather than have their own
separate copy
Memory management must allow controlled access to
shared areas of memory without compromising
protection
Mechanisms used to support relocation support
sharing capabilities
4. Logical Organization
Memory is organized as linear(one dimensional address
space)
Programs are written in modules-Advantages:
•modules can be written and compiled independently
•different degrees of protection given to modules (read-only, execute-only)
•sharing on a module level corresponds to the user’s way of viewing the problem
Segmentation (memory management technique) is the
tool that most readily satisfies the requirements above
Physical
Organization
Cannot leave the Memory available Programmer does
programmer with for a program plus not know how
the responsibility to its data may be much space will be
manage memory insufficient available
overlaying allows
various modules to be
Highest level of assigned the same
region of memory but
memory is time consuming to The flow of information
organization: program
between these two types
-main of memories is of concern.
memory( for The programmer cannot
temporary use manage memory because
-secondary of the above reasons
memory (for
permanent use) Movement of data between the two memories is a task of
memory management
Memory Partitioning
Memory management key operations is to bring
processes into main memory for execution by the
processor
involves virtual memory
Which is based on segmentation and paging
Partitioning- is a simpler technique
used in several variations in some now-obsolete
operating systems
does not involve virtual memory
Table 7.2
Memory
Management
Techniques
(Table is on page 315 in
textbook)
Disadvantages
A program may be too big to fit in a partition
program needs to be designed with the use of
overlays (larger than RAM)
Main memory utilization is inefficient
any program, regardless of size, occupies an
entire partition
internal fragmentation
wasted space due to the block of data loaded
being smaller than the partition
Note –
unequal
Use of a partitions
scheduling
queue for
each
partition is
required
Minimizes wasted memory within a partition but partitions that do not get
their size of processes remain unused
Disadvantages
Thenumber of partitions specified at
system generation time limits the
number of active processes in the
system
Small jobs will not utilize partition space
efficiently
Dynamic
Partitioning
Partitions are of variable length and number
Process is allocated exactly as much memory
as it requires
This technique was used by IBM’s mainframe
operating system, OS/MVT
Dynamic
Partitioning
External Fragmentation
• memory becomes more and more fragmented
• memory utilization declines
Compaction
• technique for overcoming external fragmentation
• OS shifts processes so that they are contiguous
• free memory is together in one block
• time consuming and wastes CPU time
Placement
Algorithms
Best-fit First-fit Next-fit
•chooses •begins to •begins to scan
scan memory memory from
the block from the the location of
the last
that is beginning and
placement and
closest in chooses the chooses the
first available next available
size to the block that is block that is
request large enough large enough
Buddy
System
Fixed partitioning scheme limits the number of active
processes and may use space inefficiently and dynamic
partitioning is more complex to maintain and has
overhead of compaction
Buddy is a better option which is comprised of fixed and
dynamic partitioning schemes
Space available for allocation is treated as a single
block
Memory blocks are available of size 2K words, L ≤ K ≤
U, where
2L = smallest size block that is allocated
2U = largest size block that is allocated; generally 2U is the size of
the entire memory available for allocation
Leaf nodes
represent
the current
partitioning
of memory
Addresses
Logical address- is generated by the CPU
• reference to a memory location independent of the current assignment of
data to memory-requires translation to physical addresses
Relative-type of logical address
• address is expressed as a location relative to some known point,
usually a value in a processor register.
Physical or Absolute
• actual location in main memory
Relative Address Translation
Addresses of
instructions and
Process is data
assigned to a
running state-
the BR has the
starting
address.BR is
a special
processor
register Indicates the
ending
location of a
program
If the address is
within bounds,
execution
continues
otherwise ,
interrupt to the OS
occurs
Paging
Both fixed-size and variable-size partitions are inefficient in
use of memory, say how
Partitions of memory of equal fixed-size chunks that are
relatively small is called frames
Process is also divided into small fixed-size chunks of the
same size called pages
Pages Frames
•chunks of •available
chunks of
a process memory
Page Table
Base address register is not sufficient but a page table
is maintained by operating system for each process
Contains the frame location for each page in the
process
Processor must know how to access for the current
process
Page table is used by processor to produce a physical
address-translation of logical to physical address for
pages is done
Four
pages
Segmentation
A program can be subdivided into segments
may vary in length
there is a maximum length
Addressing consists of two parts:
segment number
an offset
Similar
to dynamic partitioning (because of
unequal size)
Eliminates internal fragmentation
Segmentation
Usually visible to the programmer, he/she can
assign a program and data to different
segments
Provided as a convenience for organizing
programs and data
For purposes of modular programming the
program or data may be further broken down
into multiple segments
the principal inconvenience of this service is that the
programmer must be aware of the maximum segment
size limitation
Address Translation
Another consequence of unequal size segments
is that there is no simple relationship between
logical addresses and physical addresses
The following steps are needed for address
translation:
Extract the Use the segment Compare the offset, The desired
number as an index expressed in the physical address is
segment rightmost m bits, to
into the process the sum of the
number as the segment table to
the length of the
segment. If the offset starting physical
leftmost n bits of find the starting address of the
is greater than or
the logical physical address of equal to the length, segment plus the
address the segment the address is invalid offset
Summary
Memory management Memory
requirements partitioning
relocation
fixed
protection
sharing
partitioning
dynamic
logical
organization partitioning
physical buddy system
organization relocation
Paging Segmentation