block_cache: Free up blocks more aggressively on low memory conditions.

Only keep a single block when there is a "critical" low resource state.
Also don't bother doing anything if there are no unused blocks.

Change-Id: Ibfcbd8cb0beb1446083ca83030ea8e81c59a9628
Reviewed-on: https://review.haiku-os.org/c/1576
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Augustin Cavalier 2019-07-10 18:43:40 -04:00 committed by waddlesplash
parent c91c69752b
commit 7a2f744859

View File

@ -1598,21 +1598,24 @@ block_cache::_LowMemoryHandler(void* data, uint32 resources, int32 level)
// (if there is enough memory left, we don't free any)
block_cache* cache = (block_cache*)data;
if (cache->unused_block_count <= 1)
return;
int32 free = 0;
int32 secondsOld = 0;
switch (level) {
case B_NO_LOW_RESOURCE:
return;
case B_LOW_RESOURCE_NOTE:
free = cache->unused_block_count / 8;
free = cache->unused_block_count / 4;
secondsOld = 120;
break;
case B_LOW_RESOURCE_WARNING:
free = cache->unused_block_count / 4;
free = cache->unused_block_count / 2;
secondsOld = 10;
break;
case B_LOW_RESOURCE_CRITICAL:
free = cache->unused_block_count / 2;
free = cache->unused_block_count - 1;
secondsOld = 0;
break;
}