Changeset 12967 in vbox
- Timestamp:
- Oct 2, 2008 11:49:04 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 37399
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/mm.h
r12964 r12967 34 34 #include <VBox/types.h> 35 35 #include <VBox/x86.h> 36 #include <iprt/stdarg.h> 36 37 #include <VBox/sup.h> 37 38 … … 402 403 MMR3DECL(char *) MMR3HeapStrDup(PVM pVM, MMTAG enmTag, const char *psz); 403 404 MMR3DECL(char *) MMR3HeapStrDupU(PUVM pUVM, MMTAG enmTag, const char *psz); 405 MMR3DECL(char *) MMR3HeapAPrintf(PVM pVM, MMTAG enmTag, const char *pszFormat, ...); 406 MMR3DECL(char *) MMR3HeapAPrintfU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, ...); 407 MMR3DECL(char *) MMR3HeapAPrintfV(PVM pVM, MMTAG enmTag, const char *pszFormat, va_list va); 408 MMR3DECL(char *) MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va); 404 409 MMR3DECL(void) MMR3HeapFree(void *pv); 405 410 /** @} */ -
trunk/src/VBox/VMM/MM.cpp
r12814 r12967 1 1 /* $Id$ */ 2 2 /** @file 3 * MM - Memory M onitor(/Manager).3 * MM - Memory Manager. 4 4 */ 5 5 … … 21 21 22 22 23 /** @page pg_mm MM - The Memory Monitor/Manager 24 * 25 * WARNING: THIS IS SOMEWHAT OUTDATED! 26 * 27 * It seems like this is going to be the entity taking care of memory allocations 28 * and the locking of physical memory for a VM. MM will track these allocations and 29 * pinnings so pointer conversions, memory read and write, and correct clean up can 30 * be done. 31 * 32 * Memory types: 33 * - Hypervisor Memory Area (HMA). 34 * - Page tables. 35 * - Physical pages. 36 * 37 * The first two types are not accessible using the generic conversion functions 38 * for GC memory, there are special functions for these. 39 * 40 * 41 * A decent structure for this component need to be eveloped as we see usage. One 42 * or two rewrites is probabaly needed to get it right... 43 * 44 * 45 * 46 * @section Hypervisor Memory Area 47 * 48 * The hypervisor is give 4MB of space inside the guest, we assume that we can 49 * steal an page directory entry from the guest OS without cause trouble. In 50 * addition to these 4MB we'll be mapping memory for the graphics emulation, 51 * but that will be an independant mapping. 52 * 53 * The 4MBs are divided into two main parts: 54 * -# The static code and data 55 * -# The shortlived page mappings. 56 * 57 * The first part is used for the VM structure, the core code (VMMSwitch), 58 * GC modules, and the alloc-only-heap. The size will be determined at a 59 * later point but initially we'll say 2MB of locked memory, most of which 60 * is non contiguous physically. 61 * 62 * The second part is used for mapping pages to the hypervisor. We'll be using 63 * a simple round robin when doing these mappings. This means that no-one can 64 * assume that a mapping hangs around for very long, while the managing of the 65 * pages are very simple. 66 * 67 * 68 * 69 * @section Page Pool 70 * 71 * The MM manages a per VM page pool from which other components can allocate 72 * locked, page aligned and page granular memory objects. The pool provides 73 * facilities to convert back and forth between physical and virtual addresses 74 * (within the pool of course). Several specialized interfaces are provided 75 * for the most common alloctions and convertions to save the caller from 76 * bothersome casting and extra parameter passing. 77 * 23 /** @page pg_mm MM - The Memory Manager 24 * 25 * The memory manager is in charge of the following memory: 26 * - Hypervisor Memory Area (HMA) - Address space management. 27 * - Hypervisor Heap - A memory heap that lives in all contexts. 28 * - Tagged ring-3 heap. 29 * - Page pools - Primarily used by PGM for shadow page tables. 30 * - Locked process memory - Guest RAM and other. (reduce/obsolete this) 31 * - Physical guest memory (RAM & ROM) - Moving to PGM. (obsolete this) 32 * 33 * 34 * @section sec_mm_hma Hypervisor Memory Area 35 * 36 * The HMA is used when executing in raw-mode. We borrow, with the help of 37 * PGMMap, some unused space (one or more page directory entries to be precise) 38 * in the guest's virtual memory context. PGM will monitor the guest's virtual 39 * address space for changes and relocate the HMA when required. 40 * 41 * To give some idea what's in the HMA, study the 'info hma' output: 42 * @verbatim 43 VBoxDbg> info hma 44 Hypervisor Memory Area (HMA) Layout: Base 00000000a0000000, 0x00800000 bytes 45 00000000a05cc000-00000000a05cd000 DYNAMIC fence 46 00000000a05c4000-00000000a05cc000 DYNAMIC Dynamic mapping 47 00000000a05c3000-00000000a05c4000 DYNAMIC fence 48 00000000a05b8000-00000000a05c3000 DYNAMIC Paging 49 00000000a05b6000-00000000a05b8000 MMIO2 0000000000000000 PCNetShMem 50 00000000a0536000-00000000a05b6000 MMIO2 0000000000000000 VGA VRam 51 00000000a0523000-00000000a0536000 00002aaab3d0c000 LOCKED autofree alloc once (PDM_DEVICE) 52 00000000a0522000-00000000a0523000 DYNAMIC fence 53 00000000a051e000-00000000a0522000 00002aaab36f5000 LOCKED autofree VBoxDD2GC.gc 54 00000000a051d000-00000000a051e000 DYNAMIC fence 55 00000000a04eb000-00000000a051d000 00002aaab36c3000 LOCKED autofree VBoxDDGC.gc 56 00000000a04ea000-00000000a04eb000 DYNAMIC fence 57 00000000a04e9000-00000000a04ea000 00002aaab36c2000 LOCKED autofree ram range (High ROM Region) 58 00000000a04e8000-00000000a04e9000 DYNAMIC fence 59 00000000a040e000-00000000a04e8000 00002aaab2e6d000 LOCKED autofree VMMGC.gc 60 00000000a0208000-00000000a040e000 00002aaab2c67000 LOCKED autofree alloc once (PATM) 61 00000000a01f7000-00000000a0208000 00002aaaab92d000 LOCKED autofree alloc once (SELM) 62 00000000a01e7000-00000000a01f7000 00002aaaab5e8000 LOCKED autofree alloc once (SELM) 63 00000000a01e6000-00000000a01e7000 DYNAMIC fence 64 00000000a01e5000-00000000a01e6000 00002aaaab5e7000 HCPHYS 00000000c363c000 Core Code 65 00000000a01e4000-00000000a01e5000 DYNAMIC fence 66 00000000a01e3000-00000000a01e4000 00002aaaaab26000 HCPHYS 00000000619cf000 GIP 67 00000000a01a2000-00000000a01e3000 00002aaaabf32000 LOCKED autofree alloc once (PGM_PHYS) 68 00000000a016b000-00000000a01a2000 00002aaab233f000 LOCKED autofree alloc once (PGM_POOL) 69 00000000a016a000-00000000a016b000 DYNAMIC fence 70 00000000a0165000-00000000a016a000 DYNAMIC CR3 mapping 71 00000000a0164000-00000000a0165000 DYNAMIC fence 72 00000000a0024000-00000000a0164000 00002aaab215f000 LOCKED autofree Heap 73 00000000a0023000-00000000a0024000 DYNAMIC fence 74 00000000a0001000-00000000a0023000 00002aaab1d24000 LOCKED pages VM 75 00000000a0000000-00000000a0001000 DYNAMIC fence 76 @endverbatim 77 * 78 * 79 * @section sec_mm_hyperheap Hypervisor Heap 80 * 81 * The heap is accessible from ring-3, ring-0 and the raw-mode context. That 82 * said, it's not necessarily mapped into ring-0 on if that's possible since we 83 * don't wish to waste kernel address space without a good reason. 84 * 85 * Allocations within the heap are always in the same relative position in all 86 * contexts, so, it's possible to use offset based linking. In fact, the heap is 87 * internally using offset based linked lists tracking heap blocks. We use 88 * offset linked AVL trees and lists in a lot of places where share structures 89 * between RC, R3 and R0, so this is a strict requirement of the heap. However 90 * this means that we cannot easily extend the heap since the extension won't 91 * necessarily be in the continuation of the current heap memory in all (or any) 92 * context. 93 * 94 * All allocations are tagged. Per tag allocation statistics will be maintaing 95 * and exposed thru STAM when VBOX_WITH_STATISTICS is defined. 96 * 97 * 98 * @section sec_mm_r3heap Tagged Ring-3 Heap 99 * 100 * The ring-3 heap is a wrapper around the RTMem API adding allocation 101 * statistics and automatic cleanup on VM destruction. 102 * 103 * Per tag allocation statistics will be maintaing and exposed thru STAM when 104 * VBOX_WITH_STATISTICS is defined. 105 * 106 * 107 * @section sec_mm_page Page Pool 108 * 109 * The MM manages a page pool from which other components can allocate locked, 110 * page aligned and page sized memory objects. The pool provides facilities to 111 * convert back and forth between (host) physical and virtual addresses (within 112 * the pool of course). Several specialized interfaces are provided for the most 113 * common alloctions and convertions to save the caller from bothersome casting 114 * and extra parameter passing. 115 * 116 * 117 * @section sec_mm_locked Locked Process Memory 118 * 119 * MM manages the locked process memory. This is used for a bunch of things 120 * (count the LOCKED entries in the'info hma' output found in @ref sec_mm_hma), 121 * but the main consumer of memory is currently for guest RAM. There is an 122 * ongoing rewrite that will move all the guest RAM allocation to PGM and 123 * GMM. 124 * 125 * The locking of memory is something doing in cooperation with the VirtualBox 126 * support driver, SUPDrv (aka. VBoxDrv), thru the support library API, 127 * SUPR3 (aka. SUPLib). 128 * 129 * 130 * @section sec_mm_phys Physical Guest Memory 131 * 132 * MM is currently managing the physical memory for the guest. It relies heavily 133 * on PGM for this. There is an ongoing rewrite that will move this to PGM. (The 134 * rewrite is driven by the need for more flexible guest ram allocation, but 135 * also motivated by the fact that MMPhys is just adding stupid bureaucracy and 136 * that MMR3PhysReserve is a totally weird artifact that must go away.) 78 137 * 79 138 */ -
trunk/src/VBox/VMM/MMHeap.cpp
r8797 r12967 1 1 /* $Id$ */ 2 2 /** @file 3 * MM - Memory M onitor(/Manager)- Heap.3 * MM - Memory Manager - Heap. 4 4 */ 5 5 … … 571 571 572 572 /** 573 * Allocating string printf. 574 * 575 * @returns Pointer to the string. 576 * @param pVM The VM 577 * @param enmTag The statistics tag. 578 * @param pszFormat The format string. 579 * @param ... Format arguments. 580 */ 581 MMR3DECL(char *) MMR3HeapAPrintf(PVM pVM, MMTAG enmTag, const char *pszFormat, ...) 582 { 583 va_list va; 584 va_start(va, pszFormat); 585 char *psz = MMR3HeapAPrintfVU(pVM->pUVM, enmTag, pszFormat, va); 586 va_end(va); 587 return psz; 588 } 589 590 591 /** 592 * Allocating string printf. 593 * 594 * @returns Pointer to the string. 595 * @param pUVM Pointer to the user mode VM structure. 596 * @param enmTag The statistics tag. 597 * @param pszFormat The format string. 598 * @param ... Format arguments. 599 */ 600 MMR3DECL(char *) MMR3HeapAPrintfU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, ...) 601 { 602 va_list va; 603 va_start(va, pszFormat); 604 char *psz = MMR3HeapAPrintfVU(pUVM, enmTag, pszFormat, va); 605 va_end(va); 606 return psz; 607 } 608 609 610 /** 611 * Allocating string printf. 612 * 613 * @returns Pointer to the string. 614 * @param pVM The VM 615 * @param enmTag The statistics tag. 616 * @param pszFormat The format string. 617 * @param va Format arguments. 618 */ 619 MMR3DECL(char *) MMR3HeapAPrintfV(PVM pVM, MMTAG enmTag, const char *pszFormat, va_list va) 620 { 621 return MMR3HeapAPrintfVU(pVM->pUVM, enmTag, pszFormat, va); 622 } 623 624 625 /** 626 * Allocating string printf. 627 * 628 * @returns Pointer to the string. 629 * @param pUVM Pointer to the user mode VM structure. 630 * @param enmTag The statistics tag. 631 * @param pszFormat The format string. 632 * @param va Format arguments. 633 */ 634 MMR3DECL(char *) MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va) 635 { 636 /* 637 * The lazy bird way. 638 */ 639 char *psz; 640 int cch = RTStrAPrintfV(&psz, pszFormat, va); 641 if (cch < 0) 642 return NULL; 643 Assert(psz[cch] == '\0'); 644 char *pszRet = (char *)MMR3HeapAllocU(pUVM, enmTag, cch + 1); 645 if (pszRet) 646 memcpy(pszRet, psz, cch + 1); 647 RTStrFree(psz); 648 return pszRet; 649 } 650 651 652 /** 573 653 * Releases memory allocated with MMR3HeapAlloc() or MMR3HeapRealloc(). 574 654 * -
trunk/src/VBox/VMM/MMHyper.cpp
r12940 r12967 1 1 /* $Id$ */ 2 2 /** @file 3 * MM - Memory M onitor(/Manager)- Hypervisor Memory Area.3 * MM - Memory Manager - Hypervisor Memory Area. 4 4 */ 5 5 … … 925 925 { 926 926 RTGCPTR GCPtr; 927 rc = MMR3HyperMapHCRam(pVM, pvPages, cb, true, mmR3GetTagName(enmTag), &GCPtr); 927 rc = MMR3HyperMapHCRam(pVM, pvPages, cb, true, 928 MMR3HeapAPrintf(pVM, MM_TAG_MM, "alloc once (%s)", mmR3GetTagName(enmTag)), 929 &GCPtr); 928 930 if (VBOX_SUCCESS(rc)) 929 931 { -
trunk/src/VBox/VMM/MMInternal.h
r12815 r12967 347 347 * Page sub pool 348 348 * 349 * About the allocation of this struct rue. To keep the number of heap blocks,349 * About the allocation of this structure. To keep the number of heap blocks, 350 350 * the number of heap calls, and fragmentation low we allocate all the data 351 351 * related to a MMPAGESUBPOOL node in one chunk. That means that after the … … 667 667 /** Lookup list for the Hypervisor Memory Area. 668 668 * The offset is relative to the start of the heap. 669 * Use pHyperHeap HC or pHyperHeapGC to calculate the address.669 * Use pHyperHeapR3, pHyperHeapR0 or pHypeRHeapRC to calculate the address. 670 670 */ 671 671 RTUINT offLookupHyper; -
trunk/src/VBox/VMM/MMPagePool.cpp
r12815 r12967 1 1 /* $Id$ */ 2 2 /** @file 3 * MM - Memory M onitor(/Manager)- Page Pool.3 * MM - Memory Manager - Page Pool. 4 4 */ 5 5 -
trunk/src/VBox/VMM/MMPhys.cpp
r12814 r12967 1 1 /* $Id$ */ 2 2 /** @file 3 * MM - Memory M onitor(/Manager)- Physical Memory.3 * MM - Memory Manager - Physical Memory. 4 4 * 5 5 * @remarks This will will be eliminated ASAP, all physical memory management -
trunk/src/VBox/VMM/PGMPhys.cpp
r12690 r12967 1737 1737 if (VBOX_SUCCESS(rc)) 1738 1738 { 1739 rc = MMR3HyperMapHCRam(pVM, pNew, cbRam, true, pszDesc, &GCPtrNew); 1739 rc = MMR3HyperMapHCRam(pVM, pNew, cbRam, true, 1740 MMR3HeapAPrintf(pVM, MM_TAG_PGM_PHYS, "ram range (%s)", pszDesc), 1741 &GCPtrNew); 1740 1742 if (VBOX_SUCCESS(rc)) 1741 1743 { -
trunk/src/VBox/VMM/VMMAll/MMAll.cpp
r12814 r12967 1 1 /* $Id$ */ 2 2 /** @file 3 * MM - Memory M onitor(/Manager)- Any Context.3 * MM - Memory Manager - Any Context. 4 4 */ 5 5 -
trunk/src/VBox/VMM/VMMAll/MMAllHyper.cpp
r12814 r12967 1 1 /* $Id$ */ 2 2 /** @file 3 * MM - Memory M onitor(/Manager)- Hypervisor Memory Area, All Contexts.3 * MM - Memory Manager - Hypervisor Memory Area, All Contexts. 4 4 */ 5 5 -
trunk/src/VBox/VMM/VMMAll/MMAllPagePool.cpp
r12815 r12967 1 1 /* $Id$ */ 2 2 /** @file 3 * MM - Memory M onitor(/Manager)- Page Pool.3 * MM - Memory Manager - Page Pool. 4 4 * 5 5 * @remarks This file is NOT built for the raw-mode context.
Note:
See TracChangeset
for help on using the changeset viewer.