Memory Management in Operating Systems
•Memory management is a critical function of
an operating system (OS) that handles the
allocation, tracking, and deallocation of
memory resources to processes and
applications.
•It ensures optimal utilization of available
memory, prevents conflicts, and enhances
system performance.
Logical and Physical Address in Operating System
• A logical address is generated by the CPU while a
program is running.
• The logical address is a virtual address as it does
not exist physically, therefore, it is also known as a
Virtual Address.
• The physical address describes the precise position
of necessary data in a memory. Before they are
used, the MMU must map the logical address to
the physical address.
• In operating systems, logical and physical
addresses are used to manage and access memory.
• A physical address is the actual address in the main
memory where data is stored. It is a location in
physical memory, as opposed to a virtual address.
• Physical addresses are used by the
Memory Management Unit (MMU) to translate logical
addresses into physical addresses.
• The user must use the corresponding logical address to
go to the physical address rather than directly
accessing the physical address.
• For a computer program to function, physical memory
space is required. Therefore, the logical address and
physical address need to be mapped before the
program is run.
• The translation from logical to physical
addresses is performed by the operating
system’s memory management unit (MMU)
within the computer’s hardware architecture.
The MMU uses a page table to translate
logical addresses into physical addresses. The
page table maps each logical page number to
a physical frame number.
Functions of Memory Management
• Allocation & Deallocation: Assigns memory space to
processes and reclaims it when no longer needed.
• Tracking: Keeps records of memory usage (which
memory is free, which is allocated).
• Protection: Ensures that processes do not interfere
with each other’s memory space.
• Swapping & Paging: Moves processes in and out of
memory to optimize usage.
• Segmentation: Divides memory logically to manage
different parts efficiently.
Dynamic relocation using a relocation
register
• The physical hardware of a computer that
manages its virtual memory and caching
functions is called the memory management
unit (MMU).
•
Difference Between Logical address and Physical Address
Parameter LOGICAL ADDRESS PHYSICAL ADDRESS
Basic generated by CPU location in a memory unit
Address Space
Logical Address Space is set of all
logical addresses generated by CPU in
reference to a program.
Physical Address is set of all physical
addresses mapped to the
corresponding logical addresses.
Visibility User can view the logical address of a
program.
User can never view physical address
of program.
Generation generated by the CPU Computed by MMU
Access The user can use the logical address to
access the physical address.
The user can indirectly access physical
address but not directly.
Editable Logical address can be change. Physical address will not change.
Also called virtual address. real address.
Swapping
• To increase CPU utilization in
multiprogramming, a memory management
scheme known as swapping can be used.
• Swapping is the process of bringing a process
into memory and then temporarily copying it
to the disc after it has run for a while.
• The purpose of swapping in an operating
system is to access data on a hard disc and
move it to RAM so that application programs
can use it.
Swapping involves moving processes between
main memory and disk
Memory Management Techniques
• 1. Contiguous Memory Allocation
• Memory is allocated in a single contiguous block.
• Types:
– Fixed Partitioning: Memory is divided into fixed-size
partitions.
– Dynamic Partitioning: Partitions are created
dynamically as needed.
• Drawbacks: Can lead to fragmentation
(internal/external).
• Contiguous memory allocation is a memory
allocation strategy. As the name implies, we
utilize this technique to assign contiguous blocks
of memory to each task.
• In this technique, memory is allotted in a
continuous way to the processes. Contiguous
Memory Management has two types:
• Fixed(or Static) Partition
• Variable(or Dynamic) Partitioning
Contiguous Memory Management Techniques
1. Fixed Partition Scheme
• In the fixed partition scheme, memory is divided into fixed number of
partitions.
• In the fixed partition, in every partition only one process will be
accommodated.
• Degree of multi-programming is restricted by number of partitions in the
memory.
• Maximum size of the process is restricted by maximum size of the
partition.
• Every partition is associated with the limit registers.
• Limit Registers: It has two limit:
• Lower Limit: Starting address of the partition.
• Upper Limit: Ending address of the partition.
• Internal Fragmentation is found in fixed partition
scheme. To overcome the problem of internal
fragmentation, instead of fixed partition scheme,
variable partition scheme is used.
• Disadvantages Fixed partition scheme
• Maximum process size <= Maximum partition size.
• The degree of multiprogramming is directly
proportional to the number of partitions.
• If a process of 19kb wants to allocate and we have
free space which is not continuous we are not able
to allocate the space.
2. Variable Partition Scheme
• In the variable partition scheme, initially memory
will be single continuous free block. Whenever the
request by the process arrives, accordingly
partition will be made in the memory.
• If the smaller processes keep on coming then the
larger partitions will be made into smaller
partitions.
• In variable partition schema initially, the memory
will be full contiguous free block
• Memory divided into partitions according to the
process size where process size will vary.
• External Fragmentation is found in variable partition scheme.
To overcome the problem of external fragmentation,
compaction technique is used or non-contiguous memory
management techniques are used.
• Solution of External Fragmentation
• 1. Compaction
• Moving all the processes toward the top or towards the
bottom to make free available memory in a single continuous
place is called compaction. Compaction is undesirable to
implement because it interrupts all the running processes in
the memory.
• Disadvantage of Compaction
• Page fault can occur.
• It consumes CPU time (overhead).
2. Non-contiguous memory allocation
• Physical address space: Main memory (physical
memory) is divided into blocks of the same size
called frames. frame size is defined by the
operating system by comparing it with the size of
the process.
• Logical Address space: Logical memory is divided
into blocks of the same size called process pages.
page size is defined by hardware system and
these pages are stored in the main memory
during the process in non-contiguous frames.
2. Paging
• Divides memory into fixed-size pages.
• The process address space is split into pages,
which map to frames in physical memory.
• A frame is a fixed-size block of physical memory
(RAM) in which pages of a process are loaded.
Frames are used in paging, a memory
management technique that allows non-
contiguous memory allocation to processes.
• Solves external fragmentation but introduces
page tables for mapping.
• The physical memory is divided into fixed-size
frames (e.g., 4KB per frame).The logical
memory (process memory) is divided into
pages of the same size.
• Pages are mapped to frames using a page
table.
3. Segmentation
• Divides memory into variable-sized segments
based on logical divisions like functions,
arrays, etc.
• Each segment has a base and limit address.
• May suffer from external fragmentation.
4. Virtual Memory
• Uses a combination of RAM and disk space to
extend available memory.
• Implements paging and swapping to load only
necessary data into RAM.
• Allows execution of large programs beyond
physical memory limits.
Memory Management Challenges
• Fragmentation
– Internal: Wasted space inside allocated memory blocks.
– External: Free space is available but too scattered to be useful.
– Solution: Paging and Compaction.
• Thrashing
– Excessive swapping between RAM and disk, slowing down the
system.
– Solution: Working set model, increasing RAM.
• Overhead of Page Tables
– Large page tables can consume significant memory.
– Solution: Multi-level page tables, TLB (Translation Lookaside Buffer).
• Memory management plays a vital role in
system efficiency, allowing multiple processes
to run concurrently while ensuring security
and performance.
• Techniques like paging, segmentation, and
virtual memory help balance trade-offs
between speed and resource usage.
Address Spaces in Operating Systems
• An address space is the range of memory
addresses that a process or system can use.
• It plays a crucial role in how an operating
system (OS) manages memory and ensures
process isolation and security.
Types of Address Spaces
• Logical Address Space (Virtual Address Space)
– The set of addresses a process can reference.
– Generated by the CPU during execution.
– Managed by the OS using techniques like paging and segmentation.
– Example: A process might think it has access to a 4GB address space,
but in reality, only a part of it is mapped to physical memory.
• Physical Address Space
– The actual memory addresses in RAM.
– Logical addresses must be translated into physical addresses.
– The Memory Management Unit (MMU) and Page Table handle this
translation.
Memory Management in Operating Systems ppt.pptx

Memory Management in Operating Systems ppt.pptx

  • 1.
    Memory Management inOperating Systems •Memory management is a critical function of an operating system (OS) that handles the allocation, tracking, and deallocation of memory resources to processes and applications. •It ensures optimal utilization of available memory, prevents conflicts, and enhances system performance.
  • 2.
    Logical and PhysicalAddress in Operating System • A logical address is generated by the CPU while a program is running. • The logical address is a virtual address as it does not exist physically, therefore, it is also known as a Virtual Address. • The physical address describes the precise position of necessary data in a memory. Before they are used, the MMU must map the logical address to the physical address. • In operating systems, logical and physical addresses are used to manage and access memory.
  • 3.
    • A physicaladdress is the actual address in the main memory where data is stored. It is a location in physical memory, as opposed to a virtual address. • Physical addresses are used by the Memory Management Unit (MMU) to translate logical addresses into physical addresses. • The user must use the corresponding logical address to go to the physical address rather than directly accessing the physical address. • For a computer program to function, physical memory space is required. Therefore, the logical address and physical address need to be mapped before the program is run.
  • 4.
    • The translationfrom logical to physical addresses is performed by the operating system’s memory management unit (MMU) within the computer’s hardware architecture. The MMU uses a page table to translate logical addresses into physical addresses. The page table maps each logical page number to a physical frame number.
  • 5.
    Functions of MemoryManagement • Allocation & Deallocation: Assigns memory space to processes and reclaims it when no longer needed. • Tracking: Keeps records of memory usage (which memory is free, which is allocated). • Protection: Ensures that processes do not interfere with each other’s memory space. • Swapping & Paging: Moves processes in and out of memory to optimize usage. • Segmentation: Divides memory logically to manage different parts efficiently.
  • 6.
    Dynamic relocation usinga relocation register
  • 7.
    • The physicalhardware of a computer that manages its virtual memory and caching functions is called the memory management unit (MMU). •
  • 8.
    Difference Between Logicaladdress and Physical Address Parameter LOGICAL ADDRESS PHYSICAL ADDRESS Basic generated by CPU location in a memory unit Address Space Logical Address Space is set of all logical addresses generated by CPU in reference to a program. Physical Address is set of all physical addresses mapped to the corresponding logical addresses. Visibility User can view the logical address of a program. User can never view physical address of program. Generation generated by the CPU Computed by MMU Access The user can use the logical address to access the physical address. The user can indirectly access physical address but not directly. Editable Logical address can be change. Physical address will not change. Also called virtual address. real address.
  • 9.
    Swapping • To increaseCPU utilization in multiprogramming, a memory management scheme known as swapping can be used. • Swapping is the process of bringing a process into memory and then temporarily copying it to the disc after it has run for a while. • The purpose of swapping in an operating system is to access data on a hard disc and move it to RAM so that application programs can use it.
  • 10.
    Swapping involves movingprocesses between main memory and disk
  • 11.
    Memory Management Techniques •1. Contiguous Memory Allocation • Memory is allocated in a single contiguous block. • Types: – Fixed Partitioning: Memory is divided into fixed-size partitions. – Dynamic Partitioning: Partitions are created dynamically as needed. • Drawbacks: Can lead to fragmentation (internal/external).
  • 12.
    • Contiguous memoryallocation is a memory allocation strategy. As the name implies, we utilize this technique to assign contiguous blocks of memory to each task. • In this technique, memory is allotted in a continuous way to the processes. Contiguous Memory Management has two types: • Fixed(or Static) Partition • Variable(or Dynamic) Partitioning
  • 14.
    Contiguous Memory ManagementTechniques 1. Fixed Partition Scheme • In the fixed partition scheme, memory is divided into fixed number of partitions. • In the fixed partition, in every partition only one process will be accommodated. • Degree of multi-programming is restricted by number of partitions in the memory. • Maximum size of the process is restricted by maximum size of the partition. • Every partition is associated with the limit registers. • Limit Registers: It has two limit: • Lower Limit: Starting address of the partition. • Upper Limit: Ending address of the partition.
  • 15.
    • Internal Fragmentationis found in fixed partition scheme. To overcome the problem of internal fragmentation, instead of fixed partition scheme, variable partition scheme is used. • Disadvantages Fixed partition scheme • Maximum process size <= Maximum partition size. • The degree of multiprogramming is directly proportional to the number of partitions. • If a process of 19kb wants to allocate and we have free space which is not continuous we are not able to allocate the space.
  • 16.
    2. Variable PartitionScheme • In the variable partition scheme, initially memory will be single continuous free block. Whenever the request by the process arrives, accordingly partition will be made in the memory. • If the smaller processes keep on coming then the larger partitions will be made into smaller partitions. • In variable partition schema initially, the memory will be full contiguous free block • Memory divided into partitions according to the process size where process size will vary.
  • 17.
    • External Fragmentationis found in variable partition scheme. To overcome the problem of external fragmentation, compaction technique is used or non-contiguous memory management techniques are used. • Solution of External Fragmentation • 1. Compaction • Moving all the processes toward the top or towards the bottom to make free available memory in a single continuous place is called compaction. Compaction is undesirable to implement because it interrupts all the running processes in the memory. • Disadvantage of Compaction • Page fault can occur. • It consumes CPU time (overhead).
  • 18.
    2. Non-contiguous memoryallocation • Physical address space: Main memory (physical memory) is divided into blocks of the same size called frames. frame size is defined by the operating system by comparing it with the size of the process. • Logical Address space: Logical memory is divided into blocks of the same size called process pages. page size is defined by hardware system and these pages are stored in the main memory during the process in non-contiguous frames.
  • 19.
    2. Paging • Dividesmemory into fixed-size pages. • The process address space is split into pages, which map to frames in physical memory. • A frame is a fixed-size block of physical memory (RAM) in which pages of a process are loaded. Frames are used in paging, a memory management technique that allows non- contiguous memory allocation to processes. • Solves external fragmentation but introduces page tables for mapping.
  • 22.
    • The physicalmemory is divided into fixed-size frames (e.g., 4KB per frame).The logical memory (process memory) is divided into pages of the same size. • Pages are mapped to frames using a page table.
  • 23.
    3. Segmentation • Dividesmemory into variable-sized segments based on logical divisions like functions, arrays, etc. • Each segment has a base and limit address. • May suffer from external fragmentation.
  • 24.
    4. Virtual Memory •Uses a combination of RAM and disk space to extend available memory. • Implements paging and swapping to load only necessary data into RAM. • Allows execution of large programs beyond physical memory limits.
  • 25.
    Memory Management Challenges •Fragmentation – Internal: Wasted space inside allocated memory blocks. – External: Free space is available but too scattered to be useful. – Solution: Paging and Compaction. • Thrashing – Excessive swapping between RAM and disk, slowing down the system. – Solution: Working set model, increasing RAM. • Overhead of Page Tables – Large page tables can consume significant memory. – Solution: Multi-level page tables, TLB (Translation Lookaside Buffer).
  • 26.
    • Memory managementplays a vital role in system efficiency, allowing multiple processes to run concurrently while ensuring security and performance. • Techniques like paging, segmentation, and virtual memory help balance trade-offs between speed and resource usage.
  • 27.
    Address Spaces inOperating Systems • An address space is the range of memory addresses that a process or system can use. • It plays a crucial role in how an operating system (OS) manages memory and ensures process isolation and security.
  • 28.
    Types of AddressSpaces • Logical Address Space (Virtual Address Space) – The set of addresses a process can reference. – Generated by the CPU during execution. – Managed by the OS using techniques like paging and segmentation. – Example: A process might think it has access to a 4GB address space, but in reality, only a part of it is mapped to physical memory. • Physical Address Space – The actual memory addresses in RAM. – Logical addresses must be translated into physical addresses. – The Memory Management Unit (MMU) and Page Table handle this translation.