1 / 17

Windows Memory Architecture

Windows Memory Architecture. 井民全製作. A Process ’ s Virtual Address Space. Every Process has its own private virtual address 32-bits processes  4 GB address space 64-bits processes  16 EB (extrabytes) A thread in a process can access its own address space

Download Presentation

Windows Memory Architecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Windows Memory Architecture 井民全製作

  2. A Process’s Virtual Address Space • Every Process has its own private virtual address • 32-bits processes  4 GB address space • 64-bits processes  16 EB (extrabytes) • A thread in a process can access its own address space • Other process’s address space hidden and inaccessible

  3. Win2K:作業系統的記憶體位址是被隱藏的不被thread 看到 Win98:則 thread 可能會意外存取道系統的資料 (詳情請看後面的記憶體分佈表) A thread in process A cannot access the data in process B’s address space Process A Thread access 0x12345678 code Process B Thread access 0x12345678 code

  4. How a Virtual Address Space is Partitioned

  5. 修正 數量單位對照表 並沒有完全使用到

  6. How a Virtual Address Space is Partitioned (64k for W2k, 4K for W98) • Null-Pointer Assignment Partition • Help to detect NULL-pointer assignments • Any thread attempts to read/ write this partition  access violation int* pnSomeInteger=(int*) malloc(sizeof(int)); *pnSomeInteger=5; 當 malloc 配置記憶體不足時, 會傳回 NULL, 上面的程式會導致存取位址空間 0x00000000

  7. Windows 98 Only - MS-DOS/16 Bits Windows AP compatibility partition • 4MB address space (0x00001000 – 0x003fffff) • For MS-DOS or 16-bits Windows AP Our 32-bits AP should not attempt to access this partition 在 Win2000 中, 這區段屬於 User Mode

  8. User-Mode Partition (0x00010000-0x7FFEFFFF 大約是 2 G bytes) 剩下空間的給 User-Mode • The process’s private address space • One process cannot access another process’s data in this partition Win2000: 1. all .exe and DLL modules load in this area 2. System also maps all memory-mapped files within this partition Win98: 1. System DLLs load in the Shared Memory Mapped File partition 2. all shared DLLs will be the same virtual address for all processes 3. memory-mapped files never appear in the user-mode area System DLLs Kernel32, AdvAPI32, User32 and GDI32

  9. A Large outcry from developers • Getting a 3-GB User-Mode Partition (1G for Kernel) • Enable this mode Windows XP Professional (and greater)- Windows Server 2003- Windows Server 2003, Enterprise Edition- Windows Server 2003, Datacenter Edition- Windows 2000 Advanced Server- Windows 2000 Datacenter Server- Windows NT Server 4.0, Enterprise Edition Linking setup /LARGEADDRESSAWARE boot.ini [boot loader]timeout=30default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS[operating systems]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Pro"multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Pro with /3GB" /3GB 參考資料: http://www.eyeonline.com/support/technical_faqs/technical_faqs.html

  10. Penalty for the 3-GB Mode • Reduce the number of threads, stack and other resource • 使你程式可以存取 3 GB 的相關資料 參考資料 ms-help://MS.MSDNQTR.2004JAN.1033/memory/base/4gt_ram_tuning.htm

  11. 64-bits Windows • A lots of source code in which pointers are assumed to be 32-bit values 系統必須保證動態配置的記憶體不會高於 0x000000007FFFFFFF位址空間 在 64-bit 環境配置記憶體 位址可能高於2G, 但是你的 程式卻以為位址只有 32 bits 這樣會發生 Pointer Truncation 問題. user mode 除非,你的 AP 使用/LARGEADDRESSAWARE建立, 否則預設的情況下,只能使用 2-GB 位址空間 (DLL 不受影響) 在 64-bit 環境中,呼叫 32-bit DLL 並傳送位址(超過 2G)給它處理 4-TB address space in 64-bits Windows

  12. 64-KB Off-Limits Partition (W2k Only)(0x7FFF0000-0x7FFFFFFF) • Access  access violation • 因為高層的位址空間(0x80000000以上)只有 Kernel mode 程式能夠存取, 為了檢查位址更快速,Windows 2000 保留這部分的記憶體區間. 0x80000000 以上 0x7FFFFFFF access violation 64k 空間保留 0x7FFF0000 User-Mode 可使用的空間

  13. Win98 Only Shared MMF Partition(0x80000000-0xBFFFFFFF 大約1GB) • System store data that is shared all 32-bits processes • System DLLs are all loaded in this area with the same address for every processes • System also maps all memory-mapped file in this partition

  14. Kernel-Mode Partition • The area is where the OS’s code resides • Thread scheduling, memory management, • File systems support, networking support, • All device drivers is loaded in this partition • Shared among all processes • Access  access violation (win2000) Win98: the data in this partition is not protected (Any AP can corrupt the OS)

  15. 使用的部分 xxxxx 下一個配置的起點 0x00010000 0x00020000 64K-byte Regions in an address space • VirtualAlloc  allocating a region • The region begins on an allocation granularity boundary (64KB) • The size is a multiple of the page size (4-KB for win2K) Ex: If you attempt to reserve a 10-KB region of address space  12-KB • VirtualFree  releasing the region 你可以用 GetSysteInfo API 得到 page size 不同 CPU 有不同的 page size(Intel Itanium  8k bytes) 12 % 4 =0 The system reserves regions for your process 1. PEB (Process environment block) 2. TEB (Thread environment block) System 用來管理 Process 的區塊 這兩個由系統管理的 Region 並不受起始位址的限制 Process 用來管理 Thread 的區塊

  16. Committing Physical Storage Within a Region • Before you use a reserved regions, you must • Allocate physical storage • Map this storage to the reserved region • Note • Physical storage is always committed in pages • Call VirtualAlloc( ) to do this • Decommitting by calling VirtualFree( ) Committing process 看範例程式: VirtualAlloc動態配置記憶體

  17. 重要參考資料 • ms-help://MS.MSDNQTR.2004JAN.1033/dngenlib/html/msdn_ntvmm.htm

More Related