1 / 44

Lecture 9 Memory Management(1)

Lecture 9 Memory Management(1). xlanchen@04/15/2005. Two primary tasks Virtual memory  physical memory Paging. How 2K implements virtual memory? How it manages the working set?. Contents. Memory Manager Components Services the Memory Manager Provides System Memory Pools

julie
Download Presentation

Lecture 9 Memory Management(1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 9 Memory Management(1) xlanchen@04/15/2005

  2. Two primary tasks • Virtual memory  physical memory • Paging How 2K implements virtual memory? How it manages the working set? Understanding the Inside of Windows2000

  3. Contents • Memory Manager Components • Services the Memory Manager Provides • System Memory Pools • Address Space Layout • Address Translation • Page Fault Handling • Virtual Address Descriptors • Working Sets • Page Frame Number Database • Section Objects Understanding the Inside of Windows2000

  4. Understanding the Inside of Windows2000

  5. Memory Manager • In Ntoskrnl.exe • No parts of the memory manager exist in the HAL • The memory manager is • Fully reentrant Understanding the Inside of Windows2000

  6. Memory Manager Components • Components: • A set of executive system services • A translation-not-valid and access fault trap handler • Several key components that run in the context of six different kernel-mode system threads Understanding the Inside of Windows2000

  7. Six system threads • Working set manager (priority 16) • Called by the balance set manager • Once per second • When free memory falls below a certain threshold • Drives the overall memory management policies • Working set trimming • Aging • Modified page writing Understanding the Inside of Windows2000

  8. Six system threads • Process/stack swapper (priority 23) • In and out • Awakened by the balance set manager and the thread-scheduling code in the kernel • When an inswap or outswap operation needs to take place Understanding the Inside of Windows2000

  9. Six system threads • Modified page writer (priority 17) • Writes dirty pages on the modified list back to the appropriate paging files • Awakened when the size of the modified list needs to be reduced Understanding the Inside of Windows2000

  10. Six system threads • Mapped page writer (priority 17) • Writes dirty pages in mapped files to disk • Awakened when the size of the modified list needs to be reduced or If pages for mapped files have been on the modified list for more than 5 minutes. Understanding the Inside of Windows2000

  11. Six system threads • Dereference segment thread (priority 18) • Responsible for system cache and page file growth and shrinkage. • Zero page thread (priority 0) Understanding the Inside of Windows2000

  12. Configuring the Memory Manager • HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management • ClearPageFileAtShutdown • DisablePagingExecutive • IoPageLockLimit • LargePageMinimum • LargeSystemCache • NonPagedPoolQuota • NonPagedPoolSize • PagedPoolQuota • PagedPoolSize • SystemPages Understanding the Inside of Windows2000

  13. Understanding the Inside of Windows2000

  14. Determine System Memory Size • Values • Small: <19 MB • Medium: 20-32 MB • Large: >32 MB if 2K Professional >64 MB if 2K Server • Kernel-mode routines • MmQuerySystemSize • Small, medium, or large • MmIsThisAnNtAsSystem • TRUE for 2K Server; FALSE for 2K Professional Understanding the Inside of Windows2000

  15. Examining Memory Usage • EXPERIMENT • Viewing System Memory Information Understanding the Inside of Windows2000

  16. Pmon.exe (in the Windows 2000 Support Tools) • Pstat.exe (in the Platform SDK) Understanding the Inside of Windows2000

  17. EXPERIMENT • Accounting for Physical Memory Use Understanding the Inside of Windows2000

  18. System services • The memory manager provides a set of system services to • Allocate/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 • Lock the virtual pages into memory Understanding the Inside of Windows2000

  19. Services exposed through Win32 API • Page granularity virtual memory functions • Virtualxxx • Memory-mapped file functions • CreateFileMapping, MapViewOfFile • Heap functions • Heapxxx • the older interfaces Localxxx and Globalxxx Understanding the Inside of Windows2000

  20. Services provided by memory manager • Allocating/deallocating physical memory • Locking pages in physical memory for DMA transfers • To • Other kernel-mode components inside the executive • Device drivers • These functions begin with the prefixMm • Other, for example Ex… Understanding the Inside of Windows2000

  21. Services in detailed • Reserving and Committing Pages • Locking Memory • Allocation Granularity • Shared Memory and Mapped Files • Protecting Memory • Copy-on-Write • Heap Functions • Address Windowing Extensions Understanding the Inside of Windows2000

  22. Reserving and Committing Pages • Reserved address space • To reserve a range of virtual addresses for future use • If accessed, an access violation will occur • Committed pages • either private and not shareable or mapped to a view of a section • If accessed, ultimately translate to valid pages in physical memory. • Win32 functions • VirtualAlloc and VirtualAllocEx Understanding the Inside of Windows2000

  23. Locking Memory • Pages can be locked in memory in two ways • Using kernel-mode functions • MmProbeAndLockPages, MmLockPagableCodeSection, MmLockPagableDataSection, or MmLockPagableSectionByHandle. • Pages remain in memory until explicitly unlocked • Using Win32 function • VirtualLock • Lock pages in the process working set. • May paging Understanding the Inside of Windows2000

  24. Allocation Granularity • Each region begins on an integral boundary • System value: allocation granularity (e.g. 64KB) • GetSystemInfo • Not for kernel-mode code • May be a single-page granularity • The size of the region is • n X (system page size) Understanding the Inside of Windows2000

  25. Shared Memory and Mapped Files • To share memory among processes and the OS • For example: • Two processes share the same DLL • Sharing mode • Execute-only • Copy-on-write Understanding the Inside of Windows2000

  26. Section objects • File mapping objects (Win32 API) • CreateFileMapping • OpenFileMapping • … Understanding the Inside of Windows2000

  27. Protecting Memory • Kernel mode VS. user mode • Each process: a separate private address space • Hardware-controlled memory protection • Read/write, read-only, … • Standard ACLs for shared memory section objects • 2K is a robust, reliable OS Understanding the Inside of Windows2000

  28. Copy-on-Write before after Understanding the Inside of Windows2000

  29. Heap Functions • A heap • 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 • A set of functions that can be used to allocate and deallocate variable amounts of memory • The functions (in Ntdll.dll/Ntoskrnl.exe) Understanding the Inside of Windows2000

  30. Address Windowing Extensions Understanding the Inside of Windows2000

  31. System Memory Pools • two types of dynamically sized memory pools • Nonpaged pool • Paged pool • Look-Aside Lists • Driver Verifier Understanding the Inside of Windows2000

  32. Address Space Layout Understanding the Inside of Windows2000

  33. User Address Space Layout Understanding the Inside of Windows2000

  34. System Address Space Layout Understanding the Inside of Windows2000

  35. Address Translation Understanding the Inside of Windows2000

  36. Translating a Virtual Address • Components of a 32-bit virtual address on x86 systems Understanding the Inside of Windows2000

  37. Translating a valid virtual address (x86-specific) Understanding the Inside of Windows2000

  38. Page Directories • Each process has a single page directory • The physical address of the process page directory is stored in the kernel process (KPROCESS) block • but is also mapped virtually at address 0xC0300000 on x86 systems (0xC06000000 on systems running the PAE kernel image). • All code running in kernel mode references virtual addresses, not physical ones • CR3 on x86 systems • page directory entries Understanding the Inside of Windows2000

  39. Process and System Page Tables • page table • system page table • not all processes have the same view of system space • page fault Understanding the Inside of Windows2000

  40. System & process-private page tables Understanding the Inside of Windows2000

  41. Page Table Entries Understanding the Inside of Windows2000

  42. Translation Look-Aside Buffer Understanding the Inside of Windows2000

  43. Physical Address Extension • PAE • allows access to up to 64 GB of physical memory • The third level—page directory pointer table Understanding the Inside of Windows2000

  44. Understanding the Inside of Windows2000

More Related