SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
VM and I/O Topics in Linux
 Page Replacement, Swap and I/O


 Jiannan Ouyang
 Ph.D. Student
 Computer Science Department
 University of Pittsburgh
 05/05/2011
Outline

        • Overview of Linux Memory Management

        • Page Reclamation

        • Swap & I/O




Jiannan Ouyang, CS PhD@PITT                     2
Describing Physical Memory
                              Node: NUMA memory region
                              Zone: memory type
                              Struct Page: page frame




Jiannan Ouyang, CS PhD@PITT                              3
Physical Page Allocation




          Binary Buddy Allocator:
          • If a block of the desired size is not available, a large block is broken up in half, and the
             two blocks are buddies to each other. One half is used for the allocation, and the other is
             free. The blocks are continuously halved as necessary until a block of the desired size is
             available.
          • When a block is later freed, the buddy is examined, and the two are coalesced if it is free.

Jiannan Ouyang, CS PhD@PITT                                                                                4
Page Table Management

        • Three Level Mapping




Jiannan Ouyang, CS PhD@PITT     5
Kernel Memory Mapping
                        display memory
                        device memory     896-MB
                                                    0xC0000000


                                                    4-GB

0x3FFFFFFF

          1-GB
                               896-MB

0x00000000                                           0x00000000
         Physical memory
 Jiannan Ouyang, CS PhD@PITT
                                         Virtual Memory     6
User Memory Mapping
                                                   kernel
                                                   space
                                                    stack
                              stack
                                      mappings
                              text
                              data                user space      3-GB

                    physical memory
                                                    data
                                                    text

Jiannan Ouyang, CS PhD@PITT                      virtual memory          7
User Memory Mapping
            virtual memory                      virtual memory
                              physical memory
                     kernel                        kernel
                     space                         space
                                  stack
                      stack                         stack
                                  data

                                  data
                 user space       stack           user space
                       data       text              data
                       text                         text

Jiannan Ouyang, CS PhD@PITT                                      8
Outline

        • Overview of Linux Memory Management

        • Page Reclamation

        • Swap & I/O




Jiannan Ouyang, CS PhD@PITT                     9
Memory Customers
                                             Kernel Code & data

                              Request        Slab Cache
       Buddy                                 Icache & dcache
       System
                              Reclaim        User Code & Data


                                              Page Cache

       • All memory except “User Code & data” are used by the kernel
       • “User Code & Data” are managed in user space, i.e. malloc/free,
         kernel can only swap out user pages
Jiannan Ouyang, CS PhD@PITT                                                10
Slab Cache




            • Cache for commonly used objects kept in an initialized state
              available for use by the kernel.
            • Save time of allocating, initializing and freeing the same object.
Jiannan Ouyang, CS PhD@PITT                                                        11
Disk related caches

        • Dcache (metadata): dentry objects
          representing filesystem pathnames.
        • Icache (metadata): inode objects
          representing disk inodes.
        • Page Cache (data): data pages from disk,
          main disk cache used


Jiannan Ouyang, CS PhD@PITT                          12
Memory Customers Review
                                              Kernel Code & data

                              Request         Slab Cache
       Buddy                                  Icache & dcache
       System
                              Reclaim         User Code & Data


                                               Page Cache


       We’ll see when will the kernel start reclaim pages, which pages to
       reclaim, and the replacement policy.

Jiannan Ouyang, CS PhD@PITT                                                 13
Reclamation: When?

        Zone Watermarks
        • Pages Low: kswapd is woken up by the buddy
          allocator to start freeing pages. The value is twice the
          value of pages min by default.
        • Pages Min: the allocator will do the kswapd work in
          a synchronous fashion, sometimes referred to as the
          direct-reclaim path.
        • Pages High: kswapd will go back to sleep. The
          default for pages high is three times the value of pages
          min.


Jiannan Ouyang, CS PhD@PITT                                      14
Jiannan Ouyang, CS PhD@PITT   15
Reclamation: Which?




Jiannan Ouyang, CS PhD@PITT   16
Reclamation: Which? (Con.)

        • Mapped & Anonymous Pages
                – Mapped: backed up by a file
                – Anonymous: anonymous memory region of a
                  process

        • Shared & Non-shared Pages
                – Unmapping from all page table entries at once:
                  reverse mapping, important improvement in Linux
                  2.6 Kernel
Jiannan Ouyang, CS PhD@PITT                                     17
Reclamation: Which? (Con.)




       shrink_caches until given target number of pages is met,
       1. slab cache (Kmem_cache_reap)
       2. User pages & page cache (refill & shrink_cache)
       3. dcache and icache


Jiannan Ouyang, CS PhD@PITT                                       18
Replacement Policy
                              (active, ref) = {11,10, 01, 00}
                               access
                                                                Ref=1, clear
 active                          active=1

                                      access                    Ref=0



 inactive                         active=0
                                                                          reclaim

Jiannan Ouyang, CS PhD@PITT                                                         19
Moving pages across the list




           mark_page_accessed( ):
                      on each access increase the (active, ref) counter;
                      if active=1 move inactive->active;
           Refill_inactive_zone():
                      if (ref=1) {ref=0; move to head of active list;}
                      else {move active -> inactive;}
Jiannan Ouyang, CS PhD@PITT                                                20
Outline

        • Overview of Linux Memory Management

        • Page Reclamation

        • Swap & I/O




Jiannan Ouyang, CS PhD@PITT                 21
Swap

        • Able to reclaim all the page frames
          obtained by a process, and not only those
          have an image on disk
                – anonymous pages (User stack or heap)
                – Dirty pages that belong to a private memory
                  mapping of a process
                – IPC shared pages

Jiannan Ouyang, CS PhD@PITT                                     22
Swap (Con.)
        • Set up “swap areas” on disk
        • allocating and freeing “page slots” in swap
          areas
        • Provide functions both to “swap out” pages
          from RAM into a swap area and to “swap in”
          pages from a swap area into RAM.
        • Mark Page Table entries to keep track of the
          positions of data in the swap areas.

Jiannan Ouyang, CS PhD@PITT                              23
Example
         While(1){
           p = malloc(N);
           memset(p, 0, N);
         //demand paging
         }


                       total   used      free    shared   buffers   cached
         Mem:          2013    1811       201         0       157      872
         -/+ buffers/cache:     782      1231
         Swap:          397       0       397




         $free -m
                total       used      free      shared    buffers    cached
         Mem:    2013       1956(+)   56(-)           0      4(-)     109(-)
         -/+ buffers/cache: 1842(+)   170(-)
         Swap:    397          8         389


Jiannan Ouyang, CS PhD@PITT                                                    24
Linux I/O Architecture
                              • Default file I/O API,
                                fwrite(), are buffered

                              • File System:
                                (dir, name, offset) -> LBA

                              • Device File: not normal
                                file



                              • How to do bypassing?
Jiannan Ouyang, CS PhD@PITT                               25
I/O Bypassing

        • Disk Cache
                – O_DIRECT

        • File System
                – Device file

        • I/O Scheduler
                – To be solved

Jiannan Ouyang, CS PhD@PITT      26
Thanks
                               Q&A




Jiannan Ouyang, CS PhD@PITT            27
Reference

        • Understanding the Linux Kernel, 3rd
        • Understanding the Linux Virtual
          Memory Manager




Jiannan Ouyang, CS PhD@PITT                     28
BACKUP SLICES


Jiannan Ouyang, CS PhD@PITT   29
Page Table Management

        • Three Level Mapping




Jiannan Ouyang, CS PhD@PITT     30
Page Table Management (Con.)

                              PGD Address



     Linear Address                         Physical Address
                                 MMU




Jiannan Ouyang, CS PhD@PITT                                31

Más contenido relacionado

La actualidad más candente

Memory management in Linux kernel
Memory management in Linux kernelMemory management in Linux kernel
Memory management in Linux kernelVadim Nikitin
 
Os solaris memory management
Os  solaris memory managementOs  solaris memory management
Os solaris memory managementTech_MX
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory ManagementRajan Kandel
 
Linux memorymanagement
Linux memorymanagementLinux memorymanagement
Linux memorymanagementpradeepelinux
 
31 address binding, dynamic loading
31 address binding, dynamic loading31 address binding, dynamic loading
31 address binding, dynamic loadingmyrajendra
 
Windows memory manager internals
Windows memory manager internalsWindows memory manager internals
Windows memory manager internalsSisimon Soman
 
Swap-space Management
Swap-space ManagementSwap-space Management
Swap-space ManagementAgnas Jasmine
 
Unix Memory Management - Operating Systems
Unix Memory Management - Operating SystemsUnix Memory Management - Operating Systems
Unix Memory Management - Operating SystemsDrishti Bhalla
 
Designing Information Structures For Performance And Reliability
Designing Information Structures For Performance And ReliabilityDesigning Information Structures For Performance And Reliability
Designing Information Structures For Performance And Reliabilitybryanrandol
 
Memory Management in Windows 7
Memory Management in Windows 7Memory Management in Windows 7
Memory Management in Windows 7Naveed Qadri
 
Operation System
Operation SystemOperation System
Operation SystemANANTHI1997
 
34 single partition allocation
34 single partition allocation34 single partition allocation
34 single partition allocationmyrajendra
 
Windows memory management
Windows memory managementWindows memory management
Windows memory managementTech_MX
 

La actualidad más candente (20)

Memory management in Linux kernel
Memory management in Linux kernelMemory management in Linux kernel
Memory management in Linux kernel
 
Os solaris memory management
Os  solaris memory managementOs  solaris memory management
Os solaris memory management
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Linux memorymanagement
Linux memorymanagementLinux memorymanagement
Linux memorymanagement
 
31 address binding, dynamic loading
31 address binding, dynamic loading31 address binding, dynamic loading
31 address binding, dynamic loading
 
SQL 2005 Memory Module
SQL 2005 Memory ModuleSQL 2005 Memory Module
SQL 2005 Memory Module
 
Windows memory manager internals
Windows memory manager internalsWindows memory manager internals
Windows memory manager internals
 
Swap-space Management
Swap-space ManagementSwap-space Management
Swap-space Management
 
Unix Memory Management - Operating Systems
Unix Memory Management - Operating SystemsUnix Memory Management - Operating Systems
Unix Memory Management - Operating Systems
 
Memory comp
Memory compMemory comp
Memory comp
 
Cache memory
Cache memoryCache memory
Cache memory
 
Linux Memory
Linux MemoryLinux Memory
Linux Memory
 
Designing Information Structures For Performance And Reliability
Designing Information Structures For Performance And ReliabilityDesigning Information Structures For Performance And Reliability
Designing Information Structures For Performance And Reliability
 
Memory managment
Memory managmentMemory managment
Memory managment
 
Memory management
Memory managementMemory management
Memory management
 
Memory Management in Windows 7
Memory Management in Windows 7Memory Management in Windows 7
Memory Management in Windows 7
 
Cache memory
Cache memoryCache memory
Cache memory
 
Operation System
Operation SystemOperation System
Operation System
 
34 single partition allocation
34 single partition allocation34 single partition allocation
34 single partition allocation
 
Windows memory management
Windows memory managementWindows memory management
Windows memory management
 

Destacado

Presentation on simple os
Presentation on simple osPresentation on simple os
Presentation on simple osBijay Rai
 
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecksKernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecksAnne Nicolas
 
An Operating System for Multicore and Clouds: Mechanisms and Implementation
An Operating System for Multicore and Clouds: Mechanisms and ImplementationAn Operating System for Multicore and Clouds: Mechanisms and Implementation
An Operating System for Multicore and Clouds: Mechanisms and Implementationcucufrog
 
Kernel I/O Subsystem
Kernel I/O SubsystemKernel I/O Subsystem
Kernel I/O SubsystemSushil Ale
 
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...Anne Nicolas
 
Understand and optimize Linux I/O
Understand and optimize Linux I/OUnderstand and optimize Linux I/O
Understand and optimize Linux I/OAndrea Righi
 
High Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux KernelHigh Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux KernelKernel TLV
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memorysgpraju
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating SystemRaj Mohan
 

Destacado (14)

Presentation on simple os
Presentation on simple osPresentation on simple os
Presentation on simple os
 
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecksKernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
 
fundamentals of linux
fundamentals of linuxfundamentals of linux
fundamentals of linux
 
An Operating System for Multicore and Clouds: Mechanisms and Implementation
An Operating System for Multicore and Clouds: Mechanisms and ImplementationAn Operating System for Multicore and Clouds: Mechanisms and Implementation
An Operating System for Multicore and Clouds: Mechanisms and Implementation
 
Kernel I/O Subsystem
Kernel I/O SubsystemKernel I/O Subsystem
Kernel I/O Subsystem
 
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
 
Understand and optimize Linux I/O
Understand and optimize Linux I/OUnderstand and optimize Linux I/O
Understand and optimize Linux I/O
 
High Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux KernelHigh Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux Kernel
 
Memory management in linux
Memory management in linuxMemory management in linux
Memory management in linux
 
Paging
PagingPaging
Paging
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
 

Similar a VM and IO Topics in Linux

9 virtual memory management
9 virtual memory management9 virtual memory management
9 virtual memory managementDr. Loganathan R
 
ASPLOS2011 workshop RESoLVE "Effect of Disk Prefetching of Guest OS "
ASPLOS2011 workshop RESoLVE "Effect of Disk Prefetching of Guest OS "ASPLOS2011 workshop RESoLVE "Effect of Disk Prefetching of Guest OS "
ASPLOS2011 workshop RESoLVE "Effect of Disk Prefetching of Guest OS "Kuniyasu Suzaki
 
Flash Usage Models for the Oracle Database
Flash Usage Models for the Oracle DatabaseFlash Usage Models for the Oracle Database
Flash Usage Models for the Oracle DatabaseIMEX Research
 
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...Alluxio, Inc.
 
My sql with enterprise storage
My sql with enterprise storageMy sql with enterprise storage
My sql with enterprise storageCaroline_Rose
 
36 fragmentaio nnd pageconcepts
36 fragmentaio nnd pageconcepts36 fragmentaio nnd pageconcepts
36 fragmentaio nnd pageconceptsmyrajendra
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsTony Nguyen
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsYoung Alista
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsHarry Potter
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsJames Wong
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsFraboni Ec
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsHoang Nguyen
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsLuis Goldster
 
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...Alluxio, Inc.
 
M2 221-ssd fs-rl_2.2.1
M2 221-ssd fs-rl_2.2.1M2 221-ssd fs-rl_2.2.1
M2 221-ssd fs-rl_2.2.1MrudulaJoshi10
 
Challenges in Maintaining a High Performance Search Engine Written in Java
Challenges in Maintaining a High Performance Search Engine Written in JavaChallenges in Maintaining a High Performance Search Engine Written in Java
Challenges in Maintaining a High Performance Search Engine Written in Javalucenerevolution
 
Some key value stores using log-structure
Some key value stores using log-structureSome key value stores using log-structure
Some key value stores using log-structureZhichao Liang
 

Similar a VM and IO Topics in Linux (20)

9 virtual memory management
9 virtual memory management9 virtual memory management
9 virtual memory management
 
ASPLOS2011 workshop RESoLVE "Effect of Disk Prefetching of Guest OS "
ASPLOS2011 workshop RESoLVE "Effect of Disk Prefetching of Guest OS "ASPLOS2011 workshop RESoLVE "Effect of Disk Prefetching of Guest OS "
ASPLOS2011 workshop RESoLVE "Effect of Disk Prefetching of Guest OS "
 
Flash Usage Models for the Oracle Database
Flash Usage Models for the Oracle DatabaseFlash Usage Models for the Oracle Database
Flash Usage Models for the Oracle Database
 
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
 
My sql with enterprise storage
My sql with enterprise storageMy sql with enterprise storage
My sql with enterprise storage
 
36 fragmentaio nnd pageconcepts
36 fragmentaio nnd pageconcepts36 fragmentaio nnd pageconcepts
36 fragmentaio nnd pageconcepts
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
 
Extlect03
Extlect03Extlect03
Extlect03
 
M2 221-ssd fs-rl_2.2.1
M2 221-ssd fs-rl_2.2.1M2 221-ssd fs-rl_2.2.1
M2 221-ssd fs-rl_2.2.1
 
Challenges in Maintaining a High Performance Search Engine Written in Java
Challenges in Maintaining a High Performance Search Engine Written in JavaChallenges in Maintaining a High Performance Search Engine Written in Java
Challenges in Maintaining a High Performance Search Engine Written in Java
 
Presentation
PresentationPresentation
Presentation
 
Presentation
PresentationPresentation
Presentation
 
Some key value stores using log-structure
Some key value stores using log-structureSome key value stores using log-structure
Some key value stores using log-structure
 

Último

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

VM and IO Topics in Linux

  • 1. VM and I/O Topics in Linux Page Replacement, Swap and I/O Jiannan Ouyang Ph.D. Student Computer Science Department University of Pittsburgh 05/05/2011
  • 2. Outline • Overview of Linux Memory Management • Page Reclamation • Swap & I/O Jiannan Ouyang, CS PhD@PITT 2
  • 3. Describing Physical Memory Node: NUMA memory region Zone: memory type Struct Page: page frame Jiannan Ouyang, CS PhD@PITT 3
  • 4. Physical Page Allocation Binary Buddy Allocator: • If a block of the desired size is not available, a large block is broken up in half, and the two blocks are buddies to each other. One half is used for the allocation, and the other is free. The blocks are continuously halved as necessary until a block of the desired size is available. • When a block is later freed, the buddy is examined, and the two are coalesced if it is free. Jiannan Ouyang, CS PhD@PITT 4
  • 5. Page Table Management • Three Level Mapping Jiannan Ouyang, CS PhD@PITT 5
  • 6. Kernel Memory Mapping display memory device memory 896-MB 0xC0000000 4-GB 0x3FFFFFFF 1-GB 896-MB 0x00000000 0x00000000 Physical memory Jiannan Ouyang, CS PhD@PITT Virtual Memory 6
  • 7. User Memory Mapping kernel space stack stack mappings text data user space 3-GB physical memory data text Jiannan Ouyang, CS PhD@PITT virtual memory 7
  • 8. User Memory Mapping virtual memory virtual memory physical memory kernel kernel space space stack stack stack data data user space stack user space data text data text text Jiannan Ouyang, CS PhD@PITT 8
  • 9. Outline • Overview of Linux Memory Management • Page Reclamation • Swap & I/O Jiannan Ouyang, CS PhD@PITT 9
  • 10. Memory Customers Kernel Code & data Request Slab Cache Buddy Icache & dcache System Reclaim User Code & Data Page Cache • All memory except “User Code & data” are used by the kernel • “User Code & Data” are managed in user space, i.e. malloc/free, kernel can only swap out user pages Jiannan Ouyang, CS PhD@PITT 10
  • 11. Slab Cache • Cache for commonly used objects kept in an initialized state available for use by the kernel. • Save time of allocating, initializing and freeing the same object. Jiannan Ouyang, CS PhD@PITT 11
  • 12. Disk related caches • Dcache (metadata): dentry objects representing filesystem pathnames. • Icache (metadata): inode objects representing disk inodes. • Page Cache (data): data pages from disk, main disk cache used Jiannan Ouyang, CS PhD@PITT 12
  • 13. Memory Customers Review Kernel Code & data Request Slab Cache Buddy Icache & dcache System Reclaim User Code & Data Page Cache We’ll see when will the kernel start reclaim pages, which pages to reclaim, and the replacement policy. Jiannan Ouyang, CS PhD@PITT 13
  • 14. Reclamation: When? Zone Watermarks • Pages Low: kswapd is woken up by the buddy allocator to start freeing pages. The value is twice the value of pages min by default. • Pages Min: the allocator will do the kswapd work in a synchronous fashion, sometimes referred to as the direct-reclaim path. • Pages High: kswapd will go back to sleep. The default for pages high is three times the value of pages min. Jiannan Ouyang, CS PhD@PITT 14
  • 15. Jiannan Ouyang, CS PhD@PITT 15
  • 17. Reclamation: Which? (Con.) • Mapped & Anonymous Pages – Mapped: backed up by a file – Anonymous: anonymous memory region of a process • Shared & Non-shared Pages – Unmapping from all page table entries at once: reverse mapping, important improvement in Linux 2.6 Kernel Jiannan Ouyang, CS PhD@PITT 17
  • 18. Reclamation: Which? (Con.) shrink_caches until given target number of pages is met, 1. slab cache (Kmem_cache_reap) 2. User pages & page cache (refill & shrink_cache) 3. dcache and icache Jiannan Ouyang, CS PhD@PITT 18
  • 19. Replacement Policy (active, ref) = {11,10, 01, 00} access Ref=1, clear active active=1 access Ref=0 inactive active=0 reclaim Jiannan Ouyang, CS PhD@PITT 19
  • 20. Moving pages across the list mark_page_accessed( ): on each access increase the (active, ref) counter; if active=1 move inactive->active; Refill_inactive_zone(): if (ref=1) {ref=0; move to head of active list;} else {move active -> inactive;} Jiannan Ouyang, CS PhD@PITT 20
  • 21. Outline • Overview of Linux Memory Management • Page Reclamation • Swap & I/O Jiannan Ouyang, CS PhD@PITT 21
  • 22. Swap • Able to reclaim all the page frames obtained by a process, and not only those have an image on disk – anonymous pages (User stack or heap) – Dirty pages that belong to a private memory mapping of a process – IPC shared pages Jiannan Ouyang, CS PhD@PITT 22
  • 23. Swap (Con.) • Set up “swap areas” on disk • allocating and freeing “page slots” in swap areas • Provide functions both to “swap out” pages from RAM into a swap area and to “swap in” pages from a swap area into RAM. • Mark Page Table entries to keep track of the positions of data in the swap areas. Jiannan Ouyang, CS PhD@PITT 23
  • 24. Example While(1){ p = malloc(N); memset(p, 0, N); //demand paging } total used free shared buffers cached Mem: 2013 1811 201 0 157 872 -/+ buffers/cache: 782 1231 Swap: 397 0 397 $free -m total used free shared buffers cached Mem: 2013 1956(+) 56(-) 0 4(-) 109(-) -/+ buffers/cache: 1842(+) 170(-) Swap: 397 8 389 Jiannan Ouyang, CS PhD@PITT 24
  • 25. Linux I/O Architecture • Default file I/O API, fwrite(), are buffered • File System: (dir, name, offset) -> LBA • Device File: not normal file • How to do bypassing? Jiannan Ouyang, CS PhD@PITT 25
  • 26. I/O Bypassing • Disk Cache – O_DIRECT • File System – Device file • I/O Scheduler – To be solved Jiannan Ouyang, CS PhD@PITT 26
  • 27. Thanks Q&A Jiannan Ouyang, CS PhD@PITT 27
  • 28. Reference • Understanding the Linux Kernel, 3rd • Understanding the Linux Virtual Memory Manager Jiannan Ouyang, CS PhD@PITT 28
  • 30. Page Table Management • Three Level Mapping Jiannan Ouyang, CS PhD@PITT 30
  • 31. Page Table Management (Con.) PGD Address Linear Address Physical Address MMU Jiannan Ouyang, CS PhD@PITT 31