Recents in Beach

Contiguous memory allocation

Previous                                                          Next⏩

           

                Contiguous memory allocation is one of the oldest memory allocation schemes. When a process needs to execute, memory is requested by the process. The size of the process is compared with the amount of contiguous main memory available to execute the process. If sufficient contiguous memory is found, the process is allocated memory to start its execution. Otherwise, it is added to a queue of waiting processes until sufficient free contiguous memory is available.





  1. Static Partitioning
  2. Dynamic Partitioning


Static Partitioning-


  • Static partitioning is a fixed size partitioning scheme.
  • In this technique, main memory is pre-divided into fixed size partitions.
  • The size of each partition is fixed and can not be changed.
  • Each partition is allowed to store only one process.

Example-


Under fixed size partitioning scheme, a memory of size 10 KB may be divided into fixed size partitions as-


  • These partitions are allocated to the processes as they arrive.
  • The partition allocated to the arrived process depends on the algorithm followed.

Algorithms for Partition Allocation-


Popular algorithms used for allocating the partitions to the arriving processes are-


  1. First Fit Algorithm
  2. Best Fit Algorithm
  3. Worst Fit Algorithm

1. First Fit Algorithm-


  • This algorithm starts scanning the partitions serially from the starting.
  • When an empty partition that is big enough to store the process is found, it is allocated to the process.
  • Obviously, the partition size has to be greater than or at least equal to the process size.

2. Best Fit Algorithm-


  • This algorithm first scans all the empty partitions.
  • It then allocates the smallest size partition to the process.

3. Worst Fit Algorithm-


  • This algorithm first scans all the empty partitions.
  • It then allocates the largest size partition to the process.

Important Points-


Point-01:


For static partitioning,
  • Best Fit Algorithm works best.
  • This is because space left after the allocation inside the partition is of very small size.
  • Thus, internal fragmentation is least.

Point-02:


For static partitioning,
  • Worst Fit Algorithm works worst.
  • This is because space left after the allocation inside the partition is of very large size.
  • Thus, internal fragmentation is maximum.

Internal Fragmentation


  • It occurs when the space is left inside the partition after allocating the partition to a process.
  • This space is called as internally fragmented space.
  • This space can not be allocated to any other process.
  • This is because only static partitioning allows to store only one process in each partition.
  • Internal Fragmentation occurs only in static partitioning.

External Fragmentation


  • It occurs when the total amount of empty space required to store the process is available in the main memory.
  • But because the space is not contiguous, so the process can not be stored.

Translating Logical Address into Physical Address-


  • CPU always generates a logical address.
  • A physical address is needed to access the main memory.

Following steps are followed to translate logical address into physical address-

Step-01:


  • The translation scheme uses two registers that are under the control of operating system.
  • During context switching, the values corresponding to the process being loaded are set in the registers.

These two registers are-
  • Relocation Register
  • Limit Register


  • Relocation Register stores the base address or starting address of the process in the main memory.
  • Limit Register stores the size or length of the process.

Step-02:


  • CPU generates a logical address containing the address of the instruction that it wants to read.

Step-03:


  • The logical address generated by the CPU is compared with the limit of the process.
  • Now, two cases are possible-

Case-01: Generated Address >= Limit


  • If address is found to be greater than or equal to the limit, a trap is generated.
  • This helps to prevent unauthorized access.

Case-02: Generated Address < Limit


  • The address must always lie in the range [0, limit-1].
  • If address is found to be smaller than the limit, then the request is treated as a valid request.
  • Then, generated address is added with the base address of the process.
  • The result obtained after addition is the address of the memory location storing the required word.

Diagram-


The following diagram illustrates the above steps of translating logical address into physical address-


Advantages-


The advantages of static partitioning are-
  • It is simple and easy to implement.
  • It supports multiprogramming since multiple processes can be stored inside the main memory.
  • Only one memory access is required which reduces the access time.

Disadvantages-


The disadvantages of static partitioning are-
  • It suffers from both internal fragmentation and external fragmentation.
  • It utilizes memory inefficiently.
  • The degree of multiprogramming is limited equal to number of partitions.
  • There is a limitation on the size of process since processes with size greater than the size of largest partition can’t be stored and executed.

Dynamic Partitioning -


  • Dynamic partitioning is a variable size partitioning scheme.
  • It performs the allocation dynamically.
  • When a process arrives, a partition of size equal to the size of process is created.
  • Then, that partition is allocated to the process.

Partition Allocation Algorithms-


  • The processes arrive and leave the main memory.
  • As a result, holes of different size are created in the main memory.
  • These holes are allocated to the processes that arrive in future.

Partition allocation algorithms are used to decide which hole should be allocated to the arrived process.

Popular partition allocation algorithms are-


  1. First Fit Algorithm
  2. Best Fit Algorithm
  3. Worst Fit Algorithm

We have already discussed these algorithms above

Important Points-


Point-01:


For dynamic partitioning,
  • Worst Fit Algorithm works best.
  • This is because space left after allocation inside the partition is of large size.
  • There is a high probability that this space might suit the requirement of arriving processes.

Point-02:


For dynamic partitioning,
  • Best Fit Algorithm works worst.
  • This is because space left after allocation inside the partition is of very small size.
  • There is a low probability that this space might suit the requirement of arriving processes.

Translating Logical Address into Physical Address-


The following diagram illustrates the steps of translating logical address into physical address-


The steps are same as we have discussed above

Advantages-


The advantages of dynamic partitioning are-
  • It does not suffer from internal fragmentation.
  • Degree of multiprogramming is dynamic.
  • There is no limitation on the size of processes.

Disadvantages-


The disadvantages of dynamic partitioning are-
  • It suffers from external fragmentation.
  • Allocation and deallocation of memory is complex.

               Non - Contiguous memory allocation


Difference Between Contiguous and Noncontiguous Memory Allocation



Previous                                                          Next⏩




  1. What is an Operating System ?
  2. Discuss the structure off OS ?
  3. Explain type of OS?
  4. Explain Function of OS?
  5. Explain OS Services ?
  6. What do mean by system call ?List different type ofsystem call available ?

  1. what is process ? and Characteristics ?
  2. What is different process state? explain the same in details?
  3. write short note on user level and kernal level threads?
  4. explain what is thread and its type ?
  5. explain scheduler ? (short term,medium term,and long term)
  6. state and explain scheduling criteria ?
  7. Explain scheduling algorithm ? [ FCFS,SJF,PRIORITY,ROUND ROBINE.]    

  1. What is process synchronization ? explain critical section problem and race condition ?
  2. what is Race Condition ?
  3. what is critical section problem?
  4. explain classical problem of synchronization?
  5. explain bounded - buffer problem?
  6. explain reader - writer problem ?
  7. explain Dining Philosophers Problem ?
  8. explain semaphores ? its type ?

  1.  What is deadlock ?
  2. What are the 4 condition to produce deadlock ?
  3. explain methods of handling deadlock ?
  4. explain in detail deadlock prevention ?
  5. write short note on deadlock avoidance ?
  6. explain deadlock detection ? 
  7. explain Banker algorithm with example ? 


Post a Comment

0 Comments