slides 18 windows memory

Upload: sweidan-omar

Post on 07-Apr-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Slides 18 Windows Memory

    1/32

    Utolsmdosts: 2011. 04. 12.

    Az elads magnclra szabadon felhasznlhat. Kz- s felsoktatsbanfelhasznlhat, csak eltte krlek rj egy emailt nekem.

  • 8/3/2019 Slides 18 Windows Memory

    2/32

    A flik rszben a Windows Operating System Internals Curriculum Development

    Kit alapjn kszltek.

  • 8/3/2019 Slides 18 Windows Memory

    3/32

    Nem is olyan trivilismegvlaszolni!

    - Feladatkezel szmait vatosan kell kezelni!- Mit rtek szabad alatt?- Ha azt rja, hogy 10 MB van szabadon, akkor mirt tudok elindtani egy olyanprogramot, ami 15 MB memrit foglal le?- Cache-nek hasznlt memria hova szmt?- Ha a program, amit el akarok indtani, sok megosztott memrit hasznl, akkorlehet, hogy sokkal kevesebbet foglalna most, mint akkor, ha csak egyedl fut.

  • 8/3/2019 Slides 18 Windows Memory

    4/32

    Laptblk:

    - x86: 2 szint laptblk, x86 + PAE: 3szint, x64: 4 szint

    Lapozs:

    -Kezdetben igny szerintilapozs volt-Clustering: ezt kiegsztettk azzal, hogy a krt lap krnykn lv pr lapot isbehozta (lokalits elv)-Prefetch: XP ta van egy prefetcher, ami rgzti, hogy a programok indulskormiket szoktak ignyelni, s azokat elre behozza (rszletesebben lsd az eladsmsodik felben)

    -Vista ta tovbbi prefetchjelleg szolgltatsok (SuperFetch, ReadyBoost)

    Configuring the Memory Manager

    Like most of Windows, the memory manager attempts to automatically provide

    optimal system performance for varying workloads on systems of varying sizes and

    types. While there are a limited number of registry values you can add and/or

    modify under the key HKLM\ SYSTEM\CurrentControlSet\Control\Session

    Manager\Memory Management to override some of these default performance

    calculations, in general, the memory managers default computations will be

    sufficient for the majority of workloads.

  • 8/3/2019 Slides 18 Windows Memory

    5/32

    -32 bites rendszereken (ahol nincs PAE), 4 GB fizikai memria esetnis nha

    kevesebbet lt az OS, mert a memriatartomny fels rszre I/O eszkzketszoktak berakni (pl. ha van egy nagy memrij videokrtynk, akkor lehet, hogycsak 3,5 GB-ot lt az OS).-Physical Address Extension (PAE): bizonyos 32 bites processzorokban meglvtmogats, ilyenkor 32 helyett 36 cmbit van. Ha ezt az opercis rendszer ki tudjahasznlni, akkor kpes 64 GB fizikai memrit is kezelni. Figyelem: a folyamatokcmtere tovbbra is 32 bites marad, csak az OS tud tbb fizikai memrialapotkiosztani a klnbz folyamatoknak.

    -Kliens Windowsok nem hasznljk a gpben lv PAE tmogatst, mert az

    a tapasztalat, hogy a kliensekben lv eszkzk meghajti nem kezelik lerendesen a 4 GB-nl tbb fizikai memrit.-Lsd mg: Physical Address Extension, http://msdn.microsoft.com/en-us/library/aa366796%28v=VS.85%29.aspx

    rdekessgek:- Memory Limits for Windows Releases, http://msdn.microsoft.com/en-

    us/library/aa366778%28VS.85%29.aspx

    - Pushing the Limits of Windows: Physical Memory,

    http://blogs.technet.com/markrussinovich/archive/2008/07/21/3092070.aspx

  • 8/3/2019 Slides 18 Windows Memory

    6/3267

    -Alapesetben 32 bites rendszeren egy felhasznli folyamat maximum 2 GB-

    os cmtartomnyt hasznlhat fel a sajt kdjnaks adatnak trolsra. Acmtartomny msik rszn mindig a rendszer memriaterlet ltszik.-Ha a boot.ini-ben bekapcsoljuk a /3GB kapcsolt, akkor az arny 3 GB 1GB-ra vltozik(ez egy knyszer megolds volt, akkor kerlt bele, amikor mrkevs volt a 2 GB egy folyamatnak, pl. egy nagy adatbzis-kezelnek, demg nem trtek t a 64 bites OS-re)

    -Vista ta ezt 4GT-nek hvjk (4-gigabyte tuning), lsd:http://msdn.microsoft.com/en-

    us/library/bb613473%28VS.85%29.aspx

  • 8/3/2019 Slides 18 Windows Memory

    7/3277

    Ltvnyosannagyobb a cmtr 64 bites esetn, ez a f motivcija a 32

    bitrl ttrsnek.

  • 8/3/2019 Slides 18 Windows Memory

    8/3288

    No user process can touch another user process address space (without

    first opening a handle to the process, which means passing through NTsecurity)

    Separate process page tables prevent this

    Current page table changed on context switch from a thread inone process to a thread in another process

  • 8/3/2019 Slides 18 Windows Memory

    9/3298

    No user process can touch kernel memory

    Page protection in process page tables prevent this

    OS pages only accessible from kernel mode Threads change from user to kernel mode and back (via a

    secure interface) to execute kernel code, this does not

    affect scheduling (not a context switch)

  • 8/3/2019 Slides 18 Windows Memory

    10/32

    A commited memrinak kell helyet fenn tartani, a reserve mgcsak szndk

    jelzse.

  • 8/3/2019 Slides 18 Windows Memory

    11/32

    Az bra csakszemlltet jelleg, a valsg bonyolultabb ennl. Pl. a laptblkat is

    trolni kell valahol, azok is rszei a folyamat virtulis cmternek; a lapozfjlbanlv lapokra nem direktbe mutat r a laptbla

    11

  • 8/3/2019 Slides 18 Windows Memory

    12/32

    Forrs: Intel 64 and IA-32 Architectures Software Developers Manual,

    http://www.intel.com/products/processor/manuals/

    Hiba van PAE, a folyamatunk tovbbra is csak 2^20 fizikai memria keretet tudmegcmezni, gy a 12 bites offsettel egytt egy tovbbra is csak 4GB memria. Aklnbsg ott van a PAE-nl, hogy a fizikai memrialap cmzsre 24 bitethasznlunk, gy az OS a folyamatok 4 GB-os cmtereit 64 GB ( = 2^(24+12) ) fizikaicmtartomnyba tudja elhelyezni.

    13

  • 8/3/2019 Slides 18 Windows Memory

    13/32

    Forrs: Intel 64 and IA-32 Architectures Software Developers Manual,

    http://www.intel.com/products/processor/manuals/

    14

  • 8/3/2019 Slides 18 Windows Memory

    14/32

    Local kernel debuggerben

    !process 0 0!process

    egyik szl start address mezjt kikeresni!vtop 0

    hibt dob, mert rossz folyamat kontextusban prbljuk meg acmfordtst.process /p

    !vtop 0

    gy mr sikeres

    db !db

    elvileg ugyanazt kell ltni mindkt helyen!pfn

    Rszletesebb lers:

    - Virtulis -fizikai cmfordts Windows alatt x64-en,

    http://micskeiz.wordpress.com/2009/05/09/virtualis-fizikai-cimforditas-windows-

    alatt-x64-en/

    Vagy itt:

    -Understanding !PTE , Part 1: Lets get physical,

    http://blogs.msdn.com/ntdebugging/archive/2010/02/05/understanding-pte-part-

    17

  • 8/3/2019 Slides 18 Windows Memory

    15/32

    1-let-s-get-physical.aspx

    -Understanding !PTE, Part2: Flags and Large Pages ,

    http://blogs.msdn.com/ntdebugging/archive/2010/04/14/understanding-pte-

    part2-flags-and-large-pages.aspx

    17

  • 8/3/2019 Slides 18 Windows Memory

    16/32

    Working set: Implemented as array of working set listentries (WSLE)

    Soft vs. Hard laphiba:Soft page fault: memriban volt mg a lapHard page fault: lemezrl kell beolvasni

    Trimming: egy rendszer szl megvizsgljaa folyamatokat, s akinek sok fizikaimemrialapja van vagy rgta nem hasznlta ket, azoktl kezd elvenni prat. Ezt

    addig folyatja, amg elg szabad memria nem lesz a rendszerben.

  • 8/3/2019 Slides 18 Windows Memory

    17/32

    Status Description

    Active/valid: Page is part of working set (sys/proc), valid PTE points to itTransition: Page not owned by a working set, not on any paging list, I/O is in

    progress on this page

    Standby: Page belonged to a working set but was removed; not modified

    Modified: Removed from working set, modified, not yet written to disk

    Free: Page is free but has dirty data in it cannot be given to user process C2 security requirementZeroed: Page is free and has been initialized by zero page thread

    Bad: Page has generated parity or other hardware errors

  • 8/3/2019 Slides 18 Windows Memory

    18/3220

    Windows XP (& Embedded NT4) can run with no paging file

    NT4/Win2K: zero pagefile size actually creates a 20MBtemporary page file (\temppf.sys)

    WinPE never has a pagefile

    How to configure paging files for optimization and recovery in Windows

    XP (http://support.microsoft.com/kb/314482/en-us)

  • 8/3/2019 Slides 18 Windows Memory

    19/32

    Lapozfjllltsa: GUI: System Properties / Advanced / Performance, Settings /

    Advanced / Virtual Memory, SettingsRegistry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session

    Manager\Memory Management

  • 8/3/2019 Slides 18 Windows Memory

    20/3222

  • 8/3/2019 Slides 18 Windows Memory

    21/32

  • 8/3/2019 Slides 18 Windows Memory

    22/32

    A megosztott lapok beleszmolsa illetve nem szmolsa miatt llhat el az, hogy

    egyes folyamatoknl:a virtulis memria a nagyobb (okai lehetnek: kevesebb megosztott memriahasznlata; memriaterlete kikerlt a lapozfjlba; )a munkakszlet a nagyobb (pl. sok megosztott dll-t hasznlata)

    Ha sszeadjuk a Mem usage oszlop tartalmt, az nem a folyamatok ltal hasznlttnyleges fizikai memria lesz, mert az osztott lapokat tbbszr szmoltuk, sebben nincs benne a kernel memria.

  • 8/3/2019 Slides 18 Windows Memory

    23/32

    Process Explorer

    Kernel debugger: !vm, !memusage

  • 8/3/2019 Slides 18 Windows Memory

    24/32

    A VMMap segtsgvel megnzhetjk, hogy egy adott folyamatnak milyen elemek

    vannak jelenleg a cmterben:- Hogy oszlik meg kd/adat/halom/verem kztt- Adat esetn mennyi a reserved s mennyi a tnylegesen committed, majd ebbl

    mennyi van aktulisan a fizikai memriban

    26

  • 8/3/2019 Slides 18 Windows Memory

    25/32

  • 8/3/2019 Slides 18 Windows Memory

    26/32

    -Memrialapok eloszlsa

    -Indtsunk el egy memriaintenzvalkalmazst (pl. virtulis gp), s nzzk, hogyanvltozik az eloszls, hogyan n kzben a hard page fault / sec

    28

  • 8/3/2019 Slides 18 Windows Memory

    27/32

    A gondot az okozza, hogy prefetch nlkl elszr pr lapot az egyik fjlbl, majd

    pr lapot a msik dll-bl tlt be (ahogy ppen az utastsok jnnek a programkdban), s gy a merevlemezen a fejnek ssze-vissza kell mozognia.Rszletek:http://msdn.microsoft.com/msdnmag/issues/01/12/XPKernel/default.aspx

  • 8/3/2019 Slides 18 Windows Memory

    28/32

    Forrs: http://technet.microsoft.com/en-us/magazine/cc162480.aspx

    A significant change to the Memory Manager is in the way that it manages physical memory. The Standby Listmanagement used by previous versions of Windows has two limitations. First, the prioritization of pages reliesonly on the recent past behavior of processes and does not anticipate their future memory requirements.Second, the data used for prioritization is limited to the list of pages owned by a process at any given point intime. These shortcomings can result in scenarios like the "after lunch syndrome," where you leave yourcomputer for a while and a memory-intensive system application runs (such as an antivirus scan or diskdefragmentation). This application forces the code and data that your active applications had cached inmemory to be overwritten by the memory-intensive activities. When you return, you experience sluggishperformance as applications have to request their data and code from disk.Windows XP introduced prefetching support that improved boot and application startup performance byperforming large disk I/Os to preload memory with code and file system data that it expected, based onprevious boots and application launches. Windows Vista goes a big step further with SuperFetch, a memorymanagement scheme that enhances the least-recently accessed approach with historical information andproactive memory management.SuperFetch is implemented in %SystemRoot%\System32\Sysmain.dll as a Windows service that runs inside a

    Service Host process (%SystemRoot%\System32\Svchost.exe). The scheme relies on support from the MemoryManager so that it can retrieve page usage histories as well as direct the Memory Manager to preload dataand code from files on disk or from a paging file into the Standby List and assign priorities to pages. TheSuperFetch service essentially extends page-tracking to data and code that was once in memory, but that theMemory Manager has reused to make room for new data and code. It stores this information in scenario fileswith a .db extension in the %SystemRoot%\Prefetch directory alongside standard prefetch files used tooptimize application launch. Using this deep knowledge of memory usage, SuperFetch can preload data andcode when physical memory becomes available.Whenever memory becomes free-for example, when an application exits or releases memory-SuperFetch asksthe Memory Manager to fetch data and code that was recently evicted. This is done at a rate of a few pagesper second with Very Low priority I/Os so that the preloading does not impact the user or other activeapplications. Therefore, if you leave your computer to go to lunch and a memory-intensive background taskcauses the code and data from your active applications to be evicted from memory while you're gone,SuperFetch can often bring all or most of it back into memory before you return. SuperFetch also includesspecific scenario support for hibernation, standby, Fast User Switching (FUS), and application launch. When

    the system hibernates, for example, SuperFetch stores data and code in the hibernation file that it expects(based on previous hibernations) will be accessed during the subsequent resume. In contrast, when youresume Windows XP, previously cached data must be reread from the disk when it is referenced.

  • 8/3/2019 Slides 18 Windows Memory

    29/32

    defrag c: -b

    Layout.ini-nek megfelelen az indulshoz szksges fjlokat megprbljafolyamatosa helyre rendezni, hogy gyorsabb legyen az induls

  • 8/3/2019 Slides 18 Windows Memory

    30/32

    Technet HUN cikkek:

    Windows memriakezels - 1. rsz - Memriakezelsi alapok,http://www.microsoft.com/hun/technet/article/?id=7870c80b-7d94-4732-

    8220-256b625a3061

    Windows memriakezels - 2. rsz - A virtulis s a fizikai memria kapcsolata,http://www.microsoft.com/hun/technet/article/?id=d0da1b41-169a-4e8c-a793-

    d0af5dc31d37

    Windows memriakezels - 3. rsz - Paged s Nonpaged Pool,http://www.microsoft.com/hun/technet/article/?id=d698795b-d9a0-4c78-

    bd65-3be12d0780dc

    Windows memriakezels - 4. rsz - Page File s Working Set,http://www.microsoft.com/hun/technet/article/?id=dcf95237-3966-4213-a66c-

    88102d8d1cbf

    Windows memriakezels - 5. rsz - Memriakezelst gyorst szolgltatsok,http://www.microsoft.com/hun/technet/article/?id=a93f3d98-a3ff-42fb-a57d-

    47e2387250aa

    XP Prefetch:

    http://msdn.microsoft.com/msdnmag/issues/01/12/XPKernel/default.aspx

    Inside the Windows Vista Kernel

    - Part 1: http://technet.microsoft.com/en-us/magazine/2007.02.vistakernel.aspx

    - Part 2: http://technet.microsoft.com/en-us/magazine/2007.03.vistakernel.aspx

    http://msdn.microsoft.com/msdnmag/issues/01/12/XPKernel/default.aspxhttp://msdn.microsoft.com/msdnmag/issues/01/12/XPKernel/default.aspx
  • 8/3/2019 Slides 18 Windows Memory

    31/32

    - Part 3: http://technet.microsoft.com/en-us/magazine/2007.04.vistakernel.aspx

    34

  • 8/3/2019 Slides 18 Windows Memory

    32/32