Unit 4 Answer Key

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

MALLA REDDY UNIVERSITY

School of Engineering - AI&ML


II Year – II Semester

Subject Code: MR221CS0224 Subject Name: OPERATING SYSTEM

Unit 4 answer key


31.A) What is memory management, and why is it important in computer systems.

ANSWER: Memory management is the process of controlling and coordinating a


computer's main memory. It ensures that blocks of memory space are properly
managed and allocated so the operating system (OS), applications and other
running processes have the memory they need to carry out their operations.
 It is the functionality of an OPERATING SYSTEMS which handles or manages
primary memory and moves processes back and forth between main memory
and disk during execution.
 Memory management keeps track of each and every memory location,
regardless of either it is allocated to some process or it is free.
 It checks how much memory is to be allocated to processes. It decides which
process will get memory at what time.
 It tracks whenever some memory gets freed or unallocated and
correspondingly it updates the status.
B) Distinguish between Internal and External Fragmentation.

S.NO Internal fragmentation External fragmentation

In internal fragmentation fixed-sized


In external fragmentation, variable-sized memory
memory, blocks square measure
blocks square measure appointed to the method.
1. appointed to process.

Internal fragmentation happens when the


External fragmentation happens when the method or
method or process is smaller than the
process is removed.
2. memory.

The solution of internal fragmentation is The solution to external fragmentation is compaction


3. the best-fit block. and paging.

Internal fragmentation occurs when External fragmentation occurs when memory is


memory is divided into fixed-sized divided into variable size partitions based on the size
4. partitions. of processes.

The difference between memory The unused spaces formed between non-contiguous
allocated and required space or memory memory fragments are too small to serve a new
5. is called Internal fragmentation. process, which is called External fragmentation.

Internal fragmentation occurs with


External fragmentation occurs with s
6. paging and fixed partitioning.

32. Compose Contiguous Memory Allocation techniques with advantages and


disadvantages.
 Memory is allotted in a continuous way to the processes

 executing process must be loaded entirely in the main memory.

 Contiguous Technique can be divided into:

1.Fixed (or static) partitioning

2. Variable (or dynamic) partitioning

Advantages:

 Easy to implement

 Little OS overhead
Disadvantages:

 Internal Fragmentation

 External Fragmentation

 Limit process size

 Limitation on Degree of Multiprogramming

Variable (or dynamic) partitioning:

It is a part of Contiguous allocation technique. It is used to alleviate the problem faced by Fixed Partitioning. In contrast with
fixed partitioning, partitions are not made before the execution or during system configure.

Various features associated with variable Partitioning-

 Initially RAM is empty and partitions are made during the run-time according to process’s need instead of
partitioning during system configure.

 The size of partition will be equal to incoming process.

 Number of partitions in RAM is not fixed and depends on the number of incoming

process and Main Memory’s size.

Advantages:
 No Internal Fragmentation

 No restriction on Degree of Multiprogramming

 No Limitation on the size of the process

Disadvantages

 Difficult Implementation

 External Fragmentation

33. What is paging? Design the representation of paging with example?


 Paging is a memory management scheme that eliminates the need for contiguous allocation of physical memory.
This scheme permits the physical address space of a process to be non – contiguous.

 The mapping from virtual to physical address is done by the memory management unit (MMU) which is a hardware
device and this mapping is known as paging technique.

 The Physical Address Space is conceptually divided into a number of fixed-size blocks, called frames.

 The Logical address Space is also spitted into fixed-size blocks, called pages.

 Page Size = Frame Size

The address generated by the CPU is divided into

 Page number(p): Number of bits required to represent the pages in Logical Address Space or Page number

 Page offset(d): Number of bits required to represent a particular word in a page or page size of Logical Address
Space or word number of a page or page offset.

Physical Address is divided into

 Frame number(f): Number of bits required to represent the frame of Physical Address Space or Frame number frame

 Frame offset(d): Number of bits required to represent a particular word in a frame or frame size of Physical Address
= 1 K words (assumption)Space or word number of a frame or frame offset.

Let us consider an example:

 Physical Address = 12 bits, then Physical Address Space = 4 K words

 Logical Address = 13 bits, then Logical Address Space = 8 K words

 Page size = frame size


34. Consider the following : 7,0,1,2,0,3,0,4,2,3,0,3,2,3 with 4 page frames.
A) Solve by using FIFO page replacement algorithm. (4M)
B) Solve by using LRU page replacement algorithm. (4M)
A): Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page frame. Find number
of page fault.

Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults
0 is already there so —> 0 Page fault. when 3 came it will take the place of 7 because it is not used
for the longest duration of time in the future.—>1 Page fault. 0 is already there so —> 0 Page
fault. 4 will takes place of 1 —> 1 Page Fault.
Now for the further page reference string —> 0 Page fault because they are already available in the
memory.
Optimal page replacement is perfect, but not possible in practice as the operating system cannot
know future requests. The use of Optimal Page replacement is to set up a benchmark so that other
replacement algorithms can be analyzed against it.
3. Least Recently Used: In this algorithm, page will be replaced which is least recently used.
Example-3: Consider the page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page
frames. Find number of page faults.
B) Solve by using LRU page replacement algorithm.

Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults
0 is already their so —> 0 Page fault. when 3 came it will take the place of 7 because it is least
recently used —>1 Page fault
0 is already in memory so —> 0 Page fault.
4 will takes place of 1 —> 1 Page Fault
Now for the further page reference string —> 0 Page fault because they are already available in the
memory.

35, Elaborate the following memory management techniques:


A) Paging &Segmentation
B) Swapping & Thrashing
Paging is a method or technique which is used for non-contiguous memory allocation. It is a fixed-
size partitioning theme (scheme). In paging, both main memory and secondary memory are divided
into equal fixed-size partitions. The partitions of the secondary memory area unit and main memory
area unit are known as pages and frames respectively.
Paging is a memory management method accustomed fetch processes from the secondary memory
into the main memory in the form of pages. in paging, each process is split into parts wherever the
size of every part is the same as the page size. The size of the last half could also be but the page size.
The pages of the process area unit hold on within the frames of main memory relying upon their
accessibility.
Paging:
Segmentation is another non-contiguous memory allocation scheme like paging. like paging, in
segmentation, the process isn’t divided indiscriminately into mounted(fixed) size pages. It is a
variable-size partitioning theme. like paging, in segmentation, secondary and main memory are not
divided into partitions of equal size. The partitions of secondary memory area units are known as
segments. The details concerning every segment are hold in a table known as segmentation table.
Segment table contains two main data concerning segment, one is Base, which is the bottom address
of the segment and another is Limit, which is the length of the segment.
In segmentation, the CPU generates a logical address that contains the Segment number and segment
offset. If the segment offset is a smaller amount than the limit then the address called valid address
otherwise it throws miscalculation because the address is invalid.
The above figure shows the translation of a logical address to physical address.

36. Explain the concept of paging. How does it work, and what are its
advantages and disadvantages?
 Paging is a memory management scheme that eliminates the need for contiguous allocation of
physical memory. This scheme permits the physical address space of a process to be non –
contiguous.
 The mapping from virtual to physical address is done by the memory management unit
(MMU) which is a hardware device and this mapping is known as paging technique.
 The Physical Address Space is conceptually divided into a number of fixed-size blocks,
called frames.
 The Logical address Space is also spitted into fixed-size blocks, called pages.
 Page Size = Frame Size

The address generated by the CPU is divided into

 Page number(p): Number of bits required to represent the pages in Logical Address Space or
Page number
 Page offset(d): Number of bits required to represent a particular word in a page or page size of
Logical Address Space or word number of a page or page offset.

Physical Address is divided into

 Frame number(f): Number of bits required to represent the frame of Physical Address Space
or Frame number frame
 Frame offset(d): Number of bits required to represent a particular word in a frame or frame
size of Physical Address Space or word number of a frame or frame offset.

 he operating system retrieves data from secondary storage in same-


size blocks called pages. Paging is an vital part of virtual
memory implementations in new age operating systems, using secondary
storage to let programs cross the size of available physical memory.”

 Paging

 It is utilized for faster access to information/data and it is also logical concept.


The RAM (the main memory want to say) is parted out into little/small specific-
sized blocks of actual memory(physical registers) which are called frames. We
must have to keep size of frame same as that of page so as to maximize
utilization of RAM (main memory) and for avoiding external problems.

 The mapping which is done from virtual memory to physical memory is


functioned by memory management unit called MMU. which is a hardware
device and this mapping is known as paging technique.

 1. The Physical Address Space is conceptually divided into a number of fixed-


size blocks, called frames.

 2. The Logical address Space is also splitted into fixed-size blocks,


called pages.

 3. Page Size = Frame Size


 We can consider example like:

 · If physical Address = 12 bits, then Physical Address Space would be 4 K words

 · If logical Address = 13 bits, then Logical Address Space would be 8 K words

 · Page size = frame size = 1 K words (assumption)

 Paging Hardware
 Every address generated by CPU mainly consists of two parts:

 1. Page Number(p)

 2. Page Offset (d)

 where,

 Page Number is used as an index into the page table that generally
contains the base address of each page in the physical memory.

 Page offset is combined with base address in order to define the physical
memory address which is then sent to the memory unit.

 If the size of logical address space is 2 raised to the power m and page
size is 2 raised to the power n addressing units then the high order m-n bits
of logical address designates the page number and the n low-order bits
designate the page offset.

 The logical address is as follows:


 where p indicates the index into the page table, and d indicates the
displacement within the page. The Page size is usually defined by the hardware.
The size of the page is typically the power of 2 that varies between 512 bytes and
16 MB per page.

 Assuming main memory size 16 KB and frame size is 1 KB hence the main
memory will be parted/divided into the collection of 16 frames of 1 KB each.

 There are 4 processes in the system that is P1, P2, P3 and P4 having 4 KB each.
Each process is parted/divided into pages of 1 KB each by which one page can
be stored in one frame.

 Initially, all the frames are empty therefore pages of the processes will get
stored in the contiguous way.

 We can see in following diagram, frames, pages and the mapping between the
two.
Analyze the basic concept of segmentation in detail.

Analyze the basic concept of segmentation in detail.

 Assuming that, P2 and P4 are moved to waiting state after some time. Now, 8
frames become empty and hence other pages can be loaded in that empty place.
The process P5 of size 8 KB i.e.-of 8 pages is waiting inside the ready queue.

 Having 8 non-contiguous frames available in the memory and paging provides


the flexibility of storing the process at the different places, we can load the
pages of process P5 in the place of P2 and P4.
37. 37

37
Analyze the
Analyze the basic
basic concept
concept of segmentation
of segmentation in detail.in detail.

37. Analyze the basic concept of segmentation in detail.


 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 as segments.

Example” Segment Table- table that stores the information about each
segment of the process.

It has two columns.

 First column stores the size or length of the segment.


 Second column stores the base address or starting address of

the segment in the main memory.

 Segment table is stored as a separate segment in the main memory.


 Segment table base register (STBR) stores the base address of the

segment table.

Size of Segment starting address of the segment


Develop the following algorithms for Contiguous Memory Allocation for the given input:First Fit , Best Fit and
Worst Fit
Block Size[] = {100, 500, 200, 300, 600}

38. Develop the following algorithms for Contiguous Memory Allocation for
the given input:First Fit , Best Fit and Worst Fit
Block Size[] = {100, 500, 200, 300, 600}
Process Size[] = {212, 417, 112, 426}
First-Fit Memory Allocation : First job claims the first available memory with space
more than or equal to it’s size.
Input : blockSize[] = {100, 500, 200, 300, 600};
processSize[] = {212, 417, 112, 426};
Output:
Process No. Process Size Block no.
1 212 2
2 417 5
3 112 2
4 426 Not Allocated
Best-Fit Memory Allocation: closest-fitting free partition in the memory
Input : blockSize[] = {100, 500, 200, 300, 600};
processSize[] = {212, 417, 112, 426};
Output:
Process No. Process Size Block no.
1 212 4
2 417 2
3 112 3
4 426 5
Worst-Fit Memory Allocation: always search for the largest hole/partition, and then
the
process is placed
Input : blockSize[] = {100, 500, 200, 300, 600};
processSize[] = {212, 417, 112, 426};
Output:
Process No. Process Size Block no.
1 212 5
2 417 2
3 112 5
4 426 Not Allocated
39.What is MMU? Describe the role of MMU in mapping logical address to
physical address?
The physical hardware of a computer that manages its virtual memory and caching functions is called
the memory management unit (MMU). The MMU is sometimes housed in a separate Integrated Chip
(IC), but it is typically found inside the central processing unit (CPU) of the computer. The MMU
receives all inputs for data requests and decides whether to retrieve the data from ROM or RAM
storage.

The process requires physical memory to run because the logical address is a virtual address. The
Physical Address is never utilised by the User. The Memory Management Unit (MMU) maps the
logical address that the user programme creates to the physical address. Important Points about
Logical and Physical Addresses in Operating Systems
 The use of logical addresses provides a layer of abstraction that allows processes to access
memory without knowing the physical memory location.
 Logical addresses are mapped to physical addresses using a page table. The page table
contains information about the mapping between logical and physical addresses.
 The MMU translates logical addresses into physical addresses using the page table. This
translation is transparent to the process and is performed by hardware.
 The use of logical and physical addresses allows the operating system to manage memory
more efficiently by using techniques such as paging and segmentation.
A) Compare and contrast paging and segmentation.(4M)

Difference Between Logical address and Physical Address


Parameter LOGICAL ADDRESS PHYSICAL ADDRESS

Basic generated by CPU location in a memory unit

Logical Address Space is set of all logical Physical Address is set of all physical
Address
addresses generated by CPU in reference to addresses mapped to the corresponding
Space
a program. logical addresses.

User can view the logical address of a User can never view physical address of
Visibility
program. program.

Generation generated by the CPU Computed by MMU

The user can use the logical address to The user can indirectly access physical
Access
access the physical address. address but not directly.

Editable Logical address can be change. Physical address will not change.

Also called virtual address. real address

40. A) Compare and contrast paging and segmentation


B) Interpret the concept of Virtual Memory and Thrashing
S.NO Paging Segmentation

In paging, program is divided into fixed or mounted size


1. In segmentation, program is divided into variable size sections.
pages.

2. For paging OPERATING SYSTEMS is accountable. For segmentation compiler is accountable.

3. Page size is determined by hardware. Here, the section size is given by the user.

4. It is faster in the comparison of segmentation. Segmentation is slow.

5. Paging could result in internal fragmentation. Segmentation could result in external fragmentation.

In paging, logical address is split into page number and


6. Here, logical address is split into section number and section offset.
page offset.

Paging comprises a page table which encloses the base While segmentation also comprises the segment table which encloses segment number and
7.
address of every page. segment offset.

8. Page table is employed to keep up the page data. Section Table maintains the section data.

In paging, OPERATING SYSTEMS must maintain a free


9. In segmentation, OPERATING SYSTEMS maintain a list of holes in main memory.
frame list.

10. Paging is invisible to the user. Segmentation is visible to the user.

In paging, processor needs page number, offset to


11. In segmentation, processor uses segment number, offset to calculate full address.
calculate absolute address.

It is hard to allow sharing of procedures between


12. Facilitates sharing of procedures between the processes.
processes.

In paging, a programmer cannot efficiently handle data


13 It can efficiently handle data structures.
structure.

14. In this protection is hard to apply. Easy to apply protection in segmentation


 Virtual Memory is a storage allocation scheme in which secondary memory
can be addressed as though it were part of the main memory.
 It is a technique that is implemented using both hardware and software.
 It maps memory addresses used by a program, called virtual addresses,
into physical addresses in computer memory.
 Swapping
 Demand Paging: The process of loading the page into memory on demand
(whenever page fault occurs) is known as demand paging.
 Virtual memory is implemented using Demand Paging or Demand
Segmentation.
Thrashing is a condition or a situation when the system is spending a major portion of its time
servicing the page faults, but the actual processing done is very negligible.
Causes of thrashing:
1. High degree of multiprogramming.
2. Lack of frames.
3. Page replacement policy.
Thrashing’s Causes
Thrashing has an impact on the operating system’s execution performance. Thrashing also causes
serious performance issues with the operating system. When the CPU’s usage is low, the process
scheduling mechanism tries to load multiple processes into memory at the same time, increasing the
degree of Multi programming.
In this case, the number of processes in the memory exceeds the number of frames available in the
memory. Each process is given a set number of frames to work with.
If a high-priority process arrives in memory and the frame is not vacant at the moment, the other
process occupying the frame will be moved to secondary storage, and the free frame will be allotted
to a higher-priority process.
We may also argue that as soon as the memory is full, the procedure begins to take a long time to
swap in the required pages. Because most of the processes are waiting for pages, the CPU utilization
drops again.
As a result, a high level of multi programming and a lack of frames are two of the most common
reasons for thrashing in the operating system.
The basic concept involved is that if a process is allocated to few frames, then there will be too many
and too frequent page faults. As a result, no useful work would be done by the CPU and the CPU
utilization would fall drastically. The long-term scheduler would then try to improve the CPU
utilization by loading some more processes into the memory thereby increasing the degree of multi
programming. This would result in a further decrease in the CPU utilization triggering a chained
reaction of higher page faults followed by an increase in the degree of multi programming, called
Thrashing.

You might also like