From 9fd052e775623581d2d277a1688b9fde94cb18d2 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Fri, 22 Nov 2019 15:37:37 +0100 Subject: Release memory-block-pool memory back to malloc. * ggc-page.c (ggc_collect): Call memory_block_pool::trim. * memory-block.cc (memory_block_pool::clear_free_list): Rename to ... (memory_block_pool::reduce_free_list): ... this one. (memory_block_pool::trim): New static function. * memory-block.h (memory_block_pool::freelist_size): New constant (memory_block_pool::clear_free_list): Rename to ... (memory_block_pool::reduce_free_list): ... this one. (memory_block_pool::trim): Declare. * lto.c (lto_wpa_write_files): Call memory_block_pool::trim. From-SVN: r278616 --- gcc/memory-block.cc | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'gcc/memory-block.cc') diff --git a/gcc/memory-block.cc b/gcc/memory-block.cc index 507feaed157..ebf8cdd1e53 100644 --- a/gcc/memory-block.cc +++ b/gcc/memory-block.cc @@ -28,15 +28,30 @@ memory_block_pool memory_block_pool::instance; memory_block_pool::memory_block_pool () : m_blocks (NULL) {} -/* Return all blocks from free list to the OS. */ +/* Reduce free list to NUM blocks and return remaining to malloc. */ void -memory_block_pool::clear_free_list () +memory_block_pool::reduce_free_list (int num) { - while (m_blocks) + block_list **blocks = &m_blocks; + + /* First skip NUM blocks. */ + + for (;num > 0 && *blocks; num--) + blocks = &(*blocks)->m_next; + + if (!*blocks) + return; + + /* And free the remainder of them. */ + + block_list *to_free = *blocks; + *blocks = NULL; + + while (to_free) { - block_list *next = m_blocks->m_next; - XDELETEVEC (m_blocks); - m_blocks = next; + block_list *next = to_free->m_next; + XDELETEVEC (to_free); + to_free = next; } } @@ -62,3 +77,10 @@ mempool_obstack_chunk_free (void *chunk) else XDELETEVEC (chunk); } + +/* Return allocated memory back to malloc (and to system). */ +void +memory_block_pool::trim (int num) +{ + instance.reduce_free_list (num); +} -- cgit v1.2.3