Presentation is loading. Please wait.

Presentation is loading. Please wait.

计算机系 信息处理实验室 Lecture 10 Memory Management(2)

Similar presentations


Presentation on theme: "计算机系 信息处理实验室 Lecture 10 Memory Management(2)"— Presentation transcript:

1 计算机系 信息处理实验室 Lecture 10 Memory Management(2) xlanchen@04/22/2005

2 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 2 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

3 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 3 Page Fault Handling Page fault | |  Kernel trap handler | |  Memory manager: fault handler

4 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 4 Page fault conditions Page fault can be caused by a variety of conditions See table 7-14table 7-14

5 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 5 4 basic invalid PTEs Page file The desired page resides within a paging file. An in-page operation is initiated

6 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 6 4 basic invalid PTEs Demand zero A page of zeros The pager : zero page list | |  free list | |  standby list PTE format : zeros the page file number and offset in the former format

7 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 7 4 basic invalid PTEs Transition The desired page is in memory the standby, modified, or modified-no-write list The page is removed from the list and added to the working set

8 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 8 4 basic invalid PTEs Unknown The PTE is zero, or The page table doesn't yet exist.

9 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 9 Prototype PTEs For shared pages Prototype page table entries Section objects : an array of prototype PTEs First reference: Prototype PTE  real PTE Reference counter in PFN database 0  invalid the shared page

10 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 10 Prototype PTEs Structure of an invalid PTE that points to the prototype PTE States of a shared page Active/valid; transition; modified-no-write; demand zero; page file; mapped file Lazy updating

11 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 11 Two virtual pages (valid/invalid)

12 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 12 In-Paging I/O Reading a file to satisfy a page fault In-page I/O operation Synchronous not interruptible by APC

13 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 13 Collided page faults The currently being in-paged page is faulted by another thread or process A wait operation is issued When the I/O completes, all threads will be satisfied

14 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 14 Page files To store modified pages because of modified page writing 2K supports up to 16 paging files EXPERIMENT Viewing system page files Viewing Page File Usage with Task Manager

15 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 15 Virtual Address Descriptors Lazy evaluation Copy-on-write Demand paging Page table constructing Advantages and disadvantages

16 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 16 Virtual Address Descriptors

17 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 17 EXPERIMENT Viewing Virtual Address Descriptors

18 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 18 Working Sets Working Set A subset of virtual pages resident in physical memory Two types Process working sets System working set

19 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 19 Paging Policies How (or when) paging is performed fetch policy placement policy replacement policy

20 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 20 Fetch policy When Eager-paging (Before needed) Demand-paging (Until needed) 2K Demand-paging + …. to minimize the number of paging I/Os

21 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 21 Page Fault Read Clustering Values Memory Size Cluster Size for Code Pages in Images Cluster Size for Data Pages in Images Cluster Size for All Other Pages < 12 MB325 12-19 MB325 > 19 MB848

22 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 22 Placement policy Where the size of CPU memory caches must be considered to minimize unnecessary thrashing of the cache

23 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 23 Replacement policy Which Which virtual page must be removed from memory to make room for the new page Include LRU FIFO … Global or local

24 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 24 2K replacement policy For multiprocessor system a variation of a local FIFO For uniprocessor system Similar to LRU

25 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 25 Working Set Management Default Minimum and Maximum Working Set Sizes To change: SetProcessWorkingSetSize Memory Size Default Minimum Working Set Size (in Pages) Default Maximum Working Set Size (in Pages) Small2045 Medium30145 Large50345 Maximum value must < system value MmMaximumWorkingSetSize

26 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 26 Working set management When paging, it examines the process's working set limits and the amount of free memory When MmAvailablePages <= MmMinimumFreePages Must trimming working set (working set manager is called) Working set manager determines which how many

27 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 27 Working Set-Related System Control Variables VariableValue MmWorkingSetSize-Increment6 MmWorkingSetSize-Expansion20 MmWsExpandThreshold90 MmPagesAboveWsMinimumDynamic MmPagesAboveWsThreshold37 MmWsAdjustThreshold45 MmWsTrimReductionGoal29

28 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 28 EXPERIMENT Viewing Process Working Set Sizes Viewing the Working Set List

29 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 29 Balance Set Manager and Swapper Balance set manager A system thread for Working set expansion and trimming Routine: KeBalanceSetManager Two event 1-second timer expiring Internal working set manager

30 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 30 Balance set manager Every fourth time  wakes up swapper Swapper: routine (KeSwapProcessOrStack) Checks look-aside lists and adjusts their depths Looks for priority boosted threads Calls the working set manager

31 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 31 Swapper Called by Balance set manager Or scheduling code Looks for threads that can be swapped out And swapped in some threads

32 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 32 System Working Set five kinds of pages System cache pages Paged pool Pageable code and data in Ntoskrnl.exe Pageable code and data in device drivers System mapped views (sections mapped at 0xA0000000, such as Win32k.sys)

33 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 33 System Working Set Performance Counters Performance Counter (in Bytes) System Variable (in Pages) Memory: Cache BytesMmSystemCacheWs.WorkingSetSize Memory: Cache Bytes Peak MmSystemCacheWs.Peak Memory: System Cache Resident Bytes MmSystemCachePage Memory: System Code Resident Bytes MmSystemCodePage Memory: System Driver Resident Bytes MmSystemDriverPage Memory: Pool Paged Resident Bytes MmPagedPoolPage

34 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 34 System Working Set Minimum and Maximum Size Memory Size Minimum (in Pages) Maximum (in Pages) Small388500 Medium6881150 Large11882050

35 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 35 Page Frame Number Database the page frame number (PFN) database describes the state of each page in physical memory. States include Active/Transition/Standby/Modified/ Modified no-write/Free/Zeroed/Bad The PFN database consists of an array of structures that represent each physical page of memory on the system.

36 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 36 Page tables & PFN database

37 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 37 Page lists in PFN database

38 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 38 EXPERIMENT Viewing the PFN Database

39 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 39 Page List Dynamics state diagram for page frame transitions

40 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 40 EXPERIMENT Viewing Page Fault Behavior

41 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 41 Modified Page Writer writing pages back to disk, include two system threads MiModifiedPageWriter To paging file MiMappedPageWriter To mapped files The modified page writer event is triggered by the number of modified pages > MmModifiedPageMaximum Or MmAvailablePages < MmMinimumFreePages

42 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 42 Modified Page Writer Values Memory SizeModified Page Threshold Retain Modified Pages < 12 MB10040 12-19 MB15080 19-33 MB300150 >33 MB (special case) 400800

43 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 43 PFN Data Structures The states of a PFN entry

44 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 44 Flags Within PFN Database Entries Modified state Prototype PTE Parity error Read in progress Write in progress Start of nonpaged pool End of nonpaged pool In-page error

45 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 45 Section Objects section object can be mapped to the paging file or to another file on disk. Section objects, like other objects, are allocated and deallocated by the object manager

46 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 46 A section object

47 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 47 Internal section structures

48 计算机系 信息处理实验室 xlanchen@04/22/2005Understanding the Inside of Windows2000 48 EXPERIMENT Viewing Section Objects Viewing Control Areas


Download ppt "计算机系 信息处理实验室 Lecture 10 Memory Management(2)"

Similar presentations


Ads by Google