OS UNIT 5
OS UNIT 5
Main Memory
• It is work house of the memory System. It is also known as physical
memory.
• It comes in the form of chips internally in computer system.
• Main memory is the middle layer in the memory hierarchy of computer
system.
• It is slower and cheaper compare cache memory while
faster and costly compared to disks.
• Main Memory generally consists of RAM (Random
Access Memory).
• It is volatile it means it needs to have electrical power
in order to maintain its information..
• Random: means that any piece of data from this
memory can be accessed quickly in constant time.
• Main memory has limited storage capacity (64–512
MB – now 1 GB).
• Entire Main memory consider as sequential list of
bytes. Each byte has an address that is used to locate
it, this address is called physical address. Each byte
has an address in registers.
• The address for most computer system starts at 0 and
go up in sequence until each byte has an address.
Partitioning
• An important operation of memory management is to bring programs into
main memory for execution by the processor.
• Partitioning is a technique that divides a memory into multiple partitions.
• These partitions can be of different size or same size.
• Types of partitioning
Fixed partitioning i.e. static partitioning
Variable partitioning i.e. dynamic partitioning
Page tables
Physical Address Space = M words
Logical Address Space = L words
Page Size = P words
Physical Address = log 2 M = m bits
Logical Address = log 2 L = l bits
page offset = log 2 P = p bits
Difference–Logical Address Vs Physical Address
• Ex1- Suppose CPU has generates some logical address, and is given
form of(segment no , offset )- L=(2,125)
• To get physical address related to logical address, segment table will be
searched to get entry of segment no 2.
• For segment 2 ,base is 4300 and limit is 400,
• Offset compared with limit value ( 125 < 400)
• So, offset is valid
• Physical address (P) = offset + base = 125 + 4300=4425
• Ex2- Suppose CPU has generates some logical address, and is given
form of (segment no , offset )- L=(2,410)
• To get physical address related to logical address, segment table will be
searched to get entry of segment no 2.
• For segment 2 ,base is 4300 and limit is 410,
• Offset compared with limit value ( 125 > 410)
• So, offset is not valid.
• so physical address can not be generated.
Segmentation Advantages
• All segments are independent from each other, so segments can grow and
shrink without affecting other segments.
• If procedure in one segment is modified and recompiled, no other
segments need to be changed or recompiled.
• Sharing of procedure and data between various processes is simple.
• Different segment of a single process can be given different kind of
protection. One segment can be read only, while another can be writable.
• No internal fragmentation because segments are allocated exactly as
much memory as required.
Segmentation Disadvantages
• It is still expensive to allocate contiguous free memory to segments.
• External fragmentation is possible, which requires memory
defragmentation or compaction.
External Fragmentation
• It refers to the wastage of free memory
between partitions, caused by scattered non-
contiguous free space.
• This is a severe problem in contiguous
memory allocation method with dynamic
partitioning.
• Memory allocation and de-allocation
operations eventually result in small holes in
the memory.
• These holes will be so small that no any
processes can be loaded in it. But, total size
of all memory wastage is called External
• Fragmentation.
• Solution- the occupied memory by processes
are shuffled, to this problem is to collect all
the free memory together in one larger block
or linked representation.
Internal Fragmentation
• It refers to the wastage of free memory within an partitions, caused by the
difference between the size of a partition and the size of a process loaded.
• This is a severe problem in contiguous memory
allocation method with fixed partitioning.
• The partitions are of fixed size. So any space in
a partition not used by a process is wasted. This
is called Internal Fragmentation.
• Ex- A process of 10 mb is allocated to a fixed
size partition of 12MB. SO here remaining 2MB
space remains unused and it will be wasted. It
cannot be used for any othe process.
• The Solution to this problem is to use dynamic
partitioning where a process is allocated exactly
as much memory as required
Virtual Memory
o Virtual memory is a memory management capability of an
operating system (OS) that uses hardware and software to allow a
computer to compensate for physical memory shortages by
temporarily transferring data from random access memory
(RAM) to disk storage.
OR
o Virtual memory is the separation of user logical memory from physical
memory.
o This separation allows an extremely large virtual memory to be provided
for programmers when only a smaller physical memory is available.
o Virtual memory makes the task of programming much easier, because the
programmer no longer needs to worry about the amount of physical
memory available, or about what code can be placed in overlays, but can
concentrate instead on the problem to be programmed.
o A virtual memory is a technique that allows a process to execute even
though it is partially loaded in main memory.
o Virtual memory removes the requirement that an entire process should be
in main memory for its execution.
o Process size can be larger than the size of main memory.
o Logical addresses are referred as virtual addresses.
o Logical address space of a process is referred as virtual address space.
Virtual address space can be larger than the physical memory.
o Physical Address –
Paging Disadvantages
o Additional memory reference is required to read information from page
table .Two memory access required one for page table and second for
instruction or data.
o If process is of large size then page table of that process also have large
size. It may be too large to keep such page table in memory.
o A process size may not be an exact multiple of the page size. it may be
possible that space within partitions (page) remain unused by process
because of differ in page size and part of process loaded in that page . So
this paging result in from internal fragmentation
Demand Paging
o Demand paging system is similar to paging with swapping.
o The processes are kept on secondary storage, i.e. on disk.
o To execute a process, it is swapped into the memory.
o But, rather swapping the entire process into memory, only pages, which
are required for execution, are swapped.
o Page table includes the valid-invalid Bit for each page entry.
o If it is set to valid, it indicates that the page is currently present in the
memory.
o If it is set to invalid, it indicates that the page is still not loaded in the
memory.
o When a process starts its execution, this bit is set to invalid for all the
entries in the page table.
o When a page is loaded in memory, its corresponding frame number is
entered and page validity bit is set to valid.
o Whenever a logical address (virtual address) is generated, the system
operates as follows:
1. Page table is searched. If the page validity bit is set to valid,
corresponding frame number is fetched, page offset is added to it, and
physical address is determined.
2. If the page validity bit is set to invalid, then operating system reads the
page into a free frame from disk. If no frame is available, it uses a
replacement algorithm to replace an occupied frame.
****************************************************************