memory management


https://drive.google.com/file/d/19EQC9bpAaSE4v0q2-mhjFPVXtwdG51EZ/view?usp=sharing
This is for my college preparation. I use it for my personal use only nothing else.

1.What is logical and physical address ?
 An address generated by the CPU is called a logical address.
Where as an address generated by the memory management unit , is called physical    address.
Example
Suppose a program is written by a user which size is 100kb and it loaded in memory from 2100-2200.
 So,here 0-100kb is the logical address and 2100-2200 is the physical address.

Physical address space =logical address+content of relocation register.

2.Draw the figure of memory hierarchy?
3.What is compile time, load time and execution time ?
Suppose  a program is x.
X needs to be compiled before it can be run. So you use a compiler (say GCC) to compile it. 
The time that GCC takes to compile X into an executable binary is called compile time.
When you execute X after compiling it, the time that the OS takes to actually load it into
 memory (and possibly do some dynamic linking) is load time.
Finally the program X is executed on the hardware. The time that it takes to complete is 
run time.
If you're actually working on compiler internals (i.e., changing the compiler itself),
 you might be interested in how fast your compiler compiles code. In such a scenario, the 
compiler's run time might matter to you. It is still typically referred to as compile time
 though (as its the compiler that is running !).

4.
Fixed Size partition:
Fixed Partitioning:
This is the oldest and simplest technique used to put more than one processes in the main memory.
 In this partitioning, number of partitions (non-overlapping) in RAM are fixed but the size of each 
partition may or may not be the same. As it is contiguous allocation, hence no spanning is allowed.
 Here partition are made before execution or during system configure.


As illustrated in above figure, first process is only consuming 1MB out of 4MB in the main memory.
Hence, Internal Fragmentation in first block is (4-1) = 3MB.
Sum of Internal Fragmentation in every block = (4-1)+(8-7)+(8-7)+(16-14)= 3+1+1+2 = 7MB.
Suppose process P5 of size 7MB comes. But this process cannot be accommodated inspite of
 available free space because of contiguous allocation (as spanning is not allowed). Hence, 
7MB becomes part of External Fragmentation.
There are some advantages and disadvantages of fixed partitioning.
Advantages of Fixed Partitioning –
  1. Easy to implement:
    Algorithms needed to implement Fixed Partitioning are easy to implement. It simply 
    requires putting a process into certain partition without focussing on the emergence of
     Internal and External Fragmentation.
  2. Little OS overhead:
    Processing of Fixed Partitioning require lesser excess and indirect computational power.
Disadvantages of Fixed Partitioning –
  1. Internal Fragmentation:
    Main memory use is inefficient. Any program, no matter how small, occupies an entire partition.
     This can cause internal fragmentation.
  2. External Fragmentation:
    The total unused space (as stated above) of various partitions cannot be used to load the 
    processes even though there is space available but not in the contiguous form (as spanning 
    is not allowed).
  3. Limit process size:
    Process of size greater than size of partition in Main Memory cannot be accommodated. 
    Partition size cannot be varied according to the size of incoming process’s size. Hence,  
    process size of 32MB in above stated example is invalid.
  4. Limitation on Degree of Multiprogramming:
    Partition in Main Memory are made before execution or during system configure. 
    Main Memory is divided into a fixed number of partitions. Suppose if there are partitions in
     RAM and are the number of processes, then condition must be fulfilled. Number of processes 
    greater than number of partitions in RAM is invalid in Fixed Partitioning.

Variable Partition:
Variable Partitioning –
It is a part of Contiguous allocation technique. It is used to overcome the problem faced by 
Fixed Partitioning. In contrast with fixed partitioning, partitions are not made before the execution
 or during system configured. Various features associated with variable Partitioning-


  1. Initially RAM is empty and partitions are made during the run-time according to process’s 
    need instead of partitioning during system configured.
  2. The size of partition will be equal to incoming process.
  3. The partition size varies according to the need of the process so that the internal fragmentation
     can be avoided to ensure efficient utilisation of RAM.
  4. Number of partitions in RAM is not fixed and depends on the number of incoming process and
     Main Memory’s size.
There are some advantages and disadvantages of variable partitioning over fixed partitioning as given
 below.
Advantages of Variable Partitioning –
  1. No Internal Fragmentation:
    In variable Partitioning, space in main memory is allocated strictly according to the need of  
    process, hence there is no case of internal fragmentation. There will be no unused space left 
    in the partition.
  2. No restriction on Degree of Multiprogramming:
    More number of processes can be accommodated due to absence of internal fragmentation. 
    A process can be loaded until the memory is not empty.
  3. No Limitation on the size of the process:
    In Fixed partitioning, the process with the size greater than the size of the largest partition 
    could not be loaded and process can not be divided as it is invalid in contiguous allocation 
    technique. Here, In variable partitioning, the process size can’t be restricted since the partition
     size is decided according to the process size.
Disadvantages of Variable Partitioning –
  1. Difficult Implementation:
    Implementing variable Partitioning is difficult as compared to Fixed Partitioning as it involves
     allocation of memory during run-time rather than during system configured.
  2. External Fragmentation:
    There will be external fragmentation in spite of absence of internal fragmentation.
    For example, suppose in above example- process P1(2MB) and process P3(1MB) completed
     their execution. Hence two spaces are left i.e. 2MB and 1MB. Let’s suppose process P5 of size
     3MB comes. The empty space in memory cannot be allocated as no spanning is allowed in contiguous allocation. The rule says that process must be contiguously present in main memory to get executed. Hence it results in External Fragmentation.



    Now P5 of size 3 MB cannot be accommodated in spite of required available space because
     in contiguous no spanning is allowed.



i)Internal fragmentation.
ii)process size limitation.
iii)Limitation on degree of multiprogramming 


5.What is Internal and External Fragmentation ?  

Internal Fragmentation
  1. When a process is allocated more memory than required, few space is left unused and this 
    is called as INTERNAL FRAGMENTATION.
  2. It occurs when memory is divided into fixed-sized partitions.
It can be cured by allocating memory dynamically or having partitions of different sizes.5
External Fragmentation
1.It occurs when memory is divided into variable-sized partitions based on the size of proce
2.It can be cured by Compaction, Paging and Segmentation./



6.What is compaction?
It is a technique of collection of all the free spaces together in one block.This block of partition can  
be  allocated to some other job.It is the solution of the external fragmentation.

So, we can use partition 1 and partition 2 as one block and and we can allocate the memory 
for process p5.

7.What is fist fit, best fit and worst fit?

First fit:
Search the list of available memory and locate the job in the first available partition.

Best fit:
Search the entire partition and allocate a job in such a partition that internal fragmentation will be 
minimized.Choose the closet space for each.

Worst fit:
Search the entire partition and allocate a job in such a partition that internal fragmentation will be
 maximum.Choose the larger space for each.
8.what is virtual memory ?
Virtual memory is a technique which allows the execution of a process given logical 
address space is greater than physical available memory.

 The formula is (size of ram*1.5*1024)mb
Example:
If a program size in logical space is 15 mb but the available memory 12mb. So 12 mb loaded
 in the memory and the remaining 3mb will be loaded into the secondary memory. 
When the remaining 3 mb will be  needed for execution then swap out 3 mb from main
 memory to secondary memory and swap in 3 mb for secondary memory to main memory.
Advantages of Virtual Memory:

  • Allocating memory is easy and cheap
  • Degree of multiprogramming is increased
  • Os make speed up the execution of process by allocating more physical memory.
  • Eliminates external fragmentation
  • Data (page frames) can be scattered all over PM
  • Pages are mapped appropriately anyway
  • Large programs can be written, as virtual space available is huge compared to physical
     memory.
  • Less I/O required, leads to faster and easier swapping of processes.
  • More physical memory available, as programs are stored on virtual memory, so they 
    occupy very less space on actual physical memory.
  • More efficient swapping




9.What is Page Fault?
A page fault occurs when a program attempts to access the memory block/data which is not available 
in it physical memory/ram.

Then os check  it is valid or not.If it is valid the data must be located in virtual memory. Then the data
 transfer from secondary device to  the system ram.
 Also the page table are updated and instruction is restarted.

10.Explain FIFO,LRU,OPTIMAL.

FIFO
LRU  full form Least Recently used







Optimal

It is a  page replacement scheme the victim page is a page that will not be used for the longest period of time. 
Advantages-
i)It guarantees the lowest  possible- fault rate for a fixed number of frames.
ii)Never suffer from Belady’s anomaly.

Disadvantages-
It is difficult to implement as it needs to future knowledge of the reference string.







11.What is thrashing?
If this page fault and then swapping happening very frequently at higher rate, then operating 
system has to spend more time to swap these pages. This state is called thrashing. Because of this, CPU utilization is going to be reduced.

Let , in the point λ the CPU utilization  maximum and degree of multiprogramming 
in a particular point p.Then page fault increase that's why the thrashing will started.

To Reduce Thrashing:
  • Increase the main memory size.
  • Reduce the long term scheduler.
Effect of Thrashing:
All CPU utilization will degraded then through-put and performance will be reduced.


Paging-


  • Paging is a fixed size partitioning scheme.
  • In paging, secondary memory and main memory are divided into equal fixed size partitions.
  • The partitions of secondary memory are called pages.
  • The partitions of main memory are called frames.


  • Each process is divided into parts where the size of each part is same as page size.
  • The size of the last part may be less than the page size.
  • The pages of process are stored in the frames of main memory depending upon their availability.
Advantages-

The advantages of paging are-
  • It allows to store parts of a single process in a non-contiguous fashion.
  • It solves the problem of external fragmentation.

Disadvantages-

The disadvantages of paging are-
  • It suffers from internal fragmentation.
  • There is an overhead of maintaining a page table for each process.
  • The time taken to fetch the instruction increases since now two memory accesses are required.

Segmentation-


  • Like Paging, Segmentation is another non-contiguous memory allocation technique.
  • In segmentation, process is not divided blindly into fixed size pages.
  • Rather, the process is divided into modules for better visualization.

Characteristics-

  • Segmentation is a variable size partitioning scheme.
  • In segmentation, secondary memory and main memory are divided into partitions of unequal size.
  • The size of partitions depend on the length of modules.
  • The partitions of secondary memory are called segments.

Demand paging | Introduction


Comments

Popular Posts