; Chapter 7. Memory Management
Learning Center
Plans & pricing Sign in
Sign Out
Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

Chapter 7. Memory Management


  • pg 1
									    Chapter 7.
Memory Management

    데이터베이스 연구실
    석사 3학기 이 현 화
 How Microsoft Windows 2000 implements
  virtual memory
 How it manages the subset of virtual
  memory kept in physical memory
  – Mapping a process’s virtual address space
    into physical memory
  – Paging some of the contents of memory to
    disk when it becomes overcommitted – when
    running threads or system code try to use
    more physical memory than is currently
Memory Manager Components
 The memory manager is part of the Windows
  2000 executive and therefore exists in the file
 A set of executive system services for allocating,
  deallocating, and managing virtual memory
 A translation-not-valid and access fault trap
  handler for resolving hardware-detected memory
  management exceptions and making virtual
  pages resident on behalf of a process
Memory Manager Components

 Several key components
  –   Working set manager ( priority 16 )
  –   Process/stack swapper ( priority 23 )
  –   Modified page writer ( priority 17 )
  –   Mapped page writer ( priority 17 )
  –   Dereference segment thread (priority18)
  –   Zero page thread ( priority 0 )
Configuring the Memory Manager

 Registry value
  –   ClearPageFileAtShoutdown
  –   DisablePagingExecutive
  –   IoPageLockLimit
  –   LargePageMinimum
  –   LargeSystemCache
  –   NonPagedPoolQuota
  –   NonPagedPoolSize
  –   PagedPoolQuata
  –   PagedPoolSize
  –   SystemPages
 Examining Memory Usage
Experiment : viewing system memory information
Services the Memory Manager

 Allocate and free virtual memory
 Share memory between processes
 Map files into memory
 Flush virtual pages to disk
 Retrieve information about a range of
  virtual pages
 Change the protection of virtual pages
  and lock the virtual pages into memory
Reserving and Committing Pages

 Free, reserved, or committed
 Applications can first reserve address space and
  then commit pages in that address space. Or
  they can reserve and commit in the same
  function call.
 Reserved address space is simply a way for a
  thread to reserve a range of virtual addresses for
  future use.
 Committed pages are pages that, when
  accessed, ultimately translate to valid pages in
  physical memory.
Reserving and Committing Pages.

 If the pages are private to the process
   – First access as zero-initialized pages
   – Inaccessible to any other process unless they’re
     accessed using cross process memory function,
 Using the two-step process of reserving and
  committing memory can reduce memory usage
  by deferring committing pages until needed.
 Reserving and then committing memory is useful
  for applications that need a potentially large
  contiguous memory buffer; rather than
  committing pages for the entire region.
Locking Memory

 Two way
  – Device drivers can call the kernel-mode
    functions MmProbeAndLock-Pages,
    MmLockPagableDataSection, or
      Pages locked using this mechanism remain in
       memory until explicitly unlocked.
  – Win32 applications can call the VirtualLock
    function to lock pages in their process
    working set.
Shared Memory and mapped Files

 Shared memory can be defined as memory that is visible
  to more than one process or that is present in more than
  one process virtual address space
 Writable pages are mapped copy-on-write
 The underlying primitives in the memory manager
   – section objects (Win 32 API, file mapping objects) : P478
   – Fundamental primitive in the memory manager is used to
     map virtual addresses, A section can be opened by one
     process or by many.
   – To create a section object, call the Win32 CreateFileMapping
Shared Memory and mapped Files
                 For example,
                 If two processes use
                 the same DLL, it
                 would make sense to
                 load the referenced
                 code pages for that
                 DLL Into physical
                 memory only once
                 and share those page
                 between all processes
                 that map the DLL
Protecting Memory
 Windows 2000 provides this protection in four primary
   – 1) all systemwide data structures and memory pools used by
     kernel-mode system components can be accessed only
     while in kernel mode-user-mode threads can’t access these
   – 2) each process has a separate, private address space,
     protected from being accessed by any thread belonging to
     another process.
   – 3) in addition to the implicit protection virtual-to-physical
     address translation offers
   – 4) shared memory section objects have standard Windows
     2000 access-control lists(ACLs) that are checked when
     processes attempt to open them, thus limiting access of
     shared memory to those processes with the proper rights.
 Copy-on-Write page protection is an
  optimization the memory manager uses to
  conserve physical memory
 When a process maps a copy-on-write
  view of a section object that contains
  read/write pages, the memory manager
  defers making a copy of the pages until
  the page is written to.

                Before of

                After of
   Heap Function
 A heap is a region of one or more pages of reserved
  address space that can be subdivided and allocated
  in smaller chunks by the heap manager.
   – The heap manager is a set of functions that can be used to
     allocate and deallocate variable amounts of memory.
   – heap manager functions exist in two place : Ntdill.dll,
 To allocate memory from the heap, a thread must
  obtain a handle to it by calling GetProcessHeap.
   – A thread can then use the heap handle in calls to HeapAlloc
     and HeapFree to allocate and free memory blocks from that
Address Windowing
 Although Windows 2000 systems can support up to 64 GB
  of physical memory, each 32-bit user process has only 2-
  GB or 3_GB virtual address space. To allow process to
  allocate and access more physical memory , Windows 2000
  provides a set of functions called Address Windowing
  Extensions (AWE)
 AWE function is done in three steps.
   – 1. Allocating the physical memory to be used.
   – 2. Creating a region of virtual address space to act as a
     window to map views of the physical memory
   – 3. Mapping view of the physical memory into the window.
 To allocate physical memory, an application calls the Win32
  function AllocateUserPhysicalPages.
Address Windowing

                    Using AWE
                      to map
Address Windowing
 The AWE functions exist on all editions of
  Windows 2000 and are usable regardless of how
  much physical memory a system has.
 There are some restrictions on memory allocated
  and mapped by the AWE functions
   – Pages can’t be shared between processes.
   – The same physical page can’t be mapped to more than
     one virtual address in the same process.
   – Page protection is limited to read/write

To top