0% found this document useful (0 votes)
23 views16 pages

OSC06

Uploaded by

bipruu
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)
23 views16 pages

OSC06

Uploaded by

bipruu
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/ 16

Memory Management

Short Answer Type Questions (2 Marks)


1. Define Swapping

A: Swapping is the process of temporarily transferring data from main memory to disk
storage to free up RAM for other processes.

2. What is External Fragmentation?

A: External fragmentation occurs when free memory is scattered in small, non-contiguous


blocks, preventing allocation even though total free memory is sufficient

3. What is Internal Fragmentation?

A: Internal fragmentation happens when allocated memory blocks are larger than
necessary, leaving unused space within those blocks

4. What do you mean by Compaction?

A: Compaction is the process of rearranging memory contents to combine free spaces into
larger contiguous blocks, reducing fragmentation

5. What are Pages and Frames?

A: Pages are fixed-size blocks of memory used in virtual memory systems, while frames are
the corresponding blocks in physical memory where pages are loaded.

6. What is the use of Valid-Invalid Bits in Paging?

A: Valid-invalid bits are used in paging to indicate whether a page is currently loaded in
memory (valid) or not (invalid), helping manage memory access.

7. What is the basic method of Segmentation?

A: Segmentation divides memory into variable-sized segments based on logical divisions,


such as functions or data structures, allowing more flexible allocation.

8. What is Virtual Memory?

A: Virtual memory is a memory management technique that allows the execution of


processes that may not be completely in RAM by using disk space as an extension.

9. What is Demand Paging?

A: Demand paging loads pages into memory only when they are needed, reducing the
amount of RAM used and improving efficiency.
10. What is the basic approach of Page Replacement?

A: The basic approach involves selecting which pages to remove from memory when new
pages need to be loaded, based on certain algorithms.

11. What is the various Page Replacement Algorithms used for Page Replacement?

A: Common algorithms include Least Recently Used (LRU), First-In-First-Out (FIFO), and
Optimal Page Replacement.

12. What is a Reference String?

A: A reference string is a sequence of page numbers that represents the order in which
pages are accessed during program execution.

13. How is memory protected in a paged environment?

A: Memory protection is achieved by using valid-invalid bits and page tables to ensure
processes cannot access each other's memory spaces.

14. What do you mean by Best Fit, First fit and Worst fit?

A: These are strategies for allocating free memory:

• Best Fit allocates the smallest available block that fits the request.
• First Fit allocates the first available block that fits.
• Worst Fit allocates the largest available block to leave larger remaining spaces.

Long Answer Type Questions (4 Marks & 8 Marks)


1. Discuss LRU-Approximation page Replacement.

A: LRU-Approximation is a simpler way to mimic the **Least Recently Used (LRU)** page
replacement algorithm without the complexity of tracking every page access. It uses
simpler methods to decide which page to replace when memory is ffull

Common Methods:

(i) Clock Algorithm: Pages are arranged in a circle with a reference bit. Pages with a
reference bit of 0 are replaced when needed.

(ii) NRU (Not Recently Used): Pages have a reference bit that is cleared periodically. Pages
with a 0 bit are considered for replacement.

•Advantages:
-Faster and simpler than exact LRU.

-Good performance with lower overhead.

•Disadvantages:

-Less accurate: Might not always replace the optimal page.

-Potentially more page fault compared to exact LRU.

In summary, LRU-Approximation is a more efficient but less precise way to manage


memory by replacing pages that haven’t been used recently.

2. What is swapping and what is its purpose?

A: Swapping is a memory management technique used by operating systems to manage


the use of RAM (Random Access Memory). It involves temporarily moving data or processes
from RAM to secondary storage (such as a hard drive or SSD) and bringing them back when
needed.

Purpose of Swapping:

(i) Efficient Memory Usage: When the system runs out of RAM because too many programs
or processes are running, swapping helps by moving less frequently used data or
processes to disk, freeing up space in memory for other tasks.

(ii) Multitasking: Swapping allows the operating system to manage multiple programs
running at the same time, even if the total memory required exceeds the physical RAM
available. It keeps programs running smoothly by moving parts of programs to disk when
they are not actively in use.

(iii) Handling Large Processes: If a program or process is too large to fit into RAM all at once,
the operating system can swap parts of the process in and out of memory as needed,
allowing the program to run even on systems with limited RAM.

(iv) Preventing System Crashes: Without swapping, the system might run out of memory
and crash when multiple processes compete for space. Swapping helps avoid this by
temporarily moving data to disk, allowing the system to continue functioning.

Advantages of Swapping

•The swapping technique mainly helps the CPU to manage multiple processes within a
single main memory.

•This technique helps to create and use virtual memory.


•With the help of this technique, the CPU can perform several tasks simultaneously. Thus,
processes need not wait too long before their execution.

•This technique is economical.

•This technique can be easily applied to priority-based scheduling in order to improve its
performance.

Disadvantages of Swapping

•There may occur inefficiency in the case if a resource or a variable is commonly used by
those processes that are participating in the swapping process.

•If the algorithm used for swapping is not good then the overall method can increase the
number of page faults and thus decline the overall performance of processing.

•If the computer system loses power at the time of high swapping activity then the user
might lose all the information related to the program

3. Explain paging scheme for memory management, discuss the paging hardware and
Paging model.

A: Paging is a memory management technique where both the program’s memory (logical
memory) and physical memory (RAM) are divided into fixed-size blocks called pages (in
logical memory) and frames (in physical memory). The operating system loads pages into
available frames, and these pages can be scattered across memory instead of being stored
in a continuous block. This helps manage memory efficiently and simplifies allocation.

Paging Model: The paging model uses two main components:

(i) Logical Address Space: This is the address space used by a program. It is divided into
pages.

(ii) Physical Address Space: This is the actual memory (RAM). It is divided into frames.

How Paging Works:

(i) Division: The program (or process) is divided into pages, and the physical memory is
divided into frames of the same size.

(ii) Page Table: The operating system maintains a page table that holds the mapping
between logical pages and physical frames. When a process is running, the operating
system uses this page table to find where each page of the program is located in physical
memory.
(iii) Address Translation: When the CPU needs to access a memory address, the address
is split into two parts:

•Page Number: Determines which page of the process is being accessed.

•Offset: Specifies the exact location within the page.

The page number is used to look up the corresponding frame in the page table, and then
the offset is added to find the exact location in physical memory.

Paging Hardware: To efficiently perform the address translation in paging, special


hardware support is required, which includes:

(i) Page Table Register (PTR): This register holds the starting address of the page table in
memory.

(ii) Memory Management Unit (MMU): The MMU is responsible for translating logical
addresses (from the program) into physical addresses. It takes the page number from the
logical address, uses the page table to find the corresponding frame, and then combines it
with the offset to generate the physical address.

(iii) Translation Lookaside Buffer (TLB): The TLB is a small, fast cache that stores the most
recently used page table entries. This speeds up address translation because the MMU can
quickly check the TLB instead of always accessing the page table in memory.

4. Explain about contiguous memory allocation?

A: Contiguous Memory Allocation is a memory management technique in which each


process is allocated a single, continuous block of memory. The process resides in one
contiguous area in physical memory, and the operating system keeps track of the starting
address of each process's memory space. Types of Contiguous Memory Allocation:

(i) Fixed-Size Partition Scheme:

In this scheme, memory is divided into fixed-sized partitions, and each partition is
allocated to a process. All partitions are of the same size, regardless of the process size.

•Advantages:

- Simple to implement and manage.

- No need to manage the size of partitions dynamically.

•Disadvantages:
- Internal Fragmentation: If a process is smaller than the partition, unused memory within
the partition is wasted.

- Some partitions may remain unused if there aren't enough processes to fill them.

•Example: A system with 10 partitions of 1 GB each, where processes of any size are
allocated to these partitions.

(i) Variable-Size Partition Scheme:

In this scheme, memory is divided into partitions of varying sizes, and each process is
allocated a partition that exactly matches its size (or is the smallest partition that fits the
process).

•Advantages:

-Better Memory Utilization: No internal fragmentation as the partition size is based on the
process's needs.

•Disadvantages:

-External Fragmentation: Over time, free memory becomes fragmented into small blocks,
making it difficult to allocate large processes even if there is enough total free memory.

- Requires a more complex memory management system to track the partitions.

•Example: A system with different-sized partitions where each process is allocated only the
amount of memory it needs.

Strategies Used for Contiguous Memory Allocation:

These strategies are used to manage the allocation and deallocation of memory in
contiguous memory schemes

(i) First Fit: Allocate the first available partition that is large enough for the process. This is
the simplest strategy.

•Disadvantage: Can lead to fragmentation over time.

(ii) Best Fit: Allocate the smallest available partition that is large enough for the process.
This minimizes wasted space within the partition.

•Disadvantage: May leave small, unusable fragments in memory and could result in more
fragmentation.

(iii) Worst Fit: Allocate the largest available partition for the process, hoping that large
chunks of memory will remain free for future allocation.
•Disadvantage: Can also result in fragmented memory, especially when many small
processes are allocated to large blocks.

5. Explain about first fit, best fit, worst fit, next fit algorithms?

A: (i) First Fit: The First Fit algorithm allocates the first available partition (in memory) that
is large enough to fit the process. The system scans memory from the beginning and places
the process in the first free partition that is large enough.

•Advantages:

-Fast and simple: It quickly finds the first available partition, making it efficient in terms of
time complexity.

- Less searching: Since it starts from the beginning, it doesn’t need to check every partition
after finding a suitable one.

•Disadvantages:

- Fragmentation: Over time, small fragments of free memory are left scattered across the
system, leading to **external fragmentation.

-Inefficient use of space: Smaller processes might be allocated larger partitions than
necessary, wasting space within those partitions.

(ii) Best Fit: Best Fit looks at all available free partitions and **allocates the smallest
partition** that is large enough to fit the process. The idea is to minimize leftover free space
in the partition by using the smallest possible partition.

•Advantages:

-Minimizes wasted space: Best Fit tries to leave the least amount of unused space in the
memory partition by choosing the smallest fitting one.

•Disadvantages:

-Slower: It requires scanning all free partitions to find the smallest one, which takes more
time compared to First Fit.

-Creates small fragments: This approach can leave many small, unusable gaps of free
memory, making external fragmentation worse.

-Overhead: Due to the need to search through all partitions, it requires more processing
power and time, especially when there are many free partitions.
(iii) Worst Fit: Worst Fit allocates the largest free partition available for the process, hoping
that this will leave the largest remaining free space for future processes. The idea is to
leave a large block of memory free, which can accommodate future requests.

•Advantages:

Larger remaining spaces: By leaving a large free block, it’s easier for future processes to be
allocated memory without wasting space.

-Good for large processes: When a large process arrives, Worst Fit ensures there is a large
enough block available for it.

•Disadvantages:

-Increases fragmentation: The large partition could be used inefficiently, creating a lot of
small, unusable holes in memory.

-Slower: Like Best Fit, Worst Fit also requires searching through all free partitions to find the
largest one.

-Overuse of large blocks: If many small processes are allocated from large blocks, this
strategy could lead to significant waste and fragmentation.

(iv) Next Fit: Next Fit is similar to First Fit, but instead of starting from the beginning of the
memory each time, it starts from where the last allocation was made and looks for the next
available partition. Once a suitable partition is found, it allocates the process and
continues from that point on the next allocation.

•Advantages:

-Faster than First Fit: Since it doesn’t always start from the beginning, it reduces the
amount of searching for the next available partition.

-Better distribution: It tends to distribute the memory allocations more evenly throughout
the memory, which can reduce the chance of clustering small partitions together at the
start.

•Disadvantages:

-Fragmentation: Like First Fit, Next Fit can still cause external fragmentation over time, as it
might fill up memory starting from one end, leaving unused gaps elsewhere.

-Not as efficient as Best Fit: It may leave larger holes compared to Best Fit, which tries to
minimize wasted space by using the smallest fitting partition.
6. Explain about advantages and disadvantages of paging? And Explain difference
between paging and segmentation?

A: Advantages of Paging:

•Non-contiguous Allocation: Paging allows processes to be stored in non-contiguous


memory locations, which helps in utilizing memory more efficiently and reduces
fragmentation.

•Easy Memory Management: Since pages are of fixed size, the operating system can easily
allocate and deallocate memory. This simplifies memory management and makes it easier
to load processes into memory.

•Isolation: Each process has its own page table, which provides protection by isolating the
memory of different processes.

•Eliminates External Fragmentation: Paging eliminates the problem of external


fragmentation because pages and frames are of fixed size and can be scattered around
physical memory.

Disadvantages of Paging:

•Internal Fragmentation: If a process does not fully utilize the last page, there can be
unused space within that page, leading to internal fragmentation.

•Overhead: Maintaining and accessing page tables, as well as the additional hardware
support (like TLBs), adds some overhead, which can impact performance.

•Page Faults: If a page is not currently in memory, a page fault occurs, requiring the
operating system to load the page from disk, which can slow down the system.

7. Explain about Linux memory management?

A: Linux memory management is responsible for efficiently handling the system's RAM
(memory) to ensure smooth and fast operation. Here's a simplified explanation of its key
components:

(i) Virtual Memory: Linux uses virtual memory to give each process the illusion that it has
its own private memory. It helps the system run multiple applications even if there is not
enough physical RAM. Unused data is swapped to the disk when needed.

(ii) Page Allocation: Memory is divided into small blocks called pages. The system uses a
method called "buddy allocation" to assign and free up memory pages when programs
need them.
(iii) Swapping and Paging: When RAM is full, Linux can move less-used data to a special
area on the hard drive called swap space. This frees up RAM for active programs, but it can
slow down performance since accessing the disk is slower than RAM.

(iv) Memory Zones: The kernel organizes physical memory into different zones, such as
ZONE_NORMAL (main memory) and ZONE_HIGHMEM (for systems with more RAM than
can be directly addressed by the kernel).

(v) Out-of-Memory (OOM) Killer: If the system runs out of memory, the **OOM Killer**
automatically terminates processes to free up memory and prevent a system crash.

(vi)Memory Caching: Linux uses caching to store frequently used data in memory (like
files) so it can be accessed quickly without having to read from the disk every time.

(vii) Shared Memory: Linux allows multiple processes to share memory to communicate
efficiently with each other using shared memory regions.

(viii) NUMA (Non-Uniform Memory Access): In multi-processor systems, Linux can


optimize memory access by ensuring that each CPU core uses nearby memory to reduce
access delays.

8. Explain about the following page replacement algorithms a) FIFO b)OPR, c) LRU

A: Page replacement algorithms are used by the operating system to decide which pages to
swap out of memory when new pages need to be loaded. Here’s a simple explanation of
three popular page replacement algorithms:

(i) FIFO (First-In, First-Out): Replaces the oldest page in memory.

Advantages: Simple to implement.

Disadvantages: Can replace pages that are still frequently used, leading to poor
performance.

(ii) OPR (Optimal Page Replacement): Replaces the page that will not be used for the
longest time in the future.

Advantages: Minimizes page faults and is the most efficient.

Disadvantages: Not practical, as it requires knowing future page requests.

(iii) LRU (Least Recently Used): Replaces the page that has not been used for the longest
time.
Advantages: More efficient than FIFO, keeps frequently used pages in memory.

Disadvantages: Requires tracking page access, adding overhead.

9. Differentiate local and global page replacement algorithm.

A:

Feature Local Page Replacement Global Page Replacement


Scope of Replacement Replaces pages only from Replaces pages from any
the process causing the process in the system.
page fault.
Memory Allocation Each process is allocated a Memory is shared
fixed number of frames. dynamically across all
processes.
Fairness Ensures fairness by limiting Can be unfair as one
each process’s memory process can take all
usage. available memory.
Efficiency May cause inefficient More efficient as memory is
memory use if a process allocated based on the
doesn’t need all allocated needs of all processes.
frames.
Page Fault Rate Can result in higher page Typically leads to lower
fault rates due to limited page fault rates because of
frames for each process. dynamic memory
allocation.
Complexity Simpler to implement since More complex, as memory
each process has management is done
independent memory across all processes.
management.
Impact on Other Does not affect other Can negatively impact other
Processes processes’ memory directly. processes by taking too
much memory.
Example Algorithms LRU, FIFO applied Global LRU, Global FIFO
individually to each applied across all
process. processes.

10. What is virtual memory? Mention its advantages.


A: Virtual memory is a memory management technique that gives an “idealized abstraction
of the storage resources” that are actually available on a given machine, enabling programs
to be larger than physical memory (RAM). It allows the system to use hard disk space to
simulate extra RAM, which is especially useful when multiple applications are running.

Advantages of Virtual Memory:

• Allows large programs to run: Programs can use more memory than is physically
available on the system.
• Isolation: Processes are isolated from each other, providing security and stability.
• Efficient memory utilization: Memory that isn't currently in use can be swapped
out to disk, freeing up space for other processes.
• Prevents program crashes: Virtual memory protects programs from running out of
memory and crashing by giving them more virtual space than physical RAM.

11. Differentiate external fragmentation with internal fragmentation.

A: External Fragmentation occurs when free memory is scattered in small blocks


across the system, so even though there is enough total free memory, there isn’t a large
enough contiguous block of memory for a process.

Internal Fragmentation occurs when allocated memory is larger than the amount
required by the process, leaving unused space inside allocated memory blocks.

Feature External Fragmentation Internal Fragmentation


Cause Free memory is scattered Memory block allocated is
across the system. larger than needed
Impact Unused free memory blocks
cause inefficient memory
use.
Solution Compaction or memory
management techniques
like paging.

12. Write short notes on swapping.

A: Swapping is a memory management technique where processes are moved between


main memory and a backing store (usually the hard disk). When a process is not actively
running, it may be swapped out to disk, freeing up memory for other processes. When the
process needs to run again, it is swapped back into memory.

Merits of Swapping:
• More processes can run concurrently: By swapping processes in and out of
memory, the system can handle more processes than can fit into physical memory.
• Efficient memory use: Allows better utilization of available memory.

Demerits of Swapping:

• Slower performance: Disk I/O operations are slower than RAM operations, leading
to delays.
• Increased system overhead: Constant swapping can put a strain on the system's
resources.

13. Briefly explain and compare, fixed and dynamic memory partitioning schemes.

A: •Fixed Partitioning: In fixed partitioning, the memory is divided into fixed-sized blocks,
and each process is assigned to one block. This can lead to inefficiency if processes are
smaller than the partition size (internal fragmentation).

•Dynamic Partitioning: In dynamic partitioning, memory is allocated in variable-sized


blocks according to the needs of each process. This method is more efficient but can lead
to external fragmentation over time.

Feature Fixed Partitioning Dynamic Partitioning


Memory Allocation Pre-defined, fixed size Variable size based on
partitions. process needs.
Fragmentation Leads to internal Can lead to external
fragmentation. fragmentation.
Flexibility Less flexible. More flexible and
efficient.
Memory Wastage Can lead to unused space Efficient, but may cause
in partitions. fragmentation
14. Explain with the help of examples FIFO and LRU, optical page replacement
algorithms with example reference string. Mention the merits and demerits of each of
the above algorithm.

A: (i) FIFO (First In First Out): This algorithm replaces the oldest page in memory when a
new page needs to be loaded, regardless of the page's usage.

Example: Reference String: 7, 0, 1, 2, 0, 3, 0, 4

• Assume 3-page memory. FIFO will load the pages as follows:


o 7, 0, 1 (pages in memory)
o 2 replaces 7
o 0 remains, 3 replaces 1 and 0 remains, 4 replaces 2
Merits:

• Simple and easy to implement.


• Works well in predictable environments.

Demerits:

• Poor performance in cases with frequent page swaps.


• May cause high page fault rate.

(ii) LRU (Least Recently Used): This algorithm replaces the page that has not been used
for the longest time.

Example:
Reference String: 7, 0, 1, 2, 0, 3, 0, 4

• Assume 3-page memory. LRU will load pages as follows:


o 7, 0, 1 (pages in memory)
o 2 replaces 7
o 0 remains, 3 replaces 1
o 0 remains, 4 replaces 2

Merits:

• More efficient than FIFO as it reduces the chances of unnecessary page


replacements.
• Tends to provide better performance.

Demerits:

• Requires keeping track of page access history.


• More complex and can involve overhead.

15. Explain how paging supports virtual memory. With neat diagram
explain hoe logical address is translated into physical address
A: Paging is a memory management scheme that eliminates the need for contiguous
memory allocation. Virtual memory is divided into fixed-size blocks called pages, and
physical memory is divided into blocks of the same size, called frames. When a process is
loaded, its pages are mapped into available frames, and the operating system maintains a
page table to manage the mapping.
Address Translation:

• Logical Address: Composed of two parts: page number and offset.


• Physical Address: Composed of a frame number and offset.

The translation from logical to physical address involves:

1. Extracting the page number from the logical address.


2. Looking up the frame number in the page table.
3. Combining the frame number with the offset to form the physical address.

Diagram:

16. Write about the techniques for structuring the page table.

A: Page tables are used to map virtual pages to physical frames. The techniques for
structuring page tables include:

• Simple Page Table: Each entry in the table contains the physical address of the
corresponding page in memory.
• Multi-level Page Table: The page table is broken into multiple levels to reduce the
size of the page table for large address spaces (e.g., a two-level page table).
• Inverted Page Table: Instead of having an entry for each page, this table has one
entry per physical frame, mapping it to the corresponding virtual page.
• Hashed Page Table: Uses a hash table to index entries, improving the efficiency of
looking up page mappings.

17. What is thrashing and explain the methods to avoid thrashing?

A: Thrashing occurs when the system spends more time swapping pages in and out of
memory than executing processes. This happens when the system is overloaded with too
many processes, leading to excessive page faults.
Methods to avoid thrashing:

• Increase physical memory: Adding more RAM can reduce page faults and prevent
excessive swapping.
• Use working set model: Dynamically adjust the number of processes running
based on memory requirements, ensuring that only processes with enough memory
are loaded.
• Effective page replacement algorithm: Use algorithms like LRU or optimal to
minimize the page fault rate.
• Load control: Reduce the number of processes running simultaneously.

18. Explain the basic concepts of segmentation in detail.

A: Segmentation is a memory management technique where memory is divided into


segments of varying sizes, each containing a different logical unit, such as code, data, or
stack. In segmentation, the programmer specifies logical divisions in a program, and the
operating system handles the allocation of memory based on these divisions.

Key Concepts:

• Segment Table: A data structure that holds the base address and length of each
segment.
• Logical Address: Composed of a segment number and an offset within that
segment.
• Physical Address: Computed by adding the offset to the base address of the
segment.

Segmentation provides a more flexible and intuitive way to manage memory compared to
paging because it reflects the structure of the program, making it easier to manage and
share

You might also like