You are on page 1of 31

03-09-2012

Agenda

Introduction to windows os Virtual memory

Virtual address translation


Page files / page faults Working set Physical memory Conclusion
2

03-09-2012

Introduction to windows os
Microsoft Windows is a series of graphical interface operating systems

developed, marketed, and sold by Microsoft.


Microsoft Windows came to dominate the world's personal computer

market.
Microsoft introduced an operating environment named /Windows/ on

November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces.
The most recent version of Windows is Windows 7.

03-09-2012

Windows uses demand paging with Clustering. Clustering handles page faults by bringing in not only the

faulting page but also the multiple pages surrounding the faulting page.
Windows uses clock algorithm.

03-09-2012

What is Virtual Memory?


CPU can address up to 3GB of memory, using its full 32 bits.
This is normally far more than the RAM of the machine. The hardware provides for programs to operate in terms of as

much as they wish of this full 4GB space as Virtual Memory, those
parts of the program and data which are currently active being loaded into Physical Random Access Memory (RAM).

03-09-2012

Why virtual memory?


The first is to allow the use of programs that are too big to

physically fit in memory.


The other reason is to allow for multitasking multiple

programs running at once.

03-09-2012

Virtual Memory in Windows


In Windows the processor manages the mapping in terms of pages of

4 Kilobytes each a size that has implications for managing virtual memory by the system.
Only some parts of the program and data that are currently in active

use need to be held in physical RAM.


Other parts are then held in a swap file(in as its called in Windows

95/98/ME: Win386.swp )or page file(in Windows NT versions


including Windows 2000 and XP).

03-09-2012

Address space of Windows


32-bit Address Space 32-bits = 2^32 = 4 GB

3 GB for address space 1 GB for kernel mode

64-bit Address space 64-bits = 2^64 = 17,179,869,184 GB


x64 today supports 48 bits virtual

= 262,144 GB

= 256 TB = 1024 TB = 16 TB
8

IA-64 today support 50 bits virtual = 1,048,576 GB 64-bit Windows supports 44 bits
03-09-2012

= 16,384 GB

Virtual Address Space (V.A.S.)


Process space contains:
The application you are running
00000000

User Accessible

Unique per process


7FFFFFFF

(.EXE + .DLLs) A user-mode stack for each thread All static storage defined by the application

80000000

Kernel-mode accessible

Systemwide
FFFFFFFF

03-09-2012

Virtual Address Space (V.A.S.)


System space contains:
Executive, Kernel Statically-allocated system00000000

User Accessible

Unique per process


7FFFFFFF

wide data cells Page tables Kernel-mode device drivers File system cache A kernel-mode stack for every thread in every process

80000000

Kernel-mode accessible

Systemwide
FFFFFFFF

03-09-2012

10

What is loaded in RAM?


Items of RAM can be divided into two parts :
-Non paged area

Parts of system which are very important . This cannot be paged out.

-page pool

Program code, Data pages that had actual data written to them.

03-09-2012

11

Memory 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 look aside buffer) accelerates address translation


03-09-2012 12

Virtual Address Translation


Hardware converts each valid virtual address to a physical

address

virtual address Virtual page number Page Directory Byte within page

Address translation (hardware) If page


not valid

Page Tables
Translation Lookaside Buffer
03-09-2012

Page fault

Physical page number Byte within page physical address


13

Virtual address translation


.

03-09-2012

14

Page file

The page file is a hidden file called pagefile.sys. It is regenerated at each boot .

there is no need to include it in a backup

03-09-2012

15

The paging file and the RAM


The VMM creates a file on the hard disk that holds the extra memory that

is needed by the O.S.


This file is called a paging file (also known as a swap file), and plays an

important role in virtual memory.


The paging file combined with the RAM accounts for all of the memory. Whenever the O.S. needs a block of memory thats not in the real (RAM)

memory, the VMM takes a block from the real memory that hasnt been
used recently, writes it to the paging file.
Then it reads the block of memory that the O.S. needs from the paging

file.

03-09-2012

16

The paging file and the RAM


The VMM then takes the block of memory from the paging file, and

moves it into the real memory in place of the old block.


This process is called swapping (also known as paging),

The blocks of memory that are swapped are called pages.

03-09-2012

17

Page fault
When the program needs the page which is not in main

memory the page fault interrupt will be invoked.


If the this is available on disk then it will be swapped. If it is not available due to some hardware problems the

system will have invalid page fault error.


It may manifest itself as a blue screen failure with a STOP

code.
03-09-2012 18

Page Faults
A page fault occurs when there is a reference to a page that isnt

mapped to a physical page


The system goes to the appropriate block in the associated file to find

the contents of the page:


Physical page is allocated Block is read into physical page Page table entry is filled in Exception is dismissed Processor re-executes the instruction that caused the page fault

The page has now been faulted into the process working set
Pages are only brought into memory as a result of page faults
03-09-2012 19

Disadvantages of virtual memory


Virtual memory can slow down performance.
If the size of virtual memory is quite large in comparison to the real

memory, then more swapping to and from the hard disk will occur as a

result.
Accessing the hard disk is far slower than using system memory. Using too many programs at once in a system with an insufficient

amount of RAM results in constant disk swapping also


called thrashing.

03-09-2012

20

Working Set List

newer pages

older pages

Working Set All the physical pages owned by a process


E.g. the pages the process can reference without incurring a page fault

A process always starts with an empty working set


It then incurs page faults when referencing a page that isnt in its

working set
Many page faults may be resolved from memory

Working Set
Each process has a default working set minimum and maximum
Can change with SetProcessWorkingSet
Working set minimum controls maximum number of locked

pages (VirtualLock)
Minimum is also reserved from RAM as a guarantee to the

process
Working set maximum is ignored

If theres ample memory, process working set represents all the

memory it has referenced (but not freed)

Working Set Replacement


To standby or modified page list Working Set When memory manager decides the process is large enough, it

give up pages to make room for new pages


Local page replacement policy
Means that a single process cannot take over all of physical

memory unless other processes arent using it


Page replacement algorithm is least recently accessed

(pages are aged when available memory is low)

Working Set Breakdown


Consists of 2 types of pages:
Shareable (of which some may be shared)

Private

Four performance counters available:


Working Set Shareable

Working Set Shared (subset of shareable that are currently shared)

Working Set Private Working Set Size (total of WS Shareable+Private)

Note: adding this up for each process overcounts shared pages

Managing Physical Memory


System keeps unassigned physical pages on one of several lists
Free page list Modified page list Standby page lists (8 as of Vista & later) Zero page list Bad page list - pages that failed memory test at system startup

Lists are implemented by entries in the PFN database


Maintained as FIFO lists or queues

Standby and Modified Page Lists


Modified pages go to modified (dirty) list
Avoids writing pages back to disk too soon

Unmodified pages go to standby (clean) lists They form a system-wide cache of pages likely to be needed again
Pages can be faulted back into a process from the standby and

modified page list


These are counted as page faults, but not page reads

Modified Page Writer


When modified list reaches certain size, modified page writer system

thread is awoken to write pages out


Also triggered when memory is overcommitted (too few free pages) Does not flush entire modified page list

Pages move from the modified list to the standby list


E.g. can still be soft faulted into a working set

Free and Zero Page Lists


Free Page List
Used for page reads Private modified pages go here on process exit Pages contain junk in them (e.g. not zeroed) On most busy systems, this is empty

Zero Page List


Used to satisfy demand zero page faults

References to private pages that have not been created yet

When free page list has 8 or more pages, a priority zero thread is awoken

to zero them
On most busy systems, this is empty too

Super Fetch
Superfetch proactively repopulates RAM with the most useful data
Sets priority of pages to optimal value, based on the page history and

other analysis that it performs


Takes into account frequency of page usage, usage of page in context

of other pages in memory


Scenarios SuperFetch improves include
Resume from hibernate and suspend

Fast user switching


Performance after infrequent or low priority tasks execute Application launch

Conclusion

03-09-2012

30

Thank you

03-09-2012

31

You might also like