5. Any mechanism and policy associated
with memory management should satisfy
certain requirements. These requirements
are as follows:
Relocation
Protection
Sharing
55
6. The main memory is shared among
different processes in multi programming.
It is not possible to know that where the
program will be load in main memory
when it is executed.
The processes are also swapped in and
swapped out of main memory for
maximum utilization of processor.
66
7. The operating system need to know that
the location of the process control
information and execution stack.
The process of converting the Logical
address into Physical address is known as
Relocation.
77
8. In main memory many processes
being executed at one time.
Each process must be protected
against unwanted interference by
other processes.
The program in other processes should
not be able to reference the memory
location in a process to read and write
without permission.
88
9. The memory protection must be relaxed in
some cases.
Some time several processes may be
executing the same program such as an
editor.
The processes that cooperate to solve a
problem may want to access shared data
structures.
99
10. The processes that will participate in the
sharing must declare shared memory
segments.
The operating system is responsible for
protecting the shared memory from
unauthorized access by other processes.
1010
11. A process has a logical address space.
It is linear set of locations for program code,
variable and, stack and etc.
As the program executes, all parts of the
logical address space is mapped to a
physical address space.
Physical address space is a subset of primary
memory.
1111
12. The address space is a product of the
translation-linking-loading process.
Different types of addresses are as
follows:
Symbolic addresses
Logical addresses
Relative addresses
Physical addresses
1212
13. An address generated by the CPU is commonly
referred to as a Logical address where as an
address seen by the memory unit-that is, the one
loaded into the memory –address register of the
memory is commonly referred to as the Physical
address.
the set of all logical address generated by a
program from the Logical address space of the
process . The set of all Physical addresses
corresponding to these logical addresses is a
physical address space of the process.
1313
14. The total size of physical address space in
a system is equal to the size of main
memory.
The run-time mapping from virtual to
physical addresses is done by a piece of
hardware in the CPU, called the
memory management unit (MMU).
1414
16. Translation of a source program in a
high-level assembly language involves
compilation and linking of a program.
This process generates the machine
language executable code (also known as
binary image) for the give source program.
To execute the binary code, it is loaded into
the main memory and the CPU state is set
appropriately.
1616
17. The whole process is
shown in the
following diagram.
Compile/Assemble
Link
Load
Execute
1717
18. The collection of processes that is waiting on
the disk to be brought into the memory for
execution forms the Input queue.
In most cases a user program will go through
several steps –some of which may be optional-
before being executed.
Address may be bound in different ways.
1818
19. Address can be bound in instruction and data
at different time, as discussed below briefly.
Compile time: if you know at compile
where the process will reside in memory, the
absolute addresses can be assigned to
instructions and data by compiled.
Load time: if it is not know at compile time
where the processes will reside in memory
then the compiler must generate the re-
locatable code.
1919
20. Execution time: if the process can be moved
during its execution from one memory
segment to another, then binding must be
delayed until run time. Special hardware must
be available for this work.
In case of compile and load time binding, a
program may not be moved around in
memory at run time.
2020
22. Overlaying is a technique that is used to
execute a process even if the memory is
not enough.
The operating system can swap overlays
and manage the memory.
The overlays are useful when the program
to be executed is larger then available
memory.
2222
24. The earliest
computing system
required contiguous
storage allocation in
which each program
occupied single
contiguous memory
block, the technique
of multiprogramming
was not possible.
Main Memory
Process a
Operating
system
Figure of contiguous Memory
Process b
Process c
2424
25. In non-contiguous
storage allocation a
program is divided in
several blocks that
may be placed in
different parts of
main memory. It is
difficult for operating
system to control
non-contiguous
storage allocation.
Main Memory
Operating
system
Process a
Process b
Process c
Figure of non contiguous Memory
2525
26. A process cannot be executed in the CPU unless it
is completely or partly in memory. A process not
executed in CPU can be completely swapped out
of memory to a backing store such as a high-
speed disk.
The swapping is done by swapper.
Dispatcher tries to load a process into CPU and find
that it is not currently in memory.
It will call the swapper to swap the process back
into memory.
2626
28. The main memory must accommodate
both operating system and the various
user space. There are three schemes for
memory allocation these are:
Single process allocation scheme
Fixed partition allocation scheme
Variable partition allocation scheme
2828
29. In this scheme only
one process execute
in memory at a time.
The remaining part of
the memory space
will not be used.
User process
…………………
…………………
…………………
…………………
…………………
Unused
Operating
system
Loaded from
main storage
Main Memory
2929
30. This scheme
divided memory
into a number of
separate fixed
areas. Each
memory area
could hold one
process.
……………
……………
Process c
300k
……………
…………..
………….
Process b
200k
…………..…………..
Process a
150
Operating
system
Fixed partition
Partition:3
400k
Partition:2
300k
Partition:1
200k
………….
Unused
space
Memory
3030
31. The occurrence of
wasted space in
this way is called
internal
fragmentation.
It is called `Internal’
because it occurs
within the space
allocated to the
process in question.
Process b
Process A
………………..
………………..
Operating
system
……………….
………...…….
Internal
fragmentation
Example
3131
32. It is relatively simple to
implementation.
It facilitates memory
protection mechanism
due to its fixed
partitions.
The fixed partition sizes
can prevent a process
from being run due to
the unavailability of a
partition of sufficient
size.
Internal fragmentation
wastes space that
collectively could
accommodate
another process.
Advantages Disadvantages
3232
33. It allocate the
exact amount of
memory to the
process as
required.
………………………….
…Available space
………………………….
Operating system
Process A
Process B
Process C
Exact required
Size allocation
3333
34. If a new process D is
loaded then it is
allocated adjacent
to process C if
available space is
sufficient.
When a process
terminates, the
space it occupies is
freed and become
available for the
loading of a new
process.
..………………………
Operating system
Process A
Process B
Process C
Process D New process
Loaded from storage
3434
35. As processes come and go ,holes of
free space is created in the main
memory. Distribution of free memory
to processes is called External
fragmentation.
External fragmentation refers to the
situation when free memory space
exists to load a process in the memory
but the space is not contiguous.
3535
37. A process that is adjacent to one or more
holes may terminate and free its space
allocation.
The holes can be viewed and utilized as
a single hole. This effect is called
Coalescing holes.
In variable partition the system must keep
track of the position and size of each
hole.
3737
38. In this situation
linked list is a helper
key.
A common
method is use a
linked list.
A linked list
contains pointers to
the start of each
hole and the hole
size.
size
Process A
Process C
size
NIL
Free holes Linked List
::::::::::::::::::::::::
::::::::::::::::::::::::
::::::::::::::::::::::::
::::::::::::::::::::::::
Operating
system
3838
39. The fragmentation problem encountered in
the previous method the can be resolved by
physically moving the processes about the
memory in order to close up the holes.
It bring the free space into a single large
block.
This method is called compaction.
3939
40. Example
Process A
Process C
Process C
Process A
Operating
system
Operating
system
ordered
Memory before compaction Memory after compaction
4040
41. A process must be unloaded from
memory if its CPU time-slice has ended. It
is placed in the ready queue to be
loaded again later. It allows the memory
space for another process to be loaded.
A process can change place in memory for
the following three main reasons:
4141
42. A process must be unload from memory if
it enters block state by calling I/O
function etc. then it is placed in the block
queue to be loaded later.
The process may change its position if
compaction is applied.
It must be possible for a process to be
loaded at any address selected by the
operating system.
4242
43. The Limit register is used to hold the
highest memory location that a process
can access. By this way, each process is
protected from other processes in
memory.
A Logical address is expressed as a
location relative to the beginning of the
process. Instructions in the program
contain only logical address.
4343
44. A Physical address is an actual location
in main memory.
When a process is loaded in memory, the
physical address of the first location is
put in the base register. All processes are
interpreted as a being relative to this
base address.
4444
46. Physical memory is divided into fixed-size
blocks called frames.
Logical memory is also divided into the same
size blocks called pages.
A single process may require many pages of
memory.
When a process is scheduled for execution, its
pages are loaded into any available memory
frames from the backing store.
4646
47. The backing store is also divided into
blocks.
The blocks are the same size as the frames
in main memory.
Paging requires additional hardware
support in the form of a page table.
4747
48. Every logical address generated by the CPU
consist of two parts:
A Page Number (p)
A page displacement offset (d)
The page table consist the frame number (f)
of each page in physical memory. The
frame number is combined with the page
offset to obtain the physical memory
address of memory location and object
address by the corresponding logical
address.
4848
49. P is use to index the process page table;
page table entry contains the frame
number ,f, where page p is load.
The physical address of the location
referenced by (p , d) is computed by
appending d at the end of f as shown
below:
ff dd
4949
50. Assume a logical address space of 16
pages of 1024 words, each mapped into
a physical memory of 32 frames. Here is
how you calculate the various
parameters related to paging
No: of bits needed for p = ceiling [log2
16] bits = 4
bits
No: of bits needed for f = ceiling [log2 32]
bits = 5 bits
5050
53. Segmentation is a process that breaks a
program into logical segments and allocates
the space for these segments in memory
separately. The segment can be of variable
length. They may not be contiguous memory.
The segments are more flexible. They are
visible for programmers. The programmer can
use them to tell the system to bring certain
data into memory always together.
5353
54. A segment table is maintained which
contain information about every segment
in a user program (process) . Each entry in
the segment table contains a base value
and a limit value . The base value contain
the actual physical address in memory
where the segment currently resides. The
limit value contain the size of the
segment .
5454