VirtualBox

Changeset 2946 in kBuild


Ignore:
Timestamp:
Sep 20, 2016 1:46:56 AM (9 years ago)
Author:
bird
Message:

kWorker: Made the memory limit dynamic and overridable using KWORKER_MEMORY_LIMIT.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kWorker/kWorker.c

    r2941 r2946  
    88608860    if (GetProcessMemoryInfo(GetCurrentProcess(), &MemInfo, sizeof(MemInfo)))
    88618861    {
    8862         /** @todo make the limit dynamic and user configurable. */
     8862        /* The first time thru, we figure out approximately when to restart
     8863           based on installed RAM and CPU threads. */
     8864        static KU64 s_cbMaxWorkingSet = 0;
     8865        if (s_cbMaxWorkingSet != 0)
     8866        { /* likely */ }
     8867        else
     8868        {
     8869            SYSTEM_INFO SysInfo;
     8870            MEMORYSTATUSEX GlobalMemInfo;
     8871            const char    *pszValue;
     8872
     8873            /* Calculate a reasonable estimate. */
     8874            kHlpMemSet(&SysInfo, 0, sizeof(SysInfo));
     8875            GetNativeSystemInfo(&SysInfo);
     8876
     8877            kHlpMemSet(&GlobalMemInfo, 0, sizeof(GlobalMemInfo));
     8878            GlobalMemInfo.dwLength = sizeof(GlobalMemInfo);
     8879            if (!GlobalMemoryStatusEx(&GlobalMemInfo))
    88638880#if K_ARCH_BITS >= 64
    8864         if (MemInfo.WorkingSetSize >= 512*1024*1024)
     8881                GlobalMemInfo.ullTotalPhys = KU64_C(0x000200000000); /* 8GB */
    88658882#else
    8866         if (MemInfo.WorkingSetSize >= 384*1024*1024)
     8883                GlobalMemInfo.ullTotalPhys = KU64_C(0x000080000000); /* 2GB */
    88678884#endif
     8885            s_cbMaxWorkingSet = GlobalMemInfo.ullTotalPhys / (K_MAX(SysInfo.dwNumberOfProcessors, 1) * 4);
     8886            KW_LOG(("Raw estimate of s_cbMaxWorkingSet=%" KU64_PRI "\n", s_cbMaxWorkingSet));
     8887
     8888            /* User limit. */
     8889            pszValue = getenv("KWORKER_MEMORY_LIMIT");
     8890            if (pszValue != NULL)
     8891            {
     8892                char         *pszNext;
     8893                unsigned long ulValue = strtol(pszValue, &pszNext, 0);
     8894                if (*pszNext == '\0' || *pszNext == 'M')
     8895                    s_cbMaxWorkingSet = ulValue * (KU64)1048576;
     8896                else if (*pszNext == 'K')
     8897                    s_cbMaxWorkingSet = ulValue * (KU64)1024;
     8898                else if (*pszNext == 'G')
     8899                    s_cbMaxWorkingSet = ulValue * (KU64)1073741824;
     8900                else
     8901                    kwErrPrintf("Unable to grok KWORKER_MEMORY_LIMIT: %s\n", pszValue);
     8902                KW_LOG(("User s_cbMaxWorkingSet=%" KU64_PRI "\n", s_cbMaxWorkingSet));
     8903            }
     8904
     8905            /* Clamp it a little. */
     8906            if (s_cbMaxWorkingSet < 168*1024*1024)
     8907                s_cbMaxWorkingSet = 168*1024*1024;
     8908#if K_ARCH_BITS < 64
     8909            else
     8910                s_cbMaxWorkingSet = K_MIN(s_cbMaxWorkingSet,
     8911                                          SysInfo.dwProcessorType != PROCESSOR_ARCHITECTURE_AMD64
     8912                                          ?  512*1024*1024 /* Only got 2 or 3 GB VA */
     8913                                          : 1536*1024*1024 /* got 4GB VA */);
     8914#endif
     8915            if (s_cbMaxWorkingSet > GlobalMemInfo.ullTotalPhys)
     8916                s_cbMaxWorkingSet = GlobalMemInfo.ullTotalPhys;
     8917            KW_LOG(("Final s_cbMaxWorkingSet=%" KU64_PRI "\n", s_cbMaxWorkingSet));
     8918        }
     8919
     8920        /* Finally the check. */
     8921        if (MemInfo.WorkingSetSize >= s_cbMaxWorkingSet)
    88688922        {
    88698923            KW_LOG(("WorkingSetSize = %#x - > restart next time.\n", MemInfo.WorkingSetSize));
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