VirtualBox

Changeset 12967 in vbox


Ignore:
Timestamp:
Oct 2, 2008 11:49:04 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
37399
Message:

#1865: MM - docs and 4 new ring-3 heap APIs for string formatting.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/mm.h

    r12964 r12967  
    3434#include <VBox/types.h>
    3535#include <VBox/x86.h>
     36#include <iprt/stdarg.h>
    3637#include <VBox/sup.h>
    3738
     
    402403MMR3DECL(char *)    MMR3HeapStrDup(PVM pVM, MMTAG enmTag, const char *psz);
    403404MMR3DECL(char *)    MMR3HeapStrDupU(PUVM pUVM, MMTAG enmTag, const char *psz);
     405MMR3DECL(char *)    MMR3HeapAPrintf(PVM pVM, MMTAG enmTag, const char *pszFormat, ...);
     406MMR3DECL(char *)    MMR3HeapAPrintfU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, ...);
     407MMR3DECL(char *)    MMR3HeapAPrintfV(PVM pVM, MMTAG enmTag, const char *pszFormat, va_list va);
     408MMR3DECL(char *)    MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va);
    404409MMR3DECL(void)      MMR3HeapFree(void *pv);
    405410/** @} */
  • trunk/src/VBox/VMM/MM.cpp

    r12814 r12967  
    11/* $Id$ */
    22/** @file
    3  * MM - Memory Monitor(/Manager).
     3 * MM - Memory Manager.
    44 */
    55
     
    2121
    2222
    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
     43VBoxDbg> info hma
     44Hypervisor Memory Area (HMA) Layout: Base 00000000a0000000, 0x00800000 bytes
     4500000000a05cc000-00000000a05cd000                  DYNAMIC                  fence
     4600000000a05c4000-00000000a05cc000                  DYNAMIC                  Dynamic mapping
     4700000000a05c3000-00000000a05c4000                  DYNAMIC                  fence
     4800000000a05b8000-00000000a05c3000                  DYNAMIC                  Paging
     4900000000a05b6000-00000000a05b8000                  MMIO2   0000000000000000 PCNetShMem
     5000000000a0536000-00000000a05b6000                  MMIO2   0000000000000000 VGA VRam
     5100000000a0523000-00000000a0536000 00002aaab3d0c000 LOCKED  autofree         alloc once (PDM_DEVICE)
     5200000000a0522000-00000000a0523000                  DYNAMIC                  fence
     5300000000a051e000-00000000a0522000 00002aaab36f5000 LOCKED  autofree         VBoxDD2GC.gc
     5400000000a051d000-00000000a051e000                  DYNAMIC                  fence
     5500000000a04eb000-00000000a051d000 00002aaab36c3000 LOCKED  autofree         VBoxDDGC.gc
     5600000000a04ea000-00000000a04eb000                  DYNAMIC                  fence
     5700000000a04e9000-00000000a04ea000 00002aaab36c2000 LOCKED  autofree         ram range (High ROM Region)
     5800000000a04e8000-00000000a04e9000                  DYNAMIC                  fence
     5900000000a040e000-00000000a04e8000 00002aaab2e6d000 LOCKED  autofree         VMMGC.gc
     6000000000a0208000-00000000a040e000 00002aaab2c67000 LOCKED  autofree         alloc once (PATM)
     6100000000a01f7000-00000000a0208000 00002aaaab92d000 LOCKED  autofree         alloc once (SELM)
     6200000000a01e7000-00000000a01f7000 00002aaaab5e8000 LOCKED  autofree         alloc once (SELM)
     6300000000a01e6000-00000000a01e7000                  DYNAMIC                  fence
     6400000000a01e5000-00000000a01e6000 00002aaaab5e7000 HCPHYS  00000000c363c000 Core Code
     6500000000a01e4000-00000000a01e5000                  DYNAMIC                  fence
     6600000000a01e3000-00000000a01e4000 00002aaaaab26000 HCPHYS  00000000619cf000 GIP
     6700000000a01a2000-00000000a01e3000 00002aaaabf32000 LOCKED  autofree         alloc once (PGM_PHYS)
     6800000000a016b000-00000000a01a2000 00002aaab233f000 LOCKED  autofree         alloc once (PGM_POOL)
     6900000000a016a000-00000000a016b000                  DYNAMIC                  fence
     7000000000a0165000-00000000a016a000                  DYNAMIC                  CR3 mapping
     7100000000a0164000-00000000a0165000                  DYNAMIC                  fence
     7200000000a0024000-00000000a0164000 00002aaab215f000 LOCKED  autofree         Heap
     7300000000a0023000-00000000a0024000                  DYNAMIC                  fence
     7400000000a0001000-00000000a0023000 00002aaab1d24000 LOCKED  pages            VM
     7500000000a0000000-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.)
    78137 *
    79138 */
  • trunk/src/VBox/VMM/MMHeap.cpp

    r8797 r12967  
    11/* $Id$ */
    22/** @file
    3  * MM - Memory Monitor(/Manager) - Heap.
     3 * MM - Memory Manager - Heap.
    44 */
    55
     
    571571
    572572/**
     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 */
     581MMR3DECL(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 */
     600MMR3DECL(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 */
     619MMR3DECL(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 */
     634MMR3DECL(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/**
    573653 * Releases memory allocated with MMR3HeapAlloc() or MMR3HeapRealloc().
    574654 *
  • trunk/src/VBox/VMM/MMHyper.cpp

    r12940 r12967  
    11/* $Id$ */
    22/** @file
    3  * MM - Memory Monitor(/Manager) - Hypervisor Memory Area.
     3 * MM - Memory Manager - Hypervisor Memory Area.
    44 */
    55
     
    925925    {
    926926        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);
    928930        if (VBOX_SUCCESS(rc))
    929931        {
  • trunk/src/VBox/VMM/MMInternal.h

    r12815 r12967  
    347347 * Page sub pool
    348348 *
    349  * About the allocation of this structrue. To keep the number of heap blocks,
     349 * About the allocation of this structure. To keep the number of heap blocks,
    350350 * the number of heap calls, and fragmentation low we allocate all the data
    351351 * related to a MMPAGESUBPOOL node in one chunk. That means that after the
     
    667667    /** Lookup list for the Hypervisor Memory Area.
    668668     * The offset is relative to the start of the heap.
    669      * Use pHyperHeapHC or pHyperHeapGC to calculate the address.
     669     * Use pHyperHeapR3, pHyperHeapR0 or pHypeRHeapRC to calculate the address.
    670670     */
    671671    RTUINT                      offLookupHyper;
  • trunk/src/VBox/VMM/MMPagePool.cpp

    r12815 r12967  
    11/* $Id$ */
    22/** @file
    3  * MM - Memory Monitor(/Manager) - Page Pool.
     3 * MM - Memory Manager - Page Pool.
    44 */
    55
  • trunk/src/VBox/VMM/MMPhys.cpp

    r12814 r12967  
    11/* $Id$ */
    22/** @file
    3  * MM - Memory Monitor(/Manager) - Physical Memory.
     3 * MM - Memory Manager - Physical Memory.
    44 *
    55 * @remarks This will will be eliminated ASAP, all physical memory management
  • trunk/src/VBox/VMM/PGMPhys.cpp

    r12690 r12967  
    17371737        if (VBOX_SUCCESS(rc))
    17381738        {
    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);
    17401742            if (VBOX_SUCCESS(rc))
    17411743            {
  • trunk/src/VBox/VMM/VMMAll/MMAll.cpp

    r12814 r12967  
    11/* $Id$ */
    22/** @file
    3  * MM - Memory Monitor(/Manager) - Any Context.
     3 * MM - Memory Manager - Any Context.
    44 */
    55
  • trunk/src/VBox/VMM/VMMAll/MMAllHyper.cpp

    r12814 r12967  
    11/* $Id$ */
    22/** @file
    3  * MM - Memory Monitor(/Manager) - Hypervisor Memory Area, All Contexts.
     3 * MM - Memory Manager - Hypervisor Memory Area, All Contexts.
    44 */
    55
  • trunk/src/VBox/VMM/VMMAll/MMAllPagePool.cpp

    r12815 r12967  
    11/* $Id$ */
    22/** @file
    3  * MM - Memory Monitor(/Manager) - Page Pool.
     3 * MM - Memory Manager - Page Pool.
    44 *
    55 * @remarks     This file is NOT built for the raw-mode context.
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette