Windows memory management

31
Windows Memory Management 06/06/2022 1

description

 

Transcript of Windows memory management

  • 1. 9/3/2012 1

2. Agenda Introduction to windows os Virtual memory Virtual address translation Page files / page faults Working set Physical memory Conclusion9/3/2012 2 3. 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 worlds 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.9/3/20123 4. 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.9/3/2012 4 5. 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).9/3/2012 5 6. 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.9/3/2012 6 7. 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).9/3/2012 7 8. 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 IA-64 today support 50 bits virtual = 1,048,576 GB = 1024 TB 64-bit Windows supports 44 bits= 16,384 GB = 16 TB9/3/20128 9. Virtual Address Space (V.A.S.) 00000000 Process space contains: UserUnique per Accessibleprocess The application you are running 7FFFFFFF (.EXE + .DLLs)80000000 A user-mode stack for each thread Kernel-mode System-accessible wide All static storage defined by the FFFFFFFF application9/3/2012 9 10. Virtual Address Space (V.A.S.)00000000 System space contains: Executive, KernelUserUnique perAccessibleprocess Statically-allocated system- wide data cells7FFFFFFF Page tables80000000 Kernel-mode device drivers Kernel-mode System- accessible wide File system cacheFFFFFFFF A kernel-mode stack for every thread in every process9/3/2012 10 11. 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.9/3/201211 12. 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 translation9/3/2012 12 13. Virtual Address Translation Hardware converts each valid virtual address to a physical address virtual address Virtual page numberByte within page Page DirectoryAddress translation (hardware) If pagePage not valid fault PageTablesPhysical page number Byte within page Translationphysical address Lookaside Buffer9/3/2012 13 14. Virtual address translation.9/3/2012 14 15. 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 backup9/3/2012 15 16. 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.9/3/2012 16 17. 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.9/3/201217 18. 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.9/3/2012 18 19. 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 faults9/3/2012 19 20. 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.9/3/201220 21. Working Set Listnewer pagesolder 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 itsworking set Many page faults may be resolved from memory 22. 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 thememory it has referenced (but not freed) 23. Working Set Replacement To standbyor modified page list Working Set When memory manager decides the process is large enough, itgive 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) 24. 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 25. 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 26. 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 27. Modified Page Writer When modified list reaches certain size, modified page writer systemthread 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 28. 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 awokento zero them On most busy systems, this is empty too 29. 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 30. Conclusion9/3/201230 31. Thank you9/3/2012 31