Unit – 5
Memory Management
Memory Management
 Background
 Swapping
 Contiguous Allocation
 Paging
 Segmentation
 Segmentation with Paging
Background
 Program must be brought into memory and placed within a
process for it to be run
 Input queue – collection of processes on the disk that are
waiting to be brought into memory to run the program
 User programs go through several steps before being run
Binding of Instructions and Data to Memory
 Compile time
 Load time
 Execution time
Address binding of instructions and data to memory addresses can
happen at three different stages
Logical vs. Physical Address Space
 The concept of a logical address space that is bound to a
separate physical address space is central to proper memory
management
 Logical address – generated by the CPU; also referred to as
virtual address
 Physical address – address seen by the memory unit
 Logical and physical addresses are the same in compile-time and
load-time address-binding schemes; logical (virtual) and physical
addresses differ in execution-time address-binding scheme
Memory-Management Unit (MMU)
 Hardware device that maps virtual to physical address
 In MMU scheme, the value in the relocation register is
added to every address generated by a user process at
the time it is sent to memory
 The user program deals with logical addresses; it never
sees the real physical addresses
Dynamic relocation using a relocation register
Dynamic Loading
 Routine is not loaded until it is called
 Better memory-space utilization; unused routine is never
loaded
 Useful when large amounts of code are needed to handle
infrequently occurring cases
 No special support from the operating system is required
implemented through program design
Swapping
 A process can be swapped temporarily out of memory to a backing
store, and then brought back into memory for continued execution
 Backing store – fast disk large enough to accommodate copies of
all memory images for all users; must provide direct access to these
memory images
 Roll out, roll in – swapping variant used for priority-based
scheduling algorithms; lower-priority process is swapped out so
higher-priority process can be loaded and executed
 Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped
 Modified versions of swapping are found on many systems (i.e.,
UNIX, Linux, and Windows)
Schematic View of Swapping
Contiguous Allocation
 Main memory usually divided into two partitions:
 Resident operating system, usually held in low memory with
interrupt vector
 User processes then held in high memory
A base and a limit register define a logical address space
HW address protection with base and limit registers
Contiguous Allocation (Cont.)
 Multiple-partition allocation
 Hole – block of available memory; holes of various size are
scattered throughout memory
 When a process arrives, it is allocated memory from a hole
large enough to accommodate it
 Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
OS
process 5
process 8
process 2
OS
process 5
process 2
OS
process 5
process 2
OS
process 5
process 9
process 2
process 9
process 10
Dynamic Storage-Allocation Problem
 First-fit: Allocate the first hole that is big enough
 Best-fit: Allocate the smallest hole that is big enough; must search
entire list, unless ordered by size. Produces the smallest leftover
hole.
 Worst-fit: Allocate the largest hole; must also search entire list.
Produces the largest leftover hole.
How to satisfy a request of size n from a list of free holes
First-fit and best-fit better than worst-fit in terms of
speed and storage utilization
Fragmentation
 External Fragmentation – total memory space exists to
satisfy a request, but it is not contiguous
 Internal Fragmentation – allocated memory may be
slightly larger than requested memory; this size difference is
memory internal to a partition, but not being used
 Reduce external fragmentation by compaction
 Shuffle memory contents to place all free memory
together in one large block
External Fragmentation
Internal Fragmentation
Paging
 Logical address space of a process can be noncontiguous; process is
allocated physical memory whenever the latter is available
 Divide physical memory into fixed-sized blocks called frames (size is
power of 2, between 512 bytes and 8192 bytes)
 Divide logical memory into blocks of same size called pages.
 Keep track of all free frames
 To run a program of size n pages, need to find n free frames and load
program
 Set up a page table to translate logical to physical addresses
 Internal fragmentation
Address Translation Scheme
 Address generated by CPU is divided into:
 Page number (p) – used as an index into a page table
which contains base address of each page in physical
memory
 Page offset (d) – combined with base address to define
the physical memory address that is sent to the memory
unit
Address Translation Architecture
Paging Example
Paging Example
Free Frames
Before allocation After allocation
Implementation of Page Table
 Page table is kept in main memory
 Page-table base register (PTBR) points to the page
table
 Page-table length register indicates size of the page
table
 In this scheme every data/instruction access requires
two memory accesses. One for the page table and
one for the data/instruction.
 The two memory access problem can be solved by the
use of a special fast-lookup hardware cache called
associative memory or translation look-aside
buffers (TLBs)
Paging Hardware With TLB
Unit 5Memory management.pptx
Memory Protection
 Memory protection implemented by associating
protection bit with each frame
 Valid-invalid bit attached to each entry in the page
table:
 “valid” indicates that the associated page is in the
process’ logical address space, and is thus a legal
page
 “invalid” indicates that the page is not in the process’
logical address space
Valid (v) or Invalid (i) Bit In A Page Table
Two-Level Paging Example
 A logical address (on 32-bit machine with 4K page size) is divided into:
 a page number consisting of 20 bits
 a page offset consisting of 12 bits
 Since the page table is paged, the page number is further divided into:
 a 10-bit page number
 a 10-bit page offset
 Thus, a logical address is as follows:
 where pi is an index into the outer page table, and p2 is the displacement within the
page of the outer page table
page number page offset
pi p2 d
10 10 12
Two-Level Page-Table Scheme
Address-Translation Scheme
 Address-translation scheme for a two-level 32-bit paging
architecture
Inverted Page Table
 One entry for each real page of memory
 Entry consists of the virtual address of the page stored in
that real memory location, with information about the
process that owns that page
 Decreases memory needed to store each page table, but
increases time needed to search the table when a page
reference occurs
 Use hash table to limit the search to one — or at most a
few — page-table entries
Inverted Page Table Architecture
Segmentation
 Memory-management scheme that supports user view of memory
 A program is a collection of segments. A segment is a logical unit
such as:
main program,
procedure,
function,
method,
object,
local variables, global variables,
common block,
stack,
symbol table, arrays
User’s View of a Program
Logical View of Segmentation
1
3
2
4
1
4
2
3
user space physical memory space
Address Translation Architecture
Example of Segmentation

More Related Content

PPT
Chapter 8 - Main Memory
PPT
PPT
PPT
Ch9 OS
 
PPT
Memory+management
PPT
Main memory os - prashant odhavani- 160920107003
Chapter 8 - Main Memory
Ch9 OS
 
Memory+management
Main memory os - prashant odhavani- 160920107003

Similar to Unit 5Memory management.pptx (20)

PPT
unit-4 class (2).ppt,Memory managements part-1
PPT
Memory management
PPTX
Memory Managment(OS).pptx
PPT
Bab 4
 
PDF
CH08.pdf
PPT
Chapter 9 OS
 
PPTX
Memory Management
PPTX
Main Memory Management in Operating System
PPTX
Unit-4 swapping.pptx
PPTX
HW29kkkkkkkkkkkkkkkkkkkmmmmkkmmkkk454.pptx
PPT
memory management and Virtual Memory.ppt
PPT
Cache replacement policies,cache miss,writingtechniques
PPT
Memory management principles in operating systems
PDF
CS6401 OPERATING SYSTEMS Unit 3
PDF
Cs8493 unit 3
PDF
Cs8493 unit 3
PPT
PPTX
Paging +Algorithem+Segmentation+memory management
unit-4 class (2).ppt,Memory managements part-1
Memory management
Memory Managment(OS).pptx
Bab 4
 
CH08.pdf
Chapter 9 OS
 
Memory Management
Main Memory Management in Operating System
Unit-4 swapping.pptx
HW29kkkkkkkkkkkkkkkkkkkmmmmkkmmkkk454.pptx
memory management and Virtual Memory.ppt
Cache replacement policies,cache miss,writingtechniques
Memory management principles in operating systems
CS6401 OPERATING SYSTEMS Unit 3
Cs8493 unit 3
Cs8493 unit 3
Paging +Algorithem+Segmentation+memory management
Ad

Recently uploaded (20)

PDF
The TKT Course. Modules 1, 2, 3.for self study
PPTX
Reproductive system-Human anatomy and physiology
PDF
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2015).pdf
PDF
PUBH1000 - Module 6: Global Health Tute Slides
PDF
Chevening Scholarship Application and Interview Preparation Guide
PDF
Laparoscopic Colorectal Surgery at WLH Hospital
PDF
faiz-khans about Radiotherapy Physics-02.pdf
PPTX
PLASMA AND ITS CONSTITUENTS 123.pptx
PPTX
Power Point PR B.Inggris 12 Ed. 2019.pptx
PPTX
Thinking Routines and Learning Engagements.pptx
PPTX
UNIT_2-__LIPIDS[1].pptx.................
PPTX
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
PDF
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
PDF
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
PDF
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
PDF
Journal of Dental Science - UDMY (2020).pdf
PDF
Diabetes Mellitus , types , clinical picture, investigation and managment
PDF
Physical education and sports and CWSN notes
PDF
Farming Based Livelihood Systems English Notes
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
The TKT Course. Modules 1, 2, 3.for self study
Reproductive system-Human anatomy and physiology
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2015).pdf
PUBH1000 - Module 6: Global Health Tute Slides
Chevening Scholarship Application and Interview Preparation Guide
Laparoscopic Colorectal Surgery at WLH Hospital
faiz-khans about Radiotherapy Physics-02.pdf
PLASMA AND ITS CONSTITUENTS 123.pptx
Power Point PR B.Inggris 12 Ed. 2019.pptx
Thinking Routines and Learning Engagements.pptx
UNIT_2-__LIPIDS[1].pptx.................
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
Journal of Dental Science - UDMY (2020).pdf
Diabetes Mellitus , types , clinical picture, investigation and managment
Physical education and sports and CWSN notes
Farming Based Livelihood Systems English Notes
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
Ad

Unit 5Memory management.pptx

  • 1. Unit – 5 Memory Management
  • 2. Memory Management  Background  Swapping  Contiguous Allocation  Paging  Segmentation  Segmentation with Paging
  • 3. Background  Program must be brought into memory and placed within a process for it to be run  Input queue – collection of processes on the disk that are waiting to be brought into memory to run the program  User programs go through several steps before being run
  • 4. Binding of Instructions and Data to Memory  Compile time  Load time  Execution time Address binding of instructions and data to memory addresses can happen at three different stages
  • 5. Logical vs. Physical Address Space  The concept of a logical address space that is bound to a separate physical address space is central to proper memory management  Logical address – generated by the CPU; also referred to as virtual address  Physical address – address seen by the memory unit  Logical and physical addresses are the same in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme
  • 6. Memory-Management Unit (MMU)  Hardware device that maps virtual to physical address  In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory  The user program deals with logical addresses; it never sees the real physical addresses
  • 7. Dynamic relocation using a relocation register
  • 8. Dynamic Loading  Routine is not loaded until it is called  Better memory-space utilization; unused routine is never loaded  Useful when large amounts of code are needed to handle infrequently occurring cases  No special support from the operating system is required implemented through program design
  • 9. Swapping  A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution  Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images  Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed  Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped  Modified versions of swapping are found on many systems (i.e., UNIX, Linux, and Windows)
  • 10. Schematic View of Swapping
  • 11. Contiguous Allocation  Main memory usually divided into two partitions:  Resident operating system, usually held in low memory with interrupt vector  User processes then held in high memory
  • 12. A base and a limit register define a logical address space
  • 13. HW address protection with base and limit registers
  • 14. Contiguous Allocation (Cont.)  Multiple-partition allocation  Hole – block of available memory; holes of various size are scattered throughout memory  When a process arrives, it is allocated memory from a hole large enough to accommodate it  Operating system maintains information about: a) allocated partitions b) free partitions (hole) OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10
  • 15. Dynamic Storage-Allocation Problem  First-fit: Allocate the first hole that is big enough  Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole.  Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. How to satisfy a request of size n from a list of free holes First-fit and best-fit better than worst-fit in terms of speed and storage utilization
  • 16. Fragmentation  External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous  Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used  Reduce external fragmentation by compaction  Shuffle memory contents to place all free memory together in one large block
  • 19. Paging  Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter is available  Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8192 bytes)  Divide logical memory into blocks of same size called pages.  Keep track of all free frames  To run a program of size n pages, need to find n free frames and load program  Set up a page table to translate logical to physical addresses  Internal fragmentation
  • 20. Address Translation Scheme  Address generated by CPU is divided into:  Page number (p) – used as an index into a page table which contains base address of each page in physical memory  Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit
  • 24. Free Frames Before allocation After allocation
  • 25. Implementation of Page Table  Page table is kept in main memory  Page-table base register (PTBR) points to the page table  Page-table length register indicates size of the page table  In this scheme every data/instruction access requires two memory accesses. One for the page table and one for the data/instruction.  The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs)
  • 28. Memory Protection  Memory protection implemented by associating protection bit with each frame  Valid-invalid bit attached to each entry in the page table:  “valid” indicates that the associated page is in the process’ logical address space, and is thus a legal page  “invalid” indicates that the page is not in the process’ logical address space
  • 29. Valid (v) or Invalid (i) Bit In A Page Table
  • 30. Two-Level Paging Example  A logical address (on 32-bit machine with 4K page size) is divided into:  a page number consisting of 20 bits  a page offset consisting of 12 bits  Since the page table is paged, the page number is further divided into:  a 10-bit page number  a 10-bit page offset  Thus, a logical address is as follows:  where pi is an index into the outer page table, and p2 is the displacement within the page of the outer page table page number page offset pi p2 d 10 10 12
  • 32. Address-Translation Scheme  Address-translation scheme for a two-level 32-bit paging architecture
  • 33. Inverted Page Table  One entry for each real page of memory  Entry consists of the virtual address of the page stored in that real memory location, with information about the process that owns that page  Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs  Use hash table to limit the search to one — or at most a few — page-table entries
  • 34. Inverted Page Table Architecture
  • 35. Segmentation  Memory-management scheme that supports user view of memory  A program is a collection of segments. A segment is a logical unit such as: main program, procedure, function, method, object, local variables, global variables, common block, stack, symbol table, arrays
  • 36. User’s View of a Program
  • 37. Logical View of Segmentation 1 3 2 4 1 4 2 3 user space physical memory space