0% found this document useful (0 votes)
19 views11 pages

Assignment 2 Os

operating system
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views11 pages

Assignment 2 Os

operating system
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ASSIGNMENT …..

OPERATING SYSTEM…
Rollno - 56
Q1: Differentiate between
a) Physical address space and logical address space:
- Physical address space: This refers to the actual
addresses that correspond to the physical memory
chips or storage devices. It represents the real locations
where data is stored or retrieved.
- Logical address space: This is the set of addresses
generated by a program. These addresses need to be
translated into physical addresses to access the actual
memory. Logical addresses are relative to the start of
the program's execution and are mapped to physical
addresses by the memory management unit (MMU)
during execution.

b) Internal fragmentation and external fragmentation:


- Internal fragmentation: Occurs when memory is
allocated in fixed-size blocks, and the allocated
memory may be slightly larger than requested. The
difference between allocated memory and requested
memory within a single block is wasted due to internal
fragmentation.
- External fragmentation: Happens when there is
enough total memory space to satisfy a request or a
process, but it is not contiguous. This fragmentation
can lead to inefficient memory usage as the system
cannot utilize fragmented free memory blocks
effectively.

c) Paging and segmentation:


- Paging: Memory management scheme where
memory is divided into fixed-size blocks called pages.
Programs are also divided into fixed-size pages, and
these pages are mapped to frames in physical memory.
Paging helps in overcoming external fragmentation.
- Segmentation: Memory management scheme
where memory is divided into variable-size segments.
Each segment corresponds to a logical unit such as
code, data, stack, etc. Segmentation helps in organizing
and managing memory more flexibly than paging.

d) Dynamic linker and dynamic loader:


- Dynamic linker: Part of the operating system or
runtime system responsible for linking shared libraries
or modules into a program during execution. It resolves
references to external symbols and prepares the
executable code dynamically.
- Dynamic loader: Loads and links executable files into
memory for execution. It performs dynamic linking,
resolving symbolic references at runtime rather than
during compilation or linking. It prepares the program
for execution by allocating memory and setting up the
execution environment.

Q2: Memory Partitioning Algorithms

Given Memory partitions: 100K, 500K, 200K, 300K,


600K (in order)

Processes sizes to allocate: 212K, 47K, 112K, 426K (in


order)

- First Fit: Allocates the first available partition that is


large enough to fit the process.
- Best Fit: Allocates the smallest available partition that
is large enough to fit the process.
- Worst Fit: Allocates the largest available partition that
is large enough to fit the process.
Allocation Results:
- First Fit:
- 212K -> 300K
- 47K -> 100K
- 112K -> 200K
- 426K -> 600K

- **Best Fit**:
- 212K -> 300K
- 47K -> 100K
- 112K -> 200K
- 426K -> 500K

- **Worst Fit**:
- 212K -> 600K
- 47K -> 100K
- 112K -> 200K
- 426K -> 500K
Efficiency: Best Fit typically makes the most efficient
use of memory by minimizing wasted space due to
fragmentation.

Q3: Reasons

a) Why paging is faster than segmentation?


- Paging allows for efficient allocation and
management of memory due to fixed-size pages, which
are easier to manage in terms of memory allocation
and deallocation compared to variable-sized segments
in segmentation. Paging also reduces external
fragmentation.

b) Why are page sizes always power of 2?


- Page sizes are often chosen as powers of 2 (like 2^N)
because it simplifies the calculation of page offsets
within a page. Using powers of 2 allows the page offset
to be determined directly from the lower bits of the
logical address, which makes address translation faster
and more efficient.
c) Why in paging it is not necessary to add the page
offset to the starting address of the page frame to
generate a physical address?
- In paging, the page offset directly represents the
position within the page frame. Adding the page offset
to the starting address of the page frame is not
necessary because the physical address can be directly
derived from the page number and the offset within
the page. This direct mapping simplifies address
translation and improves efficiency.

Q4: Simple Paging System

a) Logical Address:
- Given: 256 pages (2^8 pages) and page size of 2^10
bytes.
- Number of bits for logical address = Page number
bits + Page offset bits
- Page number bits = log2(256) = 8 bits
- Page offset bits = log2(2^10) = 10 bits
- Total bits in logical address = 8 (page number) + 10
(page offset) = 18 bits
b) Page Frame Size:
- Page size = 2^10 bytes
- Number of bytes in a page frame = 2^10 bytes =
1024 bytes

c) Physical Address:
- Physical memory = 2^24 bytes
- Number of page frames = Physical memory size /
Page size = 2^24 bytes / 2^10 bytes = 2^14 page frames
- Number of bits for physical address specifying the
page frame = log2(2^14) = 14 bits

d) Page Table Entries:


- Number of entries in the page table = Number of
pages = 256 pages

Q5: Two-Level Page Table

a) Second Level Index Bits:


- Virtual address = 32 bits
- First 8 bits used for first level index
- Remaining bits used for second level index
- Second level index bits = 32 - 8 = 24 bits

b) Entries in Level One Page Table:


- Entries = 2^8 = 256 entries

c) Entries in Level Two Page Table:


- Each entry in level two corresponds to a page size of
2^12 bytes.
- Number of entries = 2^24 / 2^12 = 2^12 = 4096
entries

d) Pages in Virtual Address Space:


- Virtual address space = 2^32 bytes / 2^12 bytes =
2^20 pages

Q6: Associative Memory Hit Ratio

Given:
- Overhead without associative memory = 500 nsec
- Overhead with associative memory = 100 nsec
- Desired mean overhead = 200 nsec

Let \( H \) be the hit ratio.


\[ \text{Mean overhead} = H \cdot 100 \text{ nsec} + (1
- H) \cdot 500 \text{ nsec} = 200 \text{ nsec} \]
\[ H \cdot 100 + 500 - H \cdot 500 = 200 \]
\[ H \cdot 100 - H \cdot 500 = 200 - 500 \]
\[ -400H = -300 \]
\[ H = \frac{3}{4} = 0.75 \]

So, a hit ratio of \( 0.75 \) or \( 75\% \) is needed to


achieve the desired mean overhead of \( 200 \) nsec.

Q7: Concepts

a) Thrashing: Excessive paging activity that occurs when


a system spends more time paging (swapping pages
between disk and memory) than executing tasks. It
leads to a significant decrease in system performance.

b) Belady's Anomaly: Occurs in page replacement


algorithms where increasing the number of page
frames (memory allocated) can result in more page
faults, contradicting the principle that more memory
should decrease the number of page faults.

c) Overlays: Technique used to exceed the physical


memory constraints of a system by dynamically
swapping parts of a program in and out of memory as
needed.

d) Page Fault: Occurs when a program accesses a page


that is not currently present in main memory (RAM).
The operating system then retrieves the required page
from disk into memory.

e) Demand Paging: Operating system technique where


pages are loaded into memory only when they are
demanded by the executing program, rather than
loading all pages at program startup.

Q8: Page Replacement Algorithms

Given reference string: 1, 2, 3, 2, 1, 4, 3, 5, 6, 4, 3, 5, 3,


5, 6, 7, 2, 1, 5, 7
- Optimal: Determine which page will not be used for
the longest period in the future and replace it.
- FIFO (First In First Out): Replace the oldest page in
memory.
- LRU (Least Recently Used): Replace the page that
hasn't been used for the longest period of time.

Page Faults:
- Optimal: 7 page faults
- FIFO: 9 page faults
- LRU: 8 page faults

You might also like