VirtualBox

Changeset 46320 in vbox


Ignore:
Timestamp:
May 30, 2013 9:26:26 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86089
Message:

Main/PerformanceSolaris: switch to the runtime function for determining total/free RAM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/solaris/PerformanceSolaris.cpp

    r46316 r46320  
    3636#include <iprt/param.h>
    3737#include <iprt/path.h>
     38#include <iprt/system.h>
     39
    3840#include "Logging.h"
    3941#include "Performance.h"
     
    8587    uint64_t wrapDetection(uint64_t cur, uint64_t prev, const char *name);
    8688
    87     kstat_ctl_t *mKC;
    88     kstat_t     *mSysPages;
    89     kstat_t     *mZFSCache;
     89    kstat_ctl_t      *mKC;
     90    kstat_t          *mSysPages;
     91    kstat_t          *mZFSCache;
    9092
    9193    void             *mZfsSo;
     
    103105    FsMap             mFsMap;
    104106    uint32_t          mCpus;
     107
     108    ULONG             totalRAM;
    105109};
    106110
     
    151155        mZpoolVdevName  =  (PFNZPOOLVDEVNAME)dlsym(mZfsSo, "zpool_vdev_name");
    152156
    153         if (mZfsInit && mZfsOpen && mZfsClose && mZfsPropGetInt
    154             && mZpoolOpen && mZpoolClose && mZpoolGetConfig && mZpoolVdevName)
     157        if (   mZfsInit
     158            && mZfsOpen
     159            && mZfsClose
     160            && mZfsPropGetInt
     161            && mZpoolOpen
     162            && mZpoolClose
     163            && mZpoolGetConfig
     164            && mZpoolVdevName)
    155165            mZfsLib = mZfsInit();
    156166        else
     
    161171    updateFilesystemMap();
    162172    /* Notice that mCpus member will be initialized by HostCpuLoadRaw::init() */
     173
     174    uint64_t cb;
     175    int rc = RTSystemQueryTotalRam(&cb);
     176    if (RT_FAILURE(rc))
     177        totalRAM = 0;
     178    else
     179        totalRAM = (ULONG)(cb / 1024);
    163180}
    164181
     
    265282int CollectorSolaris::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
    266283{
    267     int rc = VINF_SUCCESS;
    268 
    269     kstat_named_t *kn;
    270 
    271     if (mKC == 0 || mSysPages == 0)
    272         return VERR_INTERNAL_ERROR;
    273 
    274     if (kstat_read(mKC, mSysPages, 0) == -1)
    275     {
    276         Log(("kstat_read(sys_pages) -> %d\n", errno));
    277         return VERR_INTERNAL_ERROR;
    278     }
    279     if ((kn = (kstat_named_t *)kstat_data_lookup(mSysPages, (char *)"freemem")) == 0)
    280     {
    281         Log(("kstat_data_lookup(freemem) -> %d\n", errno));
    282         return VERR_INTERNAL_ERROR;
    283     }
    284     *available = kn->value.ul * (PAGE_SIZE/1024);
    285 
    286     if (kstat_read(mKC, mZFSCache, 0) != -1)
    287     {
    288         if (mZFSCache)
    289         {
    290             if ((kn = (kstat_named_t *)kstat_data_lookup(mZFSCache, (char *)"size")))
    291             {
    292                 ulong_t ulSize = kn->value.ul;
    293 
    294                 if ((kn = (kstat_named_t *)kstat_data_lookup(mZFSCache, (char *)"c_min")))
    295                 {
    296                     /*
    297                      * Account for ZFS minimum arc cache size limit.
    298                      * "c_min" is the target minimum size of the ZFS cache, and not the hard limit. It's possible
    299                      * for "size" to shrink below "c_min" (e.g: during boot & high memory consumption).
    300                      */
    301                     ulong_t ulMin = kn->value.ul;
    302                     *available += ulSize > ulMin ? (ulSize - ulMin) / 1024 : 0;
    303                 }
    304                 else
    305                     Log(("kstat_data_lookup(c_min) ->%d\n", errno));
    306             }
    307             else
    308                 Log(("kstat_data_lookup(size) -> %d\n", errno));
    309         }
    310         else
    311             Log(("mZFSCache missing.\n"));
    312     }
    313 
    314     if ((kn = (kstat_named_t *)kstat_data_lookup(mSysPages, (char *)"physmem")) == 0)
    315     {
    316         Log(("kstat_data_lookup(physmem) -> %d\n", errno));
    317         return VERR_INTERNAL_ERROR;
    318     }
    319     *total = kn->value.ul * (PAGE_SIZE/1024);
    320     *used = *total - *available;
    321 
    322     return rc;
     284        uint64_t cb;
     285        int rc = RTSystemQueryAvailableRam(&cb);
     286        if (RT_SUCCESS(rc))
     287        {
     288            *total = totalRAM;
     289            *available = cb / 1024;
     290            *used = *total - *available;
     291        }
     292        return rc;
    323293}
    324294
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