Windows CE Memory Management

Slides:



Advertisements
Similar presentations
Paging: Design Issues. Readings r Silbershatz et al: ,
Advertisements

Memory management.
Jaishankar Sundararaman
Run-Time Storage Organization
Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
CS 241 Section Week #12 (04/22/10).
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
 Demand Technology Software, Inc. Memory Leaks Demand Technology 1020 Eighth Avenue South, Suite 6, Naples, FL phone: (941) fax: (941)
Windows 2000 Memory Management Computing Department, Lancaster University, UK.
Tutorial 6 Memory Management
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
Tutorial 7 Memory Management presented by: Antonio Maiorano Paul Di Marco.
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.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Chapter 4 Memory Management Virtual Memory.
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.
Swap Space and Other Memory Management Issues Operating Systems: Internals and Design Principles.
Processes and Virtual Memory
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation.
Pintos project 3: Virtual Memory Management
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Memory Management Chapter 5 Advanced Operating System.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
Lesson Objectives Aims Key Words Paging, Segmentation, Virtual Memory
Chapter 3: Windows7 Part 5.
Object Lifetime and Pointers
Memory Management Virtual Memory.
Chapter 2: The Linux System Part 4
Memory Management.
Processes and threads.
Virtualization Virtualize hardware resources through abstraction CPU
Operating Systems CMPSC 473
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
Structure of Processes
Run-time organization
Swapping Segmented paging allows us to have non-contiguous allocations
Software Development with uMPS
PA1 is out Best by Feb , 10:00 pm Enjoy early
CSCI206 - Computer Organization & Programming
Chapter 3: Windows7 Part 5.
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Making Virtual Memory Real: The Linux-x86-64 way
System Structure and Process Model
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Memory Allocation CS 217.
Chapter 9: Virtual Memory
Memory Management Overview
Virtual Memory Hardware
Lecture 3: Main Memory.
Lecture Topics: 11/1 General Operating System Concepts Processes
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Operating Systems: A Modern Perspective, Chapter 6
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CS703 - Advanced Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
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.
COMP755 Advanced Operating Systems
Virtual Memory and Paging
Presentation transcript:

Windows CE Memory Management Virtual Memory Simplicity Efficient use of physical memory Code and Data share-ability Protection But CE shares the address space between processes (not really switching them)

Use of 32-bit Addressing FFFF FFFF Process Slots Reserved for OS (on ROM?) 32 31 8000 0000 Memory-mapped Files 4200 0000 1 0000 0000

Each process gets a 32 MB slot But CE supports only 32 processes max Remember processes typically need for VA 0 to some value. This implies that a process needs to be copied to slot 0 before it can run Context switch will swap back from slot 0 to appropriate slot.

Process Address Space (32MB) DLLs Extra Heaps & Stacks Heap Primary Stack Data Code Reserved area (64K)

There is not really extensive protection between processes. A process can read and rite another process’ memory by calling ReadProcessMemory() and WriteProcessMemory(). Question: Why cannot a process directly read/write someone else’s memory?

Paging CE implements VM via paging Page sizes can be either 1KB or 4KB (depends on CPU) On a x86, Page Dir. Page Table 10 bits 12 bits Offset Frame #

Memory Allocation Stacks Heaps Default size is 58KB Can use malloc()/free() Can use HeapAlloc()/HeapFree() Can use VirtualAlloc()/VirtualFree()

Local Heap Each process has a default local heap Of 384 KB, and can grow based on requirements You can allocate/de-allocate from local heap using LocalAlloc/LocalFree Ptr = (void *) LocalAlloc(LPTR, size); ….. LocalFree((HLOCAL) Ptr);

Supplemental Heaps With just 1 heap, fragmentation problems can become prevalent with multiple allocation sizes. You may want to create multiple heap sizes, each operating for one small range of sizes.

Using supplemental heaps HANDLE Hp = HeapCreate(0, // No special flag size, // Initial size 0); // No max size in CE Ptr = (void *) HeapAlloc(Hp, // Heap to allocate from HEAP_ZERO_MEMORY, // Zero it out size); ……. HeapFree(Hp, 0, Ptr); GetProcessHeap() returns handle to Local Heap

Page Allocation Can directly call VirtualAlloc()/VirtualFree() provided by CE for page level management. These are anyway used by HeapAlloc/HeapFree (which are in turn used in implementing malloc/free). You can reserve a group of contiguous pages (without actually allocating physical memory), or you can also commit the physical memory at the same time. Usually, you auto-commit, i.e. you reserve and physical memory is allocated when you actually use this space

VirtualAlloc() pMemPool = VirtualAlloc(NULL, POOL_SIZE, MEM_RESERVE | MEM_AUTO_COMMIT. // Can also be MEM_COMMIT PAGE_READWRITE); // Permissions ….. UncommitMemory(pMemPool,MEM_POOL_SIZE); // Has to be uncommitted before freeing! VirtualFree(pMemPool, 0, MEM_RELEASE);

Uncommiting Memory UncommitMemory(LPVOID paddr, DWORD dwsize) { MaxAddr = paddr + dwsize; do { MEMORY_BASIC_INFORMATION mbi; VirtualQuery(paddr, &mbi, sizeof(mbi)); if (mbi.State & MEM_COMMIT) VirtualFree(mbi.BaseAddress, mbi.RegionSize, MEM_DECOMMIT); paddr = mbi.BaseAddress + mbi.RegionSize; } while (paddr < pMaxAddr); }

Relationship Application Globals VirtualAlloc() LocalAlloc() HeapAlloc() Malloc()/new() Stack

Thread Local Storage Having globals creates problems, either in application programs or in DLLs The variables are not actually shared! But at the same time using different names is inconvenient. CE provides declarations for TLBs. E.g. __declspec(thread) static int count; // Each thread has one such count

Memory Shortage It enters low memory state when available memory falls below threshold (128KB) It sends WM_HIBERNATE signal to applns asking them to release memory, and sends WM_ACTIVATE afterwards The memory allocation functions may start failing.

Static Memory Usage dumpbin /headers appln.exe Dumps the virtual addresses and sizes of different sections of the program. The common sections include .text (executable code) .data (global/static variables) .rdata (read-only data – strings, constants) .debug (debug information) You can try to go over the static layout, move things around to lower memory needs.

Dynamic Memory Usage GlobalMemoryStatus() returns VM and PM usage info using MEMORYSTATUS structure. Important fields of this structure dwMemoryLoad (util, in %) dwTotalPhys (total PM size) dwAvailPhys (Available PM size for system) dwTotalVirtual (total VM size) dwAvailVirtual (available VM size for process)

Remote Heap Walker This CE utility shows all the heaps used by an executing process For each heap, you can get what is allocated and what is free (and their addresses)

CESH Utility You can run “mi full” It gives for every process, for each page whether it is C (Code in ROM), R (read-only in ROM), c (Code in RAM), W (read-write in RAM), r (read-only in RAM), S (stack), O (Object store), P (pending commit), - (reserved, ready for commitment)

Optimizing for Low Memory Look at static and dynamic info for any possible optimizations Move as much data into read-only section (CE discards this more readily than read-write) Load data files only only when needed and write back as soon as possible. Process the WM_HIBERNATE message Track and fix memory leaks.