VirtualBox

Changeset 2878 in kBuild


Ignore:
Timestamp:
Sep 5, 2016 7:54:49 PM (8 years ago)
Author:
bird
Message:

restart when we've leaked a lot of memory (this won't ever be perfect).

Location:
trunk/src/kWorker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kWorker/Makefile.kmk

    r2860 r2878  
    4040kWorker_LIBS.win = \
    4141        $(TEMPLATE_BIN-STATIC-THREADED_LIBS) \
    42         $(PATH_SDK_WINDDK71_LIB_WNET)/ntdll.lib
     42        $(PATH_SDK_WINDDK71_LIB_WNET)/ntdll.lib \
     43        $(PATH_SDK_WINDDK71_LIB_WNET)/psapi.lib
    4344kWorker_LDFLAGS.win = \
    4445        /BASE:0x10000 /DYNAMICBASE:NO /FIXED /SECTION:DefLdBuf,EWR
  • trunk/src/kWorker/kWorker.c

    r2877 r2878  
    3232*********************************************************************************************************************************/
    3333//#undef NDEBUG
     34#define PSAPI_VERSION 1
    3435#include <k/kHlp.h>
    3536#include <k/kLdr.h>
     
    4748
    4849#include "nt/ntstuff.h"
     50#include <psapi.h>
    4951
    5052#include "nt/kFsCache.h"
     
    59545956
    59555957
    5956 static void kwSandboxCleanup(PKWSANDBOX pSandbox)
    5957 {
    5958     PKWVIRTALLOC pTracker;
    5959     PKWLOCALSTORAGE pLocalStorage;
     5958/**
     5959 * Does sandbox cleanup between jobs.
     5960 *
     5961 * We postpone whatever isn't externally visible (i.e. files) and doesn't
     5962 * influence the result, so that kmk can get on with things ASAP.
     5963 *
     5964 * @param   pSandbox            The sandbox.
     5965 */
     5966static void kwSandboxCleanupLate(PKWSANDBOX pSandbox)
     5967{
     5968    PROCESS_MEMORY_COUNTERS     MemInfo;
     5969    PKWVIRTALLOC                pTracker;
     5970    PKWLOCALSTORAGE             pLocalStorage;
    59605971#ifdef WITH_TEMP_MEMORY_FILES
    5961     PKWFSTEMPFILE pTempFile;
    5962 #endif
    5963     PPEB pPeb = kwSandboxGetProcessEnvironmentBlock();
    5964     pPeb->ProcessParameters->CommandLine = pSandbox->SavedCommandLine;
    5965     /** @todo lots more to do here!   */
    5966 
    5967 #ifdef WITH_TEMP_MEMORY_FILES
     5972    PKWFSTEMPFILE               pTempFile;
     5973
     5974    /* The temporary files aren't externally visible, they're all in memory. */
    59685975    pTempFile = pSandbox->pTempFileHead;
    59695976    pSandbox->pTempFileHead = NULL;
     
    60186025    }
    60196026
     6027
    60206028    /* Free the environment. */
    60216029    if (pSandbox->papszEnvVars)
     
    60326040        pSandbox->papwszEnvVars[0] = NULL;
    60336041    }
     6042
     6043    /*
     6044     * Check the memory usage.  If it's getting high, trigger a respawn
     6045     * after the next job.
     6046     */
     6047    MemInfo.WorkingSetSize = 0;
     6048    if (GetProcessMemoryInfo(GetCurrentProcess(), &MemInfo, sizeof(MemInfo)))
     6049    {
     6050#if K_ARCH_BITS >= 64
     6051        if (MemInfo.WorkingSetSize >= 512*1024*1024)
     6052#else
     6053        if (MemInfo.WorkingSetSize >= 384*1024*1024)
     6054#endif
     6055        {
     6056            KW_LOG(("WorkingSetSize = %#x - > restart next time.\n", MemInfo.WorkingSetSize));
     6057            //fprintf(stderr, "WorkingSetSize = %#x - > restart next time.\n", MemInfo.WorkingSetSize);
     6058            g_fRestart = K_TRUE;
     6059        }
     6060    }
     6061}
     6062
     6063
     6064static void kwSandboxCleanup(PKWSANDBOX pSandbox)
     6065{
     6066    PPEB pPeb = kwSandboxGetProcessEnvironmentBlock();
     6067    pPeb->ProcessParameters->CommandLine = pSandbox->SavedCommandLine;
    60346068}
    60356069
     
    61156149            rcExit = 42 + 4;
    61166150
     6151        /* Clean up essential bits only, the rest is done after we've replied to kmk. */
    61176152        kwSandboxCleanup(&g_Sandbox);
    61186153    }
     
    65146549                                          cEnvVars, environ);
    65156550        KW_LOG(("rcExit=%d\n", rcExit));
     6551        kwSandboxCleanupLate(&g_Sandbox);
    65166552    }
    65176553
     
    66616697                        if (   rc == 0
    66626698                            && !g_fRestart)
     6699                        {
     6700                            kwSandboxCleanupLate(&g_Sandbox);
    66636701                            continue;
     6702                        }
    66646703                    }
    66656704                    else
     
    66706709                rc = kwErrPrintfRc(-1, "Bogus message length: %u (%#x)\n", cbMsg, cbMsg);
    66716710        }
     6711        FlushFileBuffers(hPipe);
     6712        CloseHandle(hPipe);
    66726713        return rc > 0 ? 0 : 1;
    66736714    }
Note: See TracChangeset for help on using the changeset viewer.

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