mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Free cached chunks when the requested memory limit is above real usage
This commit is contained in:
commit
c7558e2fe1
1 changed files with 14 additions and 1 deletions
|
@ -2661,7 +2661,20 @@ ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length)
|
||||||
ZEND_API zend_result zend_set_memory_limit(size_t memory_limit)
|
ZEND_API zend_result zend_set_memory_limit(size_t memory_limit)
|
||||||
{
|
{
|
||||||
#if ZEND_MM_LIMIT
|
#if ZEND_MM_LIMIT
|
||||||
if (UNEXPECTED(memory_limit < AG(mm_heap)->real_size)) {
|
zend_mm_heap *heap = AG(mm_heap);
|
||||||
|
|
||||||
|
if (UNEXPECTED(memory_limit < heap->real_size)) {
|
||||||
|
if (memory_limit >= heap->real_size - heap->cached_chunks_count * ZEND_MM_CHUNK_SIZE) {
|
||||||
|
/* free some cached chunks to fit into new memory limit */
|
||||||
|
do {
|
||||||
|
zend_mm_chunk *p = heap->cached_chunks;
|
||||||
|
heap->cached_chunks = p->next;
|
||||||
|
zend_mm_chunk_free(heap, p, ZEND_MM_CHUNK_SIZE);
|
||||||
|
heap->cached_chunks_count--;
|
||||||
|
heap->real_size -= ZEND_MM_CHUNK_SIZE;
|
||||||
|
} while (memory_limit < heap->real_size);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
AG(mm_heap)->limit = memory_limit;
|
AG(mm_heap)->limit = memory_limit;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue