Commit 9fd052e7 by Jan Hubicka Committed by Jan Hubicka

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
parent f2f3dbc6
2019-11-22 Jan Hubicka <jh@suse.cz>
* 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.
2019-11-22 Richard Sandiford <richard.sandiford@arm.com> 2019-11-22 Richard Sandiford <richard.sandiford@arm.com>
* tree-vect-stmts.c (vect_model_simple_cost): Take an optional * tree-vect-stmts.c (vect_model_simple_cost): Take an optional
...@@ -2186,6 +2186,9 @@ ggc_collect (void) ...@@ -2186,6 +2186,9 @@ ggc_collect (void)
float allocated_last_gc = float allocated_last_gc =
MAX (G.allocated_last_gc, (size_t)param_ggc_min_heapsize * 1024); MAX (G.allocated_last_gc, (size_t)param_ggc_min_heapsize * 1024);
/* It is also good time to get memory block pool into limits. */
memory_block_pool::trim ();
float min_expand = allocated_last_gc * param_ggc_min_expand / 100; float min_expand = allocated_last_gc * param_ggc_min_expand / 100;
if (G.allocated < allocated_last_gc + min_expand && !ggc_force_collect) if (G.allocated < allocated_last_gc + min_expand && !ggc_force_collect)
return; return;
......
2019-11-22 Jan Hubicka <jh@suse.cz>
* lto.c (lto_wpa_write_files): Call memory_block_pool::trim.
2019-11-14 Martin Liska <mliska@suse.cz> 2019-11-14 Martin Liska <mliska@suse.cz>
* Make-lang.in: Remove wrong dependency * Make-lang.in: Remove wrong dependency
......
...@@ -387,6 +387,7 @@ lto_wpa_write_files (void) ...@@ -387,6 +387,7 @@ lto_wpa_write_files (void)
temp_priority.safe_push (part->insns); temp_priority.safe_push (part->insns);
temp_filenames.safe_push (xstrdup (temp_filename)); temp_filenames.safe_push (xstrdup (temp_filename));
} }
memory_block_pool::trim (0);
for (int set = 0; set < MAX (lto_parallelism, 1); set++) for (int set = 0; set < MAX (lto_parallelism, 1); set++)
{ {
......
...@@ -28,15 +28,30 @@ memory_block_pool memory_block_pool::instance; ...@@ -28,15 +28,30 @@ memory_block_pool memory_block_pool::instance;
memory_block_pool::memory_block_pool () : m_blocks (NULL) {} 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 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; block_list *next = to_free->m_next;
XDELETEVEC (m_blocks); XDELETEVEC (to_free);
m_blocks = next; to_free = next;
} }
} }
...@@ -62,3 +77,10 @@ mempool_obstack_chunk_free (void *chunk) ...@@ -62,3 +77,10 @@ mempool_obstack_chunk_free (void *chunk)
else else
XDELETEVEC (chunk); XDELETEVEC (chunk);
} }
/* Return allocated memory back to malloc (and to system). */
void
memory_block_pool::trim (int num)
{
instance.reduce_free_list (num);
}
...@@ -28,12 +28,15 @@ class memory_block_pool ...@@ -28,12 +28,15 @@ class memory_block_pool
public: public:
/* Blocks have fixed size. This is necessary for sharing. */ /* Blocks have fixed size. This is necessary for sharing. */
static const size_t block_size = 64 * 1024; static const size_t block_size = 64 * 1024;
/* Number of blocks we keep in the freelists. */
static const size_t freelist_size = 1024 * 1024 / block_size;
memory_block_pool (); memory_block_pool ();
static inline void *allocate () ATTRIBUTE_MALLOC; static inline void *allocate () ATTRIBUTE_MALLOC;
static inline void release (void *); static inline void release (void *);
void clear_free_list (); static void trim (int nblocks = freelist_size);
void reduce_free_list (int);
private: private:
/* memory_block_pool singleton instance, defined in memory-block.cc. */ /* memory_block_pool singleton instance, defined in memory-block.cc. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment