Unit-1
Unit-1
MCS-041
Block-2
Unit-1
Topics to be covered
Principles of Operation
Page Allocation
Segmentation
Principles of Operation
Address Translation
Memory management provides protection by using two registers, a base register and a limit
register. The base register holds the smallest legal physical memory address and the limit
register specifies the size of the range. For example, if the base register holds 300000 and the
limit register is 1209000, then the program can legally access all addresses from 300000
through 411999.
OVERLAYS
AND
SWAPPING
Overlay
Overlaying means "replacement of a block of stored instructions or data with
another." Overlaying is a programming method that allows programs to be larger than the
computer's main memory. Overlay gives the program a way to extend limited main storage.
Limitations of Overlays:
Require careful and time-consuming planning.
Programmer is responsible for organizing overlay structure of program with the help of file
structures etc. and also to ensure that piece of code is already loaded when it is called.
Operating System provides the facility to load files into overlay region.
Example of Overlay
Suppose total available memory is 140K. Consider a program with four subroutines named
as: Read ( ), Function1( ), Function2( ) and Display( ). First, Read is invoked that reads a
set of data. Based on this data set values, conditionally either one of routine Function1 or
Function2 is called. And then Display is called to output results. Here, Function1 and
Function2 are mutually exclusive and are not required simultaneously in memory.
Without the overlay it requires 180 K of memory and with the overlay support memory
requirement is 130K.
Major time consuming part of swapping is transfer time. Total transfer time is directly
proportional to the amount of memory swapped. Let us assume that the user process is of size
100KB and the backing store is a standard hard disk with transfer rate of 1 MB per second. The
actual transfer of the 100K process to or from memory will take
100KB / 1000KB per second
= 1/10 second
= 100 milliseconds
Swapping
Benefits of Swapping
• Allows dynamic relocation, i.e., if address binding at execution time is being used
we can swap in different location else in case of compile and load time bindings
performance.
LOGICAL
VS.
PHYSICAL
ADDRESS SPACE
Logical & Physical Address Space
An address generated by the CPU is a logical address whereas address actually available on
memory unit is a physical address. Logical address is also known a Virtual address.
Virtual and physical addresses are the same in compile-time and load-time address-binding
The set of all logical addresses generated by a program is referred to as a logical address
space. The set of all physical addresses corresponding to these logical addresses is referred to
The run-time mapping from virtual to physical address is done by the memory
management unit (MMU) which is a hardware device. MMU uses following
mechanism to convert virtual address to physical address.
The value in the base register is added to every address generated by a user
process which is treated as offset at the time it is sent to memory. For example, if
the base register value is 10000, then an attempt by the user to use address
location 100 will be dynamically reallocated to location 10100.
The user program deals with virtual addresses; it never sees the real physical
addresses.
SINGLE PROCESS
MONITOR
(MONOPROGRAMMING)
In the simplest case of single-user system everything was easy as at a time there
was just one process in memory and no address translation was done by the
operating system dynamically during execution. Protection of OS (or part of it) can
This approach keeps the Operating System in the lower part of the memory and other user
processes in the upper part. With this scheme, Operating System can be protected from
useful for this purpose. It not only protects user processes from each other but also from
changing OS code and data. Two registers are used: relocation register, contains value of
the smallest physical address and limit register, contains logical addresses range. Both these
process 8 process 10
Statistics:
First-fit and best-fit better than worst-fit in terms of speed and
storage utilization
Fragmentation: for N allocated blocks, another N/2 wasted due to
fragmentation
Fragmentation
• 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.
– I/O problem
– Can be very slow: 256MB of memory, copy 4 bytes in 40ns compacting memory in
2.7 sec
important to know the best location from the list of available/free holes. This dynamic storage
allocation is necessary to increase efficiency and throughput of system. Most commonly used
1) Best-fit Policy: Allocating the hole in which the process fits most “tightly” i.e., the difference
between the hole size and the process size is the minimum one.
2) First-fit Policy: Allocating the first available hole (according to memory order), which is big
3) Worst-fit Policy: Allocating the largest hole that will leave maximum amount of unused space
2) The displacement (or offset) in page p at which item resides (i.e., from start of page).
The table, which holds virtual address to physical address translations, is called the page table.
required.
Paging Translation
logical address
virtual page # offset
physical memory
page
page table frame 0
page
frame 1
physical address
page
page frame # F(PFN) offset frame 2
page
frame 3
…
page
frame Y
Paging address Translation by direct
mapping
This is the case of direct mapping as page table sends directly to physical memory
page. But disadvantage of this scheme is its speed of translation. This is because
page table is kept in primary storage and its size can be considerably large which
increases instruction execution time (also access time) and hence decreases system
speed. To overcome this additional hardware support of registers and buffers can be
used.
Paging Address Translation with
Associative Mapping
This scheme is based on the use of dedicated registers with high speed and efficiency. These
small, fast-lookup cache help to place the entire page table into a content-addresses associative
storage, hence speed-up the lookup problem with a cache. These are known as associative
registers or Translation Look-aside Buffers (TLB’s). Each register consists of two entries:
It is similar to direct mapping scheme but here as TLB’s contain only few page table entries, so
Paging hardware typically also contains some protection mechanism. In page table
corresponding to each frame a protection bit is associated. This bit can tell if page is read-
only or read-write.
Sharing code and data takes place if two page table entries in different processes point to
same physical page, the processes share the memory. If one process writes the data, other
process will see the changes. It is a very efficient way to communicate. Sharing must also be
controlled to protect modification and accessing data in one process by another process. For
this programs are kept separately as procedures and data, where procedures and data that are
Virtual address space must be greater than main memory size. i.e., can execute program
with large logical address space as compared with physical address space.
Also, extra resource consumption and overheads for paging hardware and virtual
length
offset
dynamic partitioning
Address Translation
This mapping between two is done by segment table, which contains segment base and its
limit. The segment base has starting physical address of segment, and segment limit
This scheme is similar to variable partition allocation method with improvement that the
process is divided into parts. For fast retrieval we can use registers as in paged scheme.
The segments in a segmentation scheme correspond to logical divisions of the process and
Extract the segment number and offset from logical address first. Then use segment
number as index into segment table to obtain segment base address and its limit /length.
Also, check that the offset is not greater than given limit in segment table.
Now, general physical address is obtained by adding the offset to the base address.