win lin memory

Upload: ajaya-kumar

Post on 06-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Win Lin Memory

    1/18

    Memory Management inMemory Management inWindows and LinuxWindows and Linux

    &

  • 8/3/2019 Win Lin Memory

    2/18

    Windows Memory ManagementWindows Memory Management

    Virtual memory manager (VMM)

    Executive component responsible for managing memory

    Lazy allocation

    Avoid allocating memory until necessary

    Prefetching

    Move pages from disk to main memory before they are needed

    Pagefile

    Stores pages that do not fit in main memory Windows XP supports up to 16 pagefiles

  • 8/3/2019 Win Lin Memory

    3/18

    Memory OrganizationMemory Organization

    32-bit virtual address space

    Windows 64-Bit Edition has 64-bit address space.

    4GB virtual address space per process

    User space vs. System space

    Process can access only user space

    VMM stores page tables and other data in system space

    2GB user space, 2GB system space

    4KB pages

  • 8/3/2019 Win Lin Memory

    4/18

    Memory OrganizationMemory Organization

    Two-level hierarchical memory map

    Page directory table

    Page directory entries (PDEs) point to page table

    One page directory table per process

    Location in page directory register

    Page table

    Page table entries (PTEs) point to page frames

    Page frame

    Contains page of data TLB (translation lookaside buffer) accelerates address

    translation

  • 8/3/2019 Win Lin Memory

    5/18

    .

    Virtual address translationVirtual address translation

  • 8/3/2019 Win Lin Memory

    6/18

    Memory AllocationMemory Allocation

  • 8/3/2019 Win Lin Memory

    7/18

    Page frame statesPage frame states

  • 8/3/2019 Win Lin Memory

    8/18

    Page Replacement ProcessPage Replacement Process

  • 8/3/2019 Win Lin Memory

    9/18

    Linux Memory ManagementLinux Memory Management

    Memory manager supports 32- and 64-bit addresses

    Also supports NUMA (nonuniform memory access

    architectures)

    To allow Linux to scale from desktops andworkstations, to servers and supercomputers

  • 8/3/2019 Win Lin Memory

    10/18

    Page Table OrganizationPage Table Organization

  • 8/3/2019 Win Lin Memory

    11/18

    Memory OrganizationMemory Organization

    Linux uses paging exclusively Often implemented using a single page size

    On 32-bit systems, kernel can address 4GB of data

    On 64-bit systems, the kernel supports up to 2 petabytes of data

    Three levels of page tables

    Page global directory

    Page middle directory

    Page tables

    On systems that support only two levels of page tables, pagemiddle directory contains exactly one entry

    Virtual address space organized into virtual memory areas togroup information with same permissions (similar tosegments)

  • 8/3/2019 Win Lin Memory

    12/18

    Linux on the IALinux on the IA--32 architecture32 architecture

    Kernel attempts to reduce overhead due to TLB flushing on

    context switch

    Divides each 4GB address space into a 3GB region for process

    data and instructions and a 1GB address space for kernel dataand instructions

    Most of the kernels address space is directly mapped to main

    memory so that it can access information belonging to any

    process

  • 8/3/2019 Win Lin Memory

    13/18

    Kernel virtual address space mappingKernel virtual address space mapping

  • 8/3/2019 Win Lin Memory

    14/18

    Memory OrganizationMemory Organization

    Memory zones DMA memory: first 16MB of main memory

    Kernel attempts to make memory available in this region for legacyhardware

    Normal memory: between 16MB and 896MB on the IA-32architecture

    Stores user data and most kernel data

    High memory: > 896MB on the IA-32 architecture

    Contains memory that the kernel does not permanently map to itsaddress space

    Bounce buffer Allocates low memory temporarily for I/O

    Data is bounced to high memory after I/O completes

  • 8/3/2019 Win Lin Memory

    15/18

    Physical memory zones on the IAPhysical memory zones on the IA--3232

  • 8/3/2019 Win Lin Memory

    16/18

    Page ReplacementPage Replacement

    Page replacement is performed independently for each pagezone Algorithm is a variant of the clock page-replacement algorithm

    Two linked lists per zone

    Active list contains pages that have been referenced recently

    Inactive list contains pages that have been used less recently

    Page enters system at the head of the inactive list, referenced bit set

    If the page is active or inactive and its referenced bit is off, the bit is turnedon

    Ensures that recently referenced pages are not selected forreplacement

    If page is inactive and is being referenced for the second time (referenced

    bit is on), page is moved to head of the active list, referenced bit is cleared Allows the kernel to distinguish between referenced pages that havebeen accessed once and those that have been accessed more than oncerecently

    The latter are placed in the active list so they are not selected forreplacement

  • 8/3/2019 Win Lin Memory

    17/18

    PagePage--replacement system overviewreplacement system overview

  • 8/3/2019 Win Lin Memory

    18/18

    SwappingSwapping

    kswapd(the kernel swap daemon)

    Periodically frees page frames by flushing dirty pages to disk

    Swaps pages from the tail of the inactive list

    First determines if the page has a valid entry in the swap cache

    Enables clean pages to be freed immediately

    Cannot free a page frame if

    Page is shared

    kswapdmust unmap multiple references to the page

    Reverse mapping improves efficiency

    Page is dirty

    kswapdmust flush it to disk

    Performed asynchronously bypdflush

    Page is locked (e.g., currently under I/O)

    kswapdmust wait until page is unlocked