Пример #1
0
        private ProcessSemaphoreInfo[] GetAdditionalResourceInfo(ProcessRunnablePip runnableProcess)
        {
            if (TotalRamMb == null || TotalCommitMb == null || runnableProcess.Environment.Configuration.Schedule.UseHistoricalRamUsageInfo != true)
            {
                // Not tracking working set or commit memory
                return(null);
            }

            if (!m_ramSemaphoreNameId.IsValid)
            {
                m_ramSemaphoreNameId = runnableProcess.Environment.Context.StringTable.AddString(RamSemaphoreName);
                m_ramSemaphoreIndex  = m_workerSemaphores.CreateSemaphore(m_ramSemaphoreNameId, ProcessExtensions.PercentageResourceLimit);
            }

            if (!m_commitSemaphoreNameId.IsValid)
            {
                m_commitSemaphoreNameId = runnableProcess.Environment.Context.StringTable.AddString(CommitSemaphoreName);
                m_commitSemaphoreIndex  = m_workerSemaphores.CreateSemaphore(m_commitSemaphoreNameId, ProcessExtensions.PercentageResourceLimit);
            }

            var expectedMemoryCounters = GetExpectedMemoryCounters(runnableProcess);

            return(new ProcessSemaphoreInfo[]
            {
                ProcessExtensions.GetNormalizedPercentageResource(
                    m_ramSemaphoreNameId,
                    usage: expectedMemoryCounters.PeakWorkingSetMb,
                    total: TotalRamMb.Value),
                ProcessExtensions.GetNormalizedPercentageResource(
                    m_commitSemaphoreNameId,
                    usage: expectedMemoryCounters.PeakCommitUsageMb,
                    total: TotalCommitMb.Value),
            });
        }
Пример #2
0
        private ProcessSemaphoreInfo[] GetAdditionalResourceInfo(ProcessRunnablePip runnableProcess, ProcessMemoryCounters expectedMemoryCounters)
        {
            using (var semaphoreInfoListWrapper = s_semaphoreInfoListPool.GetInstance())
            {
                var semaphores = semaphoreInfoListWrapper.Instance;

                if (runnableProcess.Process.RequiresAdmin &&
                    runnableProcess.Environment.Configuration.Sandbox.AdminRequiredProcessExecutionMode.ExecuteExternalVm() &&
                    runnableProcess.Environment.Configuration.Sandbox.VmConcurrencyLimit > 0)
                {
                    semaphores.Add(new ProcessSemaphoreInfo(
                                       runnableProcess.Environment.Context.StringTable.AddString(PipInVmSemaphoreName),
                                       value: 1,
                                       limit: runnableProcess.Environment.Configuration.Sandbox.VmConcurrencyLimit));
                }

                if (TotalRamMb == null || runnableProcess.Environment.Configuration.Schedule.UseHistoricalRamUsageInfo != true)
                {
                    // Not tracking working set
                    return(semaphores.ToArray());
                }

                if (!m_ramSemaphoreNameId.IsValid)
                {
                    m_ramSemaphoreNameId = runnableProcess.Environment.Context.StringTable.AddString(RamSemaphoreName);
                    m_ramSemaphoreIndex  = m_workerSemaphores.CreateSemaphore(m_ramSemaphoreNameId, ProcessExtensions.PercentageResourceLimit);
                }

                bool enableLessAggresiveMemoryProjection = runnableProcess.Environment.Configuration.Schedule.EnableLessAggresiveMemoryProjection;
                var  ramSemaphoreInfo = ProcessExtensions.GetNormalizedPercentageResource(
                    m_ramSemaphoreNameId,
                    usage: enableLessAggresiveMemoryProjection ? expectedMemoryCounters.AverageWorkingSetMb : expectedMemoryCounters.PeakWorkingSetMb,
                    total: TotalRamMb.Value);

                semaphores.Add(ramSemaphoreInfo);

                if (runnableProcess.Environment.Configuration.Schedule.EnableHistoricCommitMemoryProjection)
                {
                    if (!m_commitSemaphoreNameId.IsValid)
                    {
                        m_commitSemaphoreNameId = runnableProcess.Environment.Context.StringTable.AddString(CommitSemaphoreName);
                        m_commitSemaphoreIndex  = m_workerSemaphores.CreateSemaphore(m_commitSemaphoreNameId, ProcessExtensions.PercentageResourceLimit);
                    }

                    var commitSemaphoreInfo = ProcessExtensions.GetNormalizedPercentageResource(
                        m_commitSemaphoreNameId,
                        usage: enableLessAggresiveMemoryProjection ? expectedMemoryCounters.AverageCommitSizeMb : expectedMemoryCounters.PeakCommitSizeMb,
                        total: TotalCommitMb.Value);

                    semaphores.Add(commitSemaphoreInfo);
                }

                return(semaphores.ToArray());
            }
        }
Пример #3
0
        private ProcessSemaphoreInfo[] GetAdditionalResourceInfo(ProcessRunnablePip runnableProcess)
        {
            if (TotalMemoryMb == null || runnableProcess.Environment.Configuration.Schedule.UseHistoricalRamUsageInfo != true)
            {
                // Not tracking total memory
                return(null);
            }

            int expectedUsage = GetExpectedRamUsageMb(runnableProcess);

            if (!m_ramSemaphoreNameId.IsValid)
            {
                m_ramSemaphoreNameId = runnableProcess.Environment.Context.StringTable.AddString(RamSemaphoreName);
                m_ramSemaphoreIndex  = m_workerSemaphores.CreateSemaphore(m_ramSemaphoreNameId, ProcessExtensions.PercentageResourceLimit);
            }

            return(new ProcessSemaphoreInfo[]
            {
                ProcessExtensions.GetNormalizedPercentageResource(
                    m_ramSemaphoreNameId,
                    usage: expectedUsage,
                    total: TotalMemoryMb.Value),
            });
        }