bool HttpServer::CanContinue(const MemInfo& mem, int64_t rssMb, int64_t rssNeeded, int cacheFreeFactor) { if (!mem.valid()) return false; if (mem.freeMb < RuntimeOption::ServerCriticalFreeMb) return false; auto const availableMb = availableMemory(mem, rssMb, cacheFreeFactor); auto const result = (rssMb + availableMb >= rssNeeded); if (result) assert(CanStep(mem, rssMb, rssNeeded, cacheFreeFactor)); return result; }
bool HttpServer::CanContinue(const MemInfo& mem, int64_t rssMb, int64_t rssNeeded, int cacheFreeFactor) { assert(CanStep(mem, rssMb, rssNeeded, cacheFreeFactor)); if (!mem.valid()) return false; // Don't proceed if free memory is too limited, no matter how big // the cache is. if (mem.freeMb < rssNeeded / 16) return false; auto const availableMb = availableMemory(mem, rssMb, cacheFreeFactor); return (rssMb + availableMb >= rssNeeded); }
bool HttpServer::CanStep(const MemInfo& mem, int64_t rssMb, int64_t rssNeeded, int cacheFreeFactor) { if (!mem.valid()) return false; if (mem.freeMb < RuntimeOption::ServerCriticalFreeMb) return false; auto const availableMb = availableMemory(mem, rssMb, cacheFreeFactor); // Estimation of the memory needed till the next check point. Since // the current check point is not the last one, we try to be more // optimistic, by assuming that memory requirement won't grow // drastically between successive check points, and that it won't // grow over our estimate. auto const neededToStep = std::min(rssNeeded / 4, rssNeeded - rssMb); return (availableMb >= neededToStep); }