9th Lecture OS
9th Lecture OS
CS(407)
Lecture 9
Memory management
Instructor
Sibgha Zia
Department of Computer Science
UAF Sub Campus Burewala
Memory management
Memory management is the functionality of an operating system which manages
primary memory and moves processes back and forth between main memory
and disk during execution.
The base register is now termed a relocation register, whose value is added
to every memory request at the hardware level.
Note that
User programs never see physical addresses.
User programs work entirely in logical address space, and any
memory references or manipulations are done using purely logical
addresses. Only when the address gets sent to the physical memory
chips is the physical memory address generated
Logical vs. Physical Address Space
● 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 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 generated by a program
Compile time address binding is done before loading the program into memory.
Load time address binding is done after loading the program into memory.
Different types of memory management
Single partition allocation :one processes in memory.
No operation
Operation system + one process
Placement strategies
Where in primary memory should data be placed.
First fit.
Best fit.
Worst fit.
Replacement strategies
For example, if a user process needs some x bytes of contiguous memory, then all
the x bytes will reside in one place in the memory that is defined by a range of
memory addresses: 0x0000 to 0x00FF.
Non-Contiguous memory
Non-Contiguous memory allocation allocates separate blocks of
memory to a file/process.
In this scheme, the process is divided into several blocks and then
these blocks are placed in different parts of the memory according to
the availability of memory space.
The size of a frame should be kept the same as that of a page to have
maximum utilization of the main memory and to avoid external
fragmentation. Paging is used for faster access to data, and it is a logical
concept.
Every logical address generated by CPU consists of two parts.
I. A page number (p)
II. A page displacement (d)
Page Replacement Algorithms
Example of Paging
For example, if the main memory size is 16 KB and Frame size is 1 KB.
Here, the main memory will be divided into the collection of 16 frames
of 1 KB each.
There are 4 separate processes in the system that is A1, A2, A3, and A4
of 4 KB each. Here, all the processes are divided into pages of 1 KB
each so that operating system can store one page in one frame.
At the beginning of the process, all the frames remain empty so that all
the pages of the processes will get stored in a contiguous way
Paging Conceptual view
In this example you can see that A2 and A4 are moved to the waiting state after some time.
Therefore, eight frames become empty, and so other pages can be loaded in that empty blocks.
The process A5 of size 8 pages (8 KB) are waiting in the ready queue.
Fragmentation
A fragmentation is define as when the process is loaded and
removed after execution from memory, it creates a small free
hole. These holes can not be assigned to now process because
holes are not combine or do not fulfill the memory
requirement of the process.
To achieve a degree of multiprogramming, we must reduce
the waste of memory or fragmentation problem.
Types of Fragmentation
There are two types of fragmentation called
Internal fragmentation
External fragmentation
Fixed Partitioning
Internal fragmentation
Internal fragmentation
Occur when fixed size memory blocks are allocated to a process
The memory block allocated to a process is larger than required.
It causes some portion of memory to left unused. This left space
cannot be allocated to another process.
Example
Suppose, we want to allocate memory to a process of size 8 MB and as In
the above diagram, we can see that, there is enough space that is 9 MB to
run a process of size 8MB but the memory that is fragments are not
contiguous.
There is a solution for the problem of External Fragmentation and it
is Compaction.
External Fragmentation
External Fragmentation
Segmentation
Segmentation is a memory management technique which divides
each process into several segments or sections of different sizes. A
segment can be a main program, function, stacks, symbol tables, data
structures, etc.
Every segment is a different logical address space of the program.
These segments are of variable length size. In other words, the
segments are not fixed in size.
Segmentation