48
计计计计•计计计计计计计 Lecture 10 Memory Management(2) xlanchen@04/22/2005

Lecture 10 Memory Management(2)

  • Upload
    adanna

  • View
    26

  • Download
    3

Embed Size (px)

DESCRIPTION

Lecture 10 Memory Management(2). xlanchen@04/22/2005. 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 - PowerPoint PPT Presentation

Citation preview

Page 1: Lecture 10  Memory Management(2)

计算机系•信息处理实验室

Lecture 10 Memory Management(2)

xlanchen@04/22/2005

Page 2: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 3: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

3计算机系信息处理实验室

Page Fault Handling

Page fault||Kernel trap handler

||Memory manager: fault

handler

Page 4: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

4计算机系信息处理实验室

Page fault conditions

Page fault can be caused by a variety of conditions

See table 7-14

Page 5: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 6: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 7: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 8: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

8计算机系信息处理实验室

4 basic invalid PTEs

Unknown

The PTE is zero, or

The page table doesn't yet exist.

Page 9: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

0invalid the shared page

Page 10: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 11: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

11计算机系信息处理实验室

Two virtual pages (valid/invalid)

Page 12: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 13: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 14: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

14计算机系信息处理实验室

Page files

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

Page 15: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

15计算机系信息处理实验室

Virtual Address Descriptors

Lazy evaluation

Copy-on-write

Demand paging

Page table constructing

Advantages and disadvantages

Page 16: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

16计算机系信息处理实验室

Virtual Address Descriptors

Page 17: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

17计算机系信息处理实验室

EXPERIMENT

Viewing Virtual Address Descriptors

Page 18: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 19: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

19计算机系信息处理实验室

Paging Policies How (or when) paging is performed

fetch policy

placement policy

replacement policy

Page 20: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 21: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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 MB 3 2 5

12-19 MB 3 2 5

> 19 MB 8 4 8

Page 22: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

22计算机系信息处理实验室

Placement policy

Where

the size of CPU memory caches must be considered

to minimize unnecessary thrashing of the cache

Page 23: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 24: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

24计算机系信息处理实验室

2K replacement policy

For multiprocessor system

a variation of a local FIFO

For uniprocessor system

Similar to LRU

Page 25: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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)

Small 20 45

Medium 30 145

Large 50 345Maximum value must < system value

MmMaximumWorkingSetSize

Page 26: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 27: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

27计算机系信息处理实验室

Working Set-Related System Control Variables

Variable Value

MmWorkingSetSize-Increment 6

MmWorkingSetSize-Expansion 20

MmWsExpandThreshold 90

MmPagesAboveWsMinimum Dynamic

MmPagesAboveWsThreshold 37

MmWsAdjustThreshold 45

MmWsTrimReductionGoal 29

Page 28: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

28计算机系信息处理实验室

EXPERIMENT

Viewing Process Working Set Sizes

Viewing the Working Set List

Page 29: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 30: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 31: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 32: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

32计算机系信息处理实验室

System Working Setfive 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)

Page 33: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

33计算机系信息处理实验室

System Working Set Performance Counters

Performance Counter (in Bytes)

System Variable (in Pages)

Memory: Cache Bytes

MmSystemCacheWs.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

Page 34: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

34计算机系信息处理实验室

System Working Set

Minimum and Maximum Size

Memory Size

Minimum (in Pages)

Maximum (in Pages)

Small 388 500

Medium 688 1150

Large 1188 2050

Page 35: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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.

Page 36: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

36计算机系信息处理实验室

Page tables & PFN database

Page 37: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

37计算机系信息处理实验室

Page lists in PFN database

Page 38: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

38计算机系信息处理实验室

EXPERIMENT

Viewing the PFN Database

Page 39: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

39计算机系信息处理实验室

Page List Dynamics state diagram for page frame transitions

Page 40: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

40计算机系信息处理实验室

EXPERIMENT

Viewing Page Fault Behavior

Page 41: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 42: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

42计算机系信息处理实验室

Modified Page Writer Values

Memory Size Modified Page Threshold

Retain Modified Pages

< 12 MB 100 40

12-19 MB 150 80

19-33 MB 300 150

>33 MB (special case)

400 800

Page 43: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

43计算机系信息处理实验室

PFN Data Structures

The states of a PFN entry

Page 44: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 45: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding 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

Page 46: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

46计算机系信息处理实验室

A section object

Page 47: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

47计算机系信息处理实验室

Internal section structures

Page 48: Lecture 10  Memory Management(2)

xlanchen@04/22/2005 Understanding the Inside of Windows2000

48计算机系信息处理实验室

EXPERIMENT

Viewing Section Objects

Viewing Control Areas