SlideShare a Scribd company logo
Lecture Plan UNIT-IV
Lecture Topic                                    Slide
No.                                              No.
1            Swapping                            2-7
2            contiguous memory allocation        8-12
3            Paging                              13-18
4            structure of the page table         19-29
5            Segmentation                        30-42
6            page replacement                    43-51
7            case studies UNIX, Linux, Windows   52
8            REVISION


    Unit-4              OS                   1
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
   Unit-4             OS                   2
  swapped
Schematic View of Swapping




Unit-4      OS          3
Base and Limit Registers
   • A pair of base and limit registers
     define the logical address space




Unit-4          OS                 4
Multistep Processing of a User
                Program




Unit-4        OS             5
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 OS
 Unit-4                            6
Dynamic relocation using a relocation
              register




Unit-4      OS             7
Contiguous Allocation
• Main memory usually into two partitions:
  – Resident operating system, usually held in low memory
    with interrupt vector
  • User processes then held in high memory
    Relocation registers used to protect user processes
    from each other, and from changing operating-system
    code and data
  – Base register contains value of smallest physical
    address
  – Limit register contains range of logical addresses –
    each logical address must be less than the limit register
  – MMU maps logical address dynamically

 Unit-4             OS                       8
Hardware Support for Relocation and Limit Registers




Unit-4          OS                   9
Contiguous Allocation
• 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              OS          OS             OS

          process 5       process 5   process 5   process 5
                                      process 9   process 9

          process 8                               process 10


          process 2       process 2   process 2   process 2

 Unit-4                    OS                     10
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
   – Compaction is possible only if relocation is dynamic, and is
      done at execution time
   – I/O problem
       • Latch job in memory while it is involved in I/O
       • Do I/O only into OS buffers


  Unit-4              OS                         11
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 8,192
  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
   Unit-4              OS                      12
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



                      page number            page offset
                               p                 d
                             m-n                 n
         – For given logical address space 2m and
           page size 2n


Unit-4                         OS                                         13
Paging Hardware




Unit-4     OS          14
Paging Model of Logical and
              Physical Memory




Unit-4          OS             15
Paging Example




         32-byte memory and 4-byte pages
Unit-4         OS                          16
Free Frames




         Before allocation   After allocation
Unit-4               OS                   17
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 (PRLR) 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)
• Some TLBs store address-space identifiers (ASIDs) in
  each TLB entry – uniquely identifies each process to
  provide address-space protection for that process
   Unit-4             OS                     18
Paging Hardware With TLB




Unit-4          OS          19
Shared Pages
• Shared code
  – One copy of read-only (reentrant) code shared
    among processes (i.e., text editors, compilers,
    window systems).
  – Shared code must appear in same location in the
    logical address space of all processes

• Private code and data
  – Each process keeps a separate copy of the code
    and data
  – The pages for the private code and data can appear
    anywhere in the logical address space
  Unit-4           OS                   20
Shared Pages Example




Unit-4        OS          21
Two-Level Page-Table Scheme




Unit-4     OS           22
Two-Level Paging Example
•   A logical address (on 32-bit machine with 1K page size) is divided into:
    – a page number consisting of 22 bits
    – a page offset consisting of 10 bits
•   Since the page table is paged, the page number is further divided into:
    – a 12-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         page offset
                              number p
                             pi       2        d

                               12    10        10




     Unit-4                  OS                             23
Address-Translation Scheme




Unit-4      OS          24
Three-level Paging Scheme




Unit-4      OS           25
Hashed Page Tables
• Common in address spaces > 32 bits
 The virtual page number is hashed into a page table
    – This page table contains a chain of elements hashing to the same
       location
  Virtual page numbers are compared in this chain searching for a
   match
    – If a match is found, the corresponding physical frame is extracted




   Unit-4                OS                          26
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




    Unit-4                  OS                            27
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
  Unit-4  arrays OS                           28
Segmentation Architecture
• Logical address consists of a two tuple:
             <segment-number, offset>,
• Segment table – maps two-dimensional physical
  addresses; each table entry has:
   – base – contains the starting physical address
       where the segments reside in memory
   – limit – specifies the length of the segment
• Segment-table base register (STBR) points to
  the segment table’s location in memory
• Segment-table length register (STLR) indicates
  number of segments used by a program;
 Unit-4        segment number s is legal29 s < STLR
                   OS                      if
Segmentation Hardware




Unit-4        OS          30
Logical to Physical Address Translation in Pentium




Unit-4          OS                  31
Pentium Paging Architecture




Unit-4      OS           32
Three-level Paging in Linux




Unit-4           OS           33
Demand Paging
• Bring a page into memory only when it is needed
   – Less I/O needed
   – Less memory needed
   – Faster response
   – More users

• Page is needed ⇒ reference to it
   – invalid reference ⇒ abort
   – not-in-memory ⇒ bring to memory
• Lazy swapper – never swaps a page into memory unless page
  will be needed
   – Swapper that deals with pages is a pager

   Unit-4             OS                      34
Page Fault
• If there is a reference to a page, first reference to that
   page will trap to operating system:
          page fault
1. Operating system looks at another table to decide:
    – Invalid reference ⇒ abort
    – Just not in memory
2. Get empty frame
3. Swap page into frame
4. Reset tables
5. Set validation bit = v
6. Restart the instruction that caused the page fault

   Unit-4             OS                      35
Steps in Handling a Page Fault




Unit-4    OS            36
Performance of Demand Paging
• Page Fault Rate 0 ≤ p ≤ 1.0
  – if p = 0 no page faults
  – if p = 1, every reference is a fault

• Effective Access Time (EAT)
             EAT = (1 – p) x memory access
                + p (page fault overhead
                       + swap page out
                       + swap page in
                       + restart overhead
  Unit-4            OS                     37
Copy-on-Write
• Copy-on-Write (COW) allows both parent and
  child processes to initially share the same pages
  in memory

  If either process modifies a shared page, only
  then is the page copied

• COW allows more efficient process creation as
  only modified pages are copied

• Free pages are allocated from a pool of zeroed-
Unit-4 pages
   out          OS                   38
Before Process 1 Modifies Page
              C




Unit-4   OS           39
After Process 1 Modifies Page
                C




Unit-4     OS           40
Page Replacement
• Prevent over-allocation of memory by modifying page-
  fault service routine to include page replacement

• Use modify (dirty) bit to reduce overhead of page
  transfers – only modified pages are written to disk

• Page replacement completes separation between
  logical memory and physical memory – large virtual
  memory can be provided on a smaller physical
  memory


  Unit-4           OS                    41
Need For Page Replacement




Unit-4          OS           42
Page Replacement




Unit-4      OS         43
Graph of Page Faults Versus The
               Number of Frames




Unit-4            OS             44
FIFO Page Replacement




           FIFO Illustrating Belady’s Anomaly




Unit-4          OS                     45
Optimal Page Replacement




              LRU Page Replacement




Unit-4         OS                    46
Use Of A Stack to Record The Most Recent
            Page References




Unit-4       OS               47
Second-Chance (clock) Page-Replacement
               Algorithm




Unit-4       OS              48
Counting Algorithms
• Keep a counter of the number of references
  that have been made to each page
  LFU Algorithm: replaces page with
  smallest count
  MFU Algorithm: based on the argument that
  the page with the smallest count was
  probably just brought in and has yet to be
  used


 Unit-4        OS               49
Windows XP
• Uses demand paging with clustering. Clustering brings
  in pages surrounding the faulting page
• Processes are assigned working set minimum and
  working set maximum
• Working set minimum is the minimum number of pages
  the process is guaranteed to have in memory
• A process may be assigned as many pages up to its
  working set maximum
• When the amount of free memory in the system falls
  below a threshold, automatic working set trimming is
  performed to restore the amount of free memory
• Working set trimming removes pages from processes
  that have pages in excess of their working set minimum
  Unit-4            OS                     50
Solaris
• Maintains a list of free pages to assign faulting processes
• Lotsfree – threshold parameter (amount of free memory) to
  begin paging
• Desfree – threshold parameter to increasing paging
• Minfree – threshold parameter to being swapping
• Paging is performed by pageout process
• Pageout scans pages using modified clock algorithm
• Scanrate is the rate at which pages are scanned. This
  ranges from slowscan to fastscan
• Pageout is called more frequently depending upon the
  amount of free memory available



   Unit-4             OS                        51
Solaris 2 Page Scanner




Unit-4        OS           52

More Related Content

What's hot

Deadlock
DeadlockDeadlock
Deadlock
Rajandeep Gill
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
Piyush Rochwani
 
Demand paging
Demand pagingDemand paging
Demand paging
SwaroopSorte
 
operating system structure
operating system structureoperating system structure
operating system structure
Waseem Ud Din Farooqui
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page table
duvvuru madhuri
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
Dhaval Sakhiya
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
Wayne Jones Jnr
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
Mukesh Chinta
 
Swapping | Computer Science
Swapping | Computer ScienceSwapping | Computer Science
Swapping | Computer Science
Transweb Global Inc
 
Kernels and its types
Kernels and its typesKernels and its types
Kernels and its types
ARAVIND18MCS1004
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memory
Mazin Alwaaly
 
Memory management
Memory managementMemory management
Memory management
Vishal Singh
 
Memory virtualization
Memory virtualizationMemory virtualization
Memory virtualization
Piyush Rochwani
 
Process management in os
Process management in osProcess management in os
Process management in os
Miong Lazaro
 
Mainframe systems
Mainframe systemsMainframe systems
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
Muhammad SiRaj Munir
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
Anuj Modi
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentation
hamza haseeb
 
Memory management
Memory managementMemory management
Memory management
Rajni Sirohi
 
Thread
ThreadThread
Thread
Mohd Arif
 

What's hot (20)

Deadlock
DeadlockDeadlock
Deadlock
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Demand paging
Demand pagingDemand paging
Demand paging
 
operating system structure
operating system structureoperating system structure
operating system structure
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page table
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Swapping | Computer Science
Swapping | Computer ScienceSwapping | Computer Science
Swapping | Computer Science
 
Kernels and its types
Kernels and its typesKernels and its types
Kernels and its types
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memory
 
Memory management
Memory managementMemory management
Memory management
 
Memory virtualization
Memory virtualizationMemory virtualization
Memory virtualization
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Mainframe systems
Mainframe systemsMainframe systems
Mainframe systems
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentation
 
Memory management
Memory managementMemory management
Memory management
 
Thread
ThreadThread
Thread
 

Viewers also liked

Virtual Memory and Paging
Virtual Memory and PagingVirtual Memory and Paging
Virtual Memory and Paging
Emery Berger
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Paging
PagingPaging
Paging
guest53a712
 
I/O Buffering
I/O BufferingI/O Buffering
I/O Buffering
Nadhrah Nini
 
04 Cache Memory
04  Cache  Memory04  Cache  Memory
04 Cache Memory
Jeanie Delos Arcos
 
Secondary storage management in os
Secondary storage management in osSecondary storage management in os
Secondary storage management in os
Sumant Diwakar
 
Linked allocation 48
Linked  allocation 48Linked  allocation 48
Linked allocation 48
myrajendra
 
Operation System
Operation SystemOperation System
Operation System
ANANTHI1997
 
Index allocation 48 1
Index allocation 48 1Index allocation 48 1
Index allocation 48 1
myrajendra
 
File System and File allocation tables
File System and File allocation tablesFile System and File allocation tables
File System and File allocation tables
shashikant pabari
 
ITFT_File system interface in Operating System
ITFT_File system interface in Operating SystemITFT_File system interface in Operating System
ITFT_File system interface in Operating System
Sneh Prabha
 
Operating System-Memory Management
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory Management
Akmal Cikmat
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
Dr. Loganathan R
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
Shashank Shetty
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
aaina_katyal
 
Memory management
Memory managementMemory management
Memory management
Muhammad Fayyaz
 

Viewers also liked (16)

Virtual Memory and Paging
Virtual Memory and PagingVirtual Memory and Paging
Virtual Memory and Paging
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
Paging
PagingPaging
Paging
 
I/O Buffering
I/O BufferingI/O Buffering
I/O Buffering
 
04 Cache Memory
04  Cache  Memory04  Cache  Memory
04 Cache Memory
 
Secondary storage management in os
Secondary storage management in osSecondary storage management in os
Secondary storage management in os
 
Linked allocation 48
Linked  allocation 48Linked  allocation 48
Linked allocation 48
 
Operation System
Operation SystemOperation System
Operation System
 
Index allocation 48 1
Index allocation 48 1Index allocation 48 1
Index allocation 48 1
 
File System and File allocation tables
File System and File allocation tablesFile System and File allocation tables
File System and File allocation tables
 
ITFT_File system interface in Operating System
ITFT_File system interface in Operating SystemITFT_File system interface in Operating System
ITFT_File system interface in Operating System
 
Operating System-Memory Management
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory Management
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Memory management
Memory managementMemory management
Memory management
 

Similar to Os Swapping, Paging, Segmentation and Virtual Memory

Os4
Os4Os4
Os4
Os4Os4
Memory management
Memory managementMemory management
Memory management
Mohammad Sadiq
 
CSE2010- Module 4 V1.pptx
CSE2010- Module 4 V1.pptxCSE2010- Module 4 V1.pptx
CSE2010- Module 4 V1.pptx
MadhuraK13
 
Memory Management Strategies - III.pdf
Memory Management Strategies - III.pdfMemory Management Strategies - III.pdf
Memory Management Strategies - III.pdf
Harika Pudugosula
 
Ch8 main memory
Ch8   main memoryCh8   main memory
Ch8 main memory
Welly Dian Astika
 
Memory Management techniques -ch8_1.pptx
Memory Management techniques -ch8_1.pptxMemory Management techniques -ch8_1.pptx
Memory Management techniques -ch8_1.pptx
KongaMadhukar
 
kerch04.ppt
kerch04.pptkerch04.ppt
kerch04.ppt
KalimuthuVelappan
 
PAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docxPAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docx
ImranBhatti58
 
Operating systems- Main Memory Management
Operating systems- Main Memory ManagementOperating systems- Main Memory Management
Operating systems- Main Memory Management
Chandrakant Divate
 
Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
Wayne Jones Jnr
 
08 operating system support
08 operating system support08 operating system support
08 operating system support
Sher Shah Merkhel
 
Main Memory
Main MemoryMain Memory
Main Memory
Usama ahmad
 
Memory Management.pdf
Memory Management.pdfMemory Management.pdf
Memory Management.pdf
SujanTimalsina5
 
Ch9 OS
Ch9 OSCh9 OS
Ch9 OS
C.U
 
OS_Ch9
OS_Ch9OS_Ch9
OSCh9
OSCh9OSCh9
Unit-4 swapping.pptx
Unit-4 swapping.pptxUnit-4 swapping.pptx
Unit-4 swapping.pptx
ItechAnand1
 
ch8 Memory Management OS.pptx
ch8 Memory Management OS.pptxch8 Memory Management OS.pptx
ch8 Memory Management OS.pptx
Indhu Periys
 
Unit 5Memory management.pptx
Unit 5Memory management.pptxUnit 5Memory management.pptx
Unit 5Memory management.pptx
SourabhRaj29
 

Similar to Os Swapping, Paging, Segmentation and Virtual Memory (20)

Os4
Os4Os4
Os4
 
Os4
Os4Os4
Os4
 
Memory management
Memory managementMemory management
Memory management
 
CSE2010- Module 4 V1.pptx
CSE2010- Module 4 V1.pptxCSE2010- Module 4 V1.pptx
CSE2010- Module 4 V1.pptx
 
Memory Management Strategies - III.pdf
Memory Management Strategies - III.pdfMemory Management Strategies - III.pdf
Memory Management Strategies - III.pdf
 
Ch8 main memory
Ch8   main memoryCh8   main memory
Ch8 main memory
 
Memory Management techniques -ch8_1.pptx
Memory Management techniques -ch8_1.pptxMemory Management techniques -ch8_1.pptx
Memory Management techniques -ch8_1.pptx
 
kerch04.ppt
kerch04.pptkerch04.ppt
kerch04.ppt
 
PAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docxPAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docx
 
Operating systems- Main Memory Management
Operating systems- Main Memory ManagementOperating systems- Main Memory Management
Operating systems- Main Memory Management
 
Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
 
08 operating system support
08 operating system support08 operating system support
08 operating system support
 
Main Memory
Main MemoryMain Memory
Main Memory
 
Memory Management.pdf
Memory Management.pdfMemory Management.pdf
Memory Management.pdf
 
Ch9 OS
Ch9 OSCh9 OS
Ch9 OS
 
OS_Ch9
OS_Ch9OS_Ch9
OS_Ch9
 
OSCh9
OSCh9OSCh9
OSCh9
 
Unit-4 swapping.pptx
Unit-4 swapping.pptxUnit-4 swapping.pptx
Unit-4 swapping.pptx
 
ch8 Memory Management OS.pptx
ch8 Memory Management OS.pptxch8 Memory Management OS.pptx
ch8 Memory Management OS.pptx
 
Unit 5Memory management.pptx
Unit 5Memory management.pptxUnit 5Memory management.pptx
Unit 5Memory management.pptx
 

Recently uploaded

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 

Recently uploaded (20)

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 

Os Swapping, Paging, Segmentation and Virtual Memory

  • 1. Lecture Plan UNIT-IV Lecture Topic Slide No. No. 1 Swapping 2-7 2 contiguous memory allocation 8-12 3 Paging 13-18 4 structure of the page table 19-29 5 Segmentation 30-42 6 page replacement 43-51 7 case studies UNIX, Linux, Windows 52 8 REVISION Unit-4 OS 1
  • 2. 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 Unit-4 OS 2 swapped
  • 3. Schematic View of Swapping Unit-4 OS 3
  • 4. Base and Limit Registers • A pair of base and limit registers define the logical address space Unit-4 OS 4
  • 5. Multistep Processing of a User Program Unit-4 OS 5
  • 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 OS Unit-4 6
  • 7. Dynamic relocation using a relocation register Unit-4 OS 7
  • 8. Contiguous Allocation • Main memory usually into two partitions: – Resident operating system, usually held in low memory with interrupt vector • User processes then held in high memory Relocation registers used to protect user processes from each other, and from changing operating-system code and data – Base register contains value of smallest physical address – Limit register contains range of logical addresses – each logical address must be less than the limit register – MMU maps logical address dynamically Unit-4 OS 8
  • 9. Hardware Support for Relocation and Limit Registers Unit-4 OS 9
  • 10. Contiguous Allocation • 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 OS OS OS process 5 process 5 process 5 process 5 process 9 process 9 process 8 process 10 process 2 process 2 process 2 process 2 Unit-4 OS 10
  • 11. 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 – Compaction is possible only if relocation is dynamic, and is done at execution time – I/O problem • Latch job in memory while it is involved in I/O • Do I/O only into OS buffers Unit-4 OS 11
  • 12. 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 8,192 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 Unit-4 OS 12
  • 13. 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 page number page offset p d m-n n – For given logical address space 2m and page size 2n Unit-4 OS 13
  • 15. Paging Model of Logical and Physical Memory Unit-4 OS 15
  • 16. Paging Example 32-byte memory and 4-byte pages Unit-4 OS 16
  • 17. Free Frames Before allocation After allocation Unit-4 OS 17
  • 18. 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 (PRLR) 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) • Some TLBs store address-space identifiers (ASIDs) in each TLB entry – uniquely identifies each process to provide address-space protection for that process Unit-4 OS 18
  • 19. Paging Hardware With TLB Unit-4 OS 19
  • 20. Shared Pages • Shared code – One copy of read-only (reentrant) code shared among processes (i.e., text editors, compilers, window systems). – Shared code must appear in same location in the logical address space of all processes • Private code and data – Each process keeps a separate copy of the code and data – The pages for the private code and data can appear anywhere in the logical address space Unit-4 OS 20
  • 23. Two-Level Paging Example • A logical address (on 32-bit machine with 1K page size) is divided into: – a page number consisting of 22 bits – a page offset consisting of 10 bits • Since the page table is paged, the page number is further divided into: – a 12-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 page offset number p pi 2 d 12 10 10 Unit-4 OS 23
  • 26. Hashed Page Tables • Common in address spaces > 32 bits The virtual page number is hashed into a page table – This page table contains a chain of elements hashing to the same location Virtual page numbers are compared in this chain searching for a match – If a match is found, the corresponding physical frame is extracted Unit-4 OS 26
  • 27. 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 Unit-4 OS 27
  • 28. 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 Unit-4 arrays OS 28
  • 29. Segmentation Architecture • Logical address consists of a two tuple: <segment-number, offset>, • Segment table – maps two-dimensional physical addresses; each table entry has: – base – contains the starting physical address where the segments reside in memory – limit – specifies the length of the segment • Segment-table base register (STBR) points to the segment table’s location in memory • Segment-table length register (STLR) indicates number of segments used by a program; Unit-4 segment number s is legal29 s < STLR OS if
  • 31. Logical to Physical Address Translation in Pentium Unit-4 OS 31
  • 33. Three-level Paging in Linux Unit-4 OS 33
  • 34. Demand Paging • Bring a page into memory only when it is needed – Less I/O needed – Less memory needed – Faster response – More users • Page is needed ⇒ reference to it – invalid reference ⇒ abort – not-in-memory ⇒ bring to memory • Lazy swapper – never swaps a page into memory unless page will be needed – Swapper that deals with pages is a pager Unit-4 OS 34
  • 35. Page Fault • If there is a reference to a page, first reference to that page will trap to operating system: page fault 1. Operating system looks at another table to decide: – Invalid reference ⇒ abort – Just not in memory 2. Get empty frame 3. Swap page into frame 4. Reset tables 5. Set validation bit = v 6. Restart the instruction that caused the page fault Unit-4 OS 35
  • 36. Steps in Handling a Page Fault Unit-4 OS 36
  • 37. Performance of Demand Paging • Page Fault Rate 0 ≤ p ≤ 1.0 – if p = 0 no page faults – if p = 1, every reference is a fault • Effective Access Time (EAT) EAT = (1 – p) x memory access + p (page fault overhead + swap page out + swap page in + restart overhead Unit-4 OS 37
  • 38. Copy-on-Write • Copy-on-Write (COW) allows both parent and child processes to initially share the same pages in memory If either process modifies a shared page, only then is the page copied • COW allows more efficient process creation as only modified pages are copied • Free pages are allocated from a pool of zeroed- Unit-4 pages out OS 38
  • 39. Before Process 1 Modifies Page C Unit-4 OS 39
  • 40. After Process 1 Modifies Page C Unit-4 OS 40
  • 41. Page Replacement • Prevent over-allocation of memory by modifying page- fault service routine to include page replacement • Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk • Page replacement completes separation between logical memory and physical memory – large virtual memory can be provided on a smaller physical memory Unit-4 OS 41
  • 42. Need For Page Replacement Unit-4 OS 42
  • 44. Graph of Page Faults Versus The Number of Frames Unit-4 OS 44
  • 45. FIFO Page Replacement FIFO Illustrating Belady’s Anomaly Unit-4 OS 45
  • 46. Optimal Page Replacement LRU Page Replacement Unit-4 OS 46
  • 47. Use Of A Stack to Record The Most Recent Page References Unit-4 OS 47
  • 48. Second-Chance (clock) Page-Replacement Algorithm Unit-4 OS 48
  • 49. Counting Algorithms • Keep a counter of the number of references that have been made to each page LFU Algorithm: replaces page with smallest count MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used Unit-4 OS 49
  • 50. Windows XP • Uses demand paging with clustering. Clustering brings in pages surrounding the faulting page • Processes are assigned working set minimum and working set maximum • Working set minimum is the minimum number of pages the process is guaranteed to have in memory • A process may be assigned as many pages up to its working set maximum • When the amount of free memory in the system falls below a threshold, automatic working set trimming is performed to restore the amount of free memory • Working set trimming removes pages from processes that have pages in excess of their working set minimum Unit-4 OS 50
  • 51. Solaris • Maintains a list of free pages to assign faulting processes • Lotsfree – threshold parameter (amount of free memory) to begin paging • Desfree – threshold parameter to increasing paging • Minfree – threshold parameter to being swapping • Paging is performed by pageout process • Pageout scans pages using modified clock algorithm • Scanrate is the rate at which pages are scanned. This ranges from slowscan to fastscan • Pageout is called more frequently depending upon the amount of free memory available Unit-4 OS 51
  • 52. Solaris 2 Page Scanner Unit-4 OS 52