Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
73 views12 pages

Memory Management for IT Pros

Uploaded by

Debasish Sarangi
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)
73 views12 pages

Memory Management for IT Pros

Uploaded by

Debasish Sarangi
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/ 12

Memory Management System Strategies: IT is essential for allocating, tracking, and organizing

memory resources efficiently, The key strategies in memory management include


Contiguous Memory Allocation, Paging, Segmentation, and Swapping. These strategies address how
memory is allocated to processes, how fragmentation is managed, and how the system can efficiently
handle memory. Let's dive into these strategies: Contiguous Memory Allocation: Contiguous
Memory Allocation is one of the simplest memory management schemes, where memory is divided
into fixed-size or variable-size partitions, and each process is allocated a single contiguous block of
memory. Types: Fixed Partitioning: The memory is divided into fixed-size partitions, and each process
is allocated a partition. If a process does not fit in a partition, it cannot be loaded into memory. Cons:
Can lead to internal fragmentation, where the memory allocated to a process is larger than the
required size. Dynamic Partitioning: Memory is allocated in variable-size blocks based on the
process's needs. The OS dynamically divides memory into partitions of varying sizes and assigns them
to processes. Pros: More flexible than fixed partitioning. Cons: Leads to external fragmentation,
where free memory is scattered in small blocks that are too small to allocate to processes, causing
ineffcient memory use. Problems: Internal Fragmentation: In fixed partitioning, unused memory
within a partition that is too small for another process. External Fragmentation: In dynamic
partitioning, free memory is scattered across the system in small blocks, making it difficult to allocate
large contiguous blocks to proces
1.
2.
Paging: Paging is a memory management technique that eliminates the problem of external fragmentation by breaking
physical memory and logical memory into fixed-size blocks called pages and page frames, respectively. How it Works: Page: A
block Of logical memory. Page Frame: A corresponding block of physical memory (same size as a page). The process is divided
into pages, and these pages are loaded into available page frames in physical memory. The operating system keeps track of
the mapping between logical pages and physical page frames using a page table. Advantages: Eliminates Extemal
Fragmentation. Pages can be scattered in physical memory, avoiding the need for contiguous space. Efficient Memory Use:
The operating system can allocate memory in fixed-size chunks, which helps in better managing memory. Disadvantages:
Internal Fragmentation: The last page of a process may not be fully utilized if the process doesn't fit into the full page size.
leading to wasted space within that page. Page Table Overhead; Each process needs a page table to track the mappings of
pages to page frames, and large processes can require large page tables. Example:A process may have 10 pages, each 4 KB in
size. If the physical memory contains 4 KB page frames, the OS will load these pages into 1 0 different locations in physical
memory. The page table maps each page to its respective frame.
3.
Segmentation: Segmentation is a memory management scheme that divides memory into segments, which are variable-
sized blocks. Each segment represents a logical unit such as code, data. or stack Unlike paging, which divides memory into
fixed-size chunks, segmentation divides it according to the logical structure of a program How it Works: A program is
divided into segments, each of which contains different types of data (e.g.. code, stack. heap).Each segment has a starting
address and a length, and segments are allocated in contiguous memory blocks. The operating system uses a segment table
to manage the base address and size of each segment. Advantages: Logical Organization: It allows the system to manage
memory in a way that reflects the program's structure, making it easier to handle things like function calls (stack), data
(heap), and code (text). No Internal Fragmentation: Since segments are allocated based on logical divisions, they do not
suffer from internal fragmentation, unlike paging. Disadvantages: External Fragmentation: If free memory blocks are
scattered, it may be difficult to allocate large contiguous blocks for segments. leading to external fragmentation. Complex
Memory Management Managing segments requires more complex memory allocation techniques and overhead.
Example:A program might consist of three segments: one for code (100 KB)' one for data (200 KB), and one for the stack (50
KB), These segments are allocated in contiguous memory locations.
4.
Swapping: Swapping is not a memory allocation strategy In itself but a technique used to manage memory in a system that has limited physical
memory. It allows the operating system to move entire processes in and aut of physical memory to disk (swap space) as needed, This is
particularly useful in systems that are running more processes than can fit in physical memory. How it Works: When the system runs low on
memory, the OS can move a process or part of a process (e.g., apage or segment) from RAM to disk. This "swap out" frees up memory for other
processes. When the swapped-out pracess or data is needed again, it is brought back inta RAM with a 'swap in' operation. The area on the disk
where the swappedout process resides is called the swap space. Advantages: Increased Process Capacity: Swapping allows the system to run
more processes than can fit into the physical memory. Efficient Memory use: It maximizes the use of available memory by moving idle processes
out of RAM. Disadvantages: Performance Overhead: Swapping involves reading from and writing to the disk, which is much slower than
accessing RAM. This can cause performance degradation (known as thrashing) if excessive swapping occurs. Disk Space Consumptiom Swap
space can take up a sign 'ficant amount of disk space
Summary of Strategies:

Strategy
Disadvantages
Contiguous Allocates memory in a single Simple to imp ement. Can cause internal and

Allocation contiguous block. external fragmentation.

Paging Divides memory inta fixed- Eliminates external Causes internal

size pages and page frames. fragmentation.


fragmentation and page table
overhead.

Divides memory into Logical organization and Cen cause external


Segmentation
no internal fragmentation fragmentation_
variable-sized segments based on
logical units.

Swapping Moves processes between Allows more processes to Causes performance

RAM and disk to free up memory. run With limited RAM. overhead dueto disk I/O.

Conclusion: Contiguous Allocation is simple but suffers from fragmentation issues. Paging solves external fragmentation but can cause internal
fragmentation and requires maintaining page tables. Segmentation allows for a more logical allocation of memory but can suffer from external
fragmentation. Swapping is a technique used to deal with memory shortages by temporarily moving processes to disk, but it can introduce
significant performance overhead.
Virtual Memory Management: Virtual Memory is a memory management technique that gives an application the impression it has
contiguous working memory (or a large range af addresses), while in reality, it may be physically fragmented and even stored in
secondary storage (such as a disk). The goal of virtual memory is to extend the apparent available memory beyond what is physically
installed in the system, enabling more efficient and flexible use of resources. Key Concepts of Virtual Memory Virtual Memory allows
processes to access memory without worrying about the underlying physical memory limitations. It uses a combination of physical
memory (RAM) and disk space (usually known as swap space) to simulate a larger amount of RAM. Address Translation: The operating
system maps virtual addresses used by processes to physical addresses in RAM using structures like page tables. Advantages of Virtual
Memory: Isolation: Each process has own virtual address space, which prevents one process from accessing the memory of another.
Simplifies Programming. Programs can be written as if they have unlimited memory without needing to worry about the actual
limitations of physical memory. Better Resource Utilization: Virtual memory allows the system to run more processes than can fit in
physical memory by swapping portions of programs in and out cf disk storage.Demand Paging: Demand Paging [s a memory management
technique where pages of a program are only loaded into memory when they are needed (i.e., on demand). This avoids loading the entire
program into memory at once, saving memory space and allowing for more efficient use of system resources. How Demand Paging
Works When a process starts, only a small part (such as the initial page) is loaded into physical Memory. If the process tries to access a
page that is not in memory, a page fault occurs. The operating system then loads the required page from disk (swap space) into physical
memory, replacing an existing page if necessary. The process resumes execution as soon as the page is loaded into memory. Advantages:
Efficient Memory Use: Only the pages that are needed are loaded into memory, reducing the memory footprint. Faster Process Startup:
Programs start executing more quickly since not all pages need to be loaded initially. Disadvantages: Page Fault Overhead. Every time a
page is accessed that isnt in memory, a page fault occurs, which can slow down the system because accessing disk is much slower than
accessing RAM
1.
Page Replacement: Page Replacement is a technique used in virtual memory systems when there
is not enough physical memory (RAM) to hold all the pages required by running processes. When a
process needs a page that is not in memory (a page fault occurs), the operating system must
replace an existing page in memory to make space for the new one. Page Replacement
Algorithms: Some of the commonly used page replacement algorithms are: FIFO (First-in, First-
out): The simplest page replacement algorithm. It replaces the page that has been in memory the
longest (the first one that was brought into memory). Disadvantage. FIFO can suffer from BeladYs
Anomaly, where adding more frames can cause more page faults. LRU (Least Recently Used) This
algorithm replaces the page that has not been used for the longest period of time. The operating
system keeps track of the usage of pages. Advantage: LRU generally performs better than FIFO in
many scenarios. Optimal (MIN): The optimal algorithm replaces the page that will not be used for
the longest period of time in the future. While this gives the best possible performance, it is
impractical in real systems because it requires future knowledge. Clock Algorithm (Second
Chance): This is a more practical approximation of LRU. Pages are arranged in a circular queue,
and when a page needs to be replaced, the algorithm checks the "use" bit to determine if a page
has been recently used. If it has, the page gets a •second chance' and the bit is cleared. If not, ifs
replaced. Page Replacement Process: When a page fault occurs and no free frames are available,
the OS selects a page to replace using one of the replacement algorithms. The selected page is
written back to disk (if it has been modified), and the new page is loaded into memory. The page
table is updated to reflect the new mapping between virtual and physical memory.
2.
Thrashing: Thrashing occurs when the system spends most of its time swapping pages in and
out of memory rather than executing processes. This happens when there is not enough
physical memory to support all the running processes, causing excessive page faults. As a
result, the system becomes extremely slow and unresponsive. Causes of Thrashing: High
Degree of Multiprogramming: When too many processes are loaded into memory. each
process might not have enough memory pages to execute efficiently, causing frequent page
faults. Insufficient Physical Memory: If the system is running more processes than it has RAM
for, it will constantly swap pages between RAM and disk, leading to thrashing. How Thrashing
Works: Multiple processes continuously request pages that are not in memory. The operating
system is forced to swap out pages to bring in the required ones. This results in continuous
swapping (high I/O operations), and the CPU spends more time swapping than actually
executing processes. Symptoms of Thrashing: High Disk Activity: Excessive page swaps
between RAM and disk (swap space). Slow System Performance: Processes take significantly
longer to execute, and the system becomes unresponsive. High CPU Utilization but No
Progress: The CPU might be highly utilized by the OS due to constant page faults, but actual
program execution is minimal. Solutions to Thrashing: Reduce the degree of
multiprogramming: Limit the number of processes running concurrently in the system.
Increase physical memory: Adding more RAM can reduce thrashing by allowing more pages to
stay in memory at once. Use working sets• The OS can track the "working set• of each
process, which is the set of pages that a process actively uses. When the working set of a
process exceeds available memory, the system may reduce the number of processes running
or swap out less-needed pages. Page Fault Frequency (PFF): Adjust the allocation of memory
to processes based on their page fault rates. A process with frequent page faults might be
allocated more memory to avoid thrashing.
Concept Description Advantages Disadvantages
Virtual Uses disk space to extend Enables running large Disk I/O overhead when

available memory beyond programs and multiple pages are swapped inVout
physical RAM processes.

Loads pages into memory only Saves memoy and Page fau overhead slows
Demand
Paging when needed (on demand). speeds up process startup. down execution.

page Replaces pages •n memory Allows processes to page replacement

Replacement when thetés not enough access more memory algorithms may CäUSé
space. than physically avail able. overhead.

Thrashing When excessive swapping WA Significant system

occurs, and the system slowdown and


becomes too slow to execute tasks. unresponsiveness.

Summary of Key Concepts:


Conclusion:

Virtual Memory allows the operating system to manage memory efficiently and enables programs to run even if the system
doesn't have enough physical RAM.

Demand Paging reduces memory usage by only loading pages as they are needed, improving resource utilization, page
Replacement ensures that the operating system can manage memory efficiently. even when physical memory is full, by selecting
pages to swap out based on algorithms like FIFO,
LRU, and Optimal,

Thrashing is a problem that occurs when the system is overloaded with processes and insufficient memory, leading to excessive
paging and poor performance.

You might also like