libroot/malloc: Add a free maximum to PagesAllocator.
128 MB should be more than enough memory in the global cache for most applications (this limit's hit once the application has 512 MB of live allocations, based on the current free percentage of 25%.)
This commit is contained in:
@@ -32,6 +32,9 @@ static const size_t kReserveAddressSpace = 128 * 1024 * 1024;
|
||||
/*! Cache up to this many percentage points of free memory (compared to used.) */
|
||||
static const size_t kFreePercentage = 25;
|
||||
|
||||
/*! Always forbid more free memory than this, even if it's below kFreePercentage. */
|
||||
static const size_t kFreeMaximum = 128 * 1024 * 1024;
|
||||
|
||||
/*! Always allow this much free memory, even if it's above kFreePercentage. */
|
||||
static const size_t kFreeMinimum = 128 * kPageSize;
|
||||
|
||||
@@ -252,6 +255,7 @@ public:
|
||||
}
|
||||
chunk = previousChunk;
|
||||
}
|
||||
|
||||
status_t status = _UnlockingRemoveAndUnmap(chunk);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
@@ -320,6 +324,8 @@ private:
|
||||
size_t freeLimit = ((fUsed * kFreePercentage) / 100);
|
||||
if (freeLimit < kFreeMinimum)
|
||||
freeLimit = kFreeMinimum;
|
||||
else if (freeLimit > kFreeMaximum)
|
||||
freeLimit = kFreeMaximum;
|
||||
else
|
||||
freeLimit = (freeLimit + (kPageSize - 1)) & ~(kPageSize - 1);
|
||||
return freeLimit;
|
||||
|
||||
Reference in New Issue
Block a user