Memory Management II CS 470 - Spring 2002. Overview Logical Addressing and Virtual Memory –Logical to Linear Address Mapping –Linear to Physical Address.

Slides:



Advertisements
Similar presentations
CSCC69: Operating Systems
Advertisements

Paging 1 CS502 Spring 2006 Paging CS-502 Operating Systems.
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
Memory/Storage Architecture Lab Computer Architecture Virtual Memory.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Memory Management (II)
Chapter 3.2 : Virtual Memory
Translation Buffers (TLB’s)
Address Translation Mechanism of 80386
Cosc 3P92 Week 9 & 10 Lecture slides
Topics covered: Memory subsystem CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Computer Architecture Lecture 28 Fasih ur Rehman.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Win32 Programming Lesson 16: Virtual Memory. Where are we?  We’ve covered the theory of Windows memory, and poked around some  Now let’s use how to.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Virtual Memory Expanding Memory Multiple Concurrent Processes.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally VIRTUALMEMORY.
Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations.
Win32 Programming Lesson 14: Introducing Windows Memory (C Rox…)
Virtual Memory Additional Slides Slide Source: Topics Address translation Accelerating translation with TLBs class12.ppt.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Processes and Virtual Memory
Memory Management CS Spring Overview Partitioning, Segmentation, and Paging External versus Internal Fragmentation Logical to Physical Address.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Win32 Programming Lesson 15: Practical Windows Memory (If you can read this you have good vision)
COS 318: Operating Systems Virtual Memory Design Issues.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
CS161 – Design and Architecture of Computer
Translation Lookaside Buffer
Lecture 11 Virtual Memory
Virtual Memory CSSE 332 Operating Systems
CS161 – Design and Architecture of Computer
Section 9: Virtual Memory (VM)
Virtual Memory User memory model so far:
Virtual Memory: Systems
Section 9: Virtual Memory (VM)
Anton Burtsev February, 2017
Address Translation Mechanism of 80386
Morgan Kaufmann Publishers
CSE 153 Design of Operating Systems Winter 2018
CSE 153 Design of Operating Systems Winter 2018
Virtual Memory: Systems
Chapter 9: Virtual-Memory Management
Virtual Memory: Systems
Virtual Memory Hardware
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
Translation Lookaside Buffer
Virtual Memory.
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSCI 380: Operating Systems William Killian
Computer Architecture
CSE 153 Design of Operating Systems Winter 2019
CS703 - Advanced Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
Translation Buffers (TLBs)
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Review What are the advantages/disadvantages of pages versus segments?
Instructor: Phil Gibbons
Memory allocation.
Presentation transcript:

Memory Management II CS Spring 2002

Overview Logical Addressing and Virtual Memory –Logical to Linear Address Mapping –Linear to Physical Address Mapping NT Virtual Address Descriptors –What is a VAD? –Virtual Memory Functions –Example: Displaying the VAD splay –Example: How does the stack work?

Logical to Physical Mapping SelectorSegment Offset Logical Address Segment Translation PG? DirPagePage Offset Page Translation Linear Address Physical Address Yes No Control Register 0, bit

Linear to Physical Mapping DirPageOffset Linear Address Dir Entry. Page Directory Pg Tbl Entry Page Table CR3 Physical Address 031 Physical Address Trans. Lookaside Buffer miss hit Valid? yes Page Fault Handler no

Page/Directory Table Entry Page Frame AddrDA CDCD RWRW USUS V V Valid R/W Read / Write U/S User / Supervisor W/TWrite through C/DCache Disabled A Accessed D Dirty LLarge page GLGlobal WTWT GLGL L

VM Access Steps Instruction references logical address Hardware looks up page table entry Valid PTE gives physical address Invalid PTE causes address exception (page fault) Handler copies page to memory from disk or net, updates PTE and restarts instruction. Now have valid PTE and so get physical address Physical address used to access cache

Virtual Memory Advantages Allows programs to be larger than physical memory, but more importantly it allows many more processes to be simultaneously active Page table entries allow for security with page level granularity But, much added complexity, especially danger of thrashing as memory is so much faster than disk access

NT Process Structure Process Access Token Thread a File c Section f Object Table Virtual Address Space Description Handle 1 Handle 2 Handle 3

Virtual Address Descriptors Per process splay of VAD’s describes its virtual address space VAD records location, security, and inheritance of a range of pages Each region can be free, reserved, or reserved and committed. –Reserved - No storage, Inaccessible, can’t reserve a second time –Committed - Storage can be associated with the region, can be accessible, PTE constructed on first access.

VAD Information Starting and Ending address for VAD range; amount of committed memory Pointers to other VAD structures in splay Attributes –Is allocated memory committed? –Shared/private flag –Protection (cf next slide) –Copy-on-write enabled flag - For Posix fork() –Inherited by forked child? (for mapped views) –Mapped view of section object?

VAD Protection Bits Combinations of the following: PAGE_NOACCESS, PAGE_READONLY, PAGE_READWRITE, PAGE_EXECUTE, PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_GUARD, and PAGE_NOCACHE Allocation types: MEM_RESERVE, MEM_COMMIT, MEM_TOP_DOWN

Virtual Memory Functions VirtualAllocateEx - To reserve or commit VirtualFreeEx - To de-commit or release VirtualProtectEx - To modify protection VirtualLock, VirtualUnlock - To lock pages into memory VirtualQueryEx - To get information on a region of memory GlobalMemoryStatus - To get summary information

Virtual Memory Allocation LPVOID VirtualAllocEx( HANDLE hProcess, LPVOID lpAddress, // can be NULL DWORD dwSize, DWORD flAllocationType, // See last slide DWORD flProtect // See last slide );

Freeing Virtual Memory BOOL VirtualFreeEx( HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, DWORD dwFreeType ); Types: MEM_DECOMMIT, MEM_RELEASE

Changing Protection BOOL VirtualProtectEx( HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, DWORD flNewProtect, PDWORD lpflOldProtect );

Locking Pages into Memory BOOL VirtualLock( LPVOID lpAddress, DWORD dwSize ); BOOL VirtualUnlock( LPVOID lpAddress, DWORD dwSize ); At most 30 pages can be locked -- without changing minimum working set size.

VAD Status Functions DWORD VirtualQueryEx( HANDLE hProcess, LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, // See next slide DWORD dwLength ); VOID GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer );

Memory Info Structure typedef struct _MEMORY_BASIC_INFORMATION { PVOID BaseAddress; PVOID AllocationBase; DWORD AllocationProtect; DWORD RegionSize; DWORD State; DWORD Protect; DWORD Type; // e.g. MEM_PRIVATE } MEMORY_BASIC_INFORMATION;

Summary Info Struct typedef struct _MEMORYSTATUS { DWORD dwLength; // of this struct DWORD dwMemoryLoad; DWORD dwTotalPhys, dwAvailPhys; DWORD dwTotalPageFile; dwAvailPageFile; DWORD dwTotalVirtual, dwAvailVirtual; } MEMORYSTATUS;

Example: mem.c Use VirtualQueryEx to print out vad info DWORD ShowRegion( HANDLE hProcess, LPCVOID addr) { MEMORY_BASIC_INFORMATION mbi; if (!VirtualQueryEx(hProcess, addr, &mbi, sizeof(mbi))) { Gripe(); return -1; } else { print_out_mbi (&mbi); }

PAGE_GUARD Protection Visual C++ VirtualAlloc doc says -- Pages in the region become guard pages. Any attempt to read from or write to a guard page causes the operating system to raise a STATUS_GUARD_PAGE exception and turn off the guard page status. Guard pages thus act as a one-shot access alarm.

How does the stack work? #include void main() { unsigned sptr; __asm { mov eax, esp mov sptr, eax } printf("esp: 0x%x\n", sptr); while (getchar()) { __asm { mov eax, esp sub eax, 4096 mov esp, eax mov sptr, eax mov eax, [esp] } printf("esp: 0x%x\n", sptr); }

Jumping over the Guard Page void main() { char a[4096]; } The assembly language is: push ebp mov ebp, esp mov eax, 4096 call __chkstk mov esp, ebp pop ebp See vc98\crt\src\intel\chkstk.asm in c:\program files\Microsoft Visual Studio