summaryrefslogtreecommitdiff
path: root/alloc.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-02-28 00:47:35 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-02-28 00:59:57 +0300
commite700c781a5783cb232e4b47b1ae94a53a6c77378 (patch)
tree3f5cc8ee50fcfbbb18d6a932d35d4589dce9f26c /alloc.c
parent59ac9b43d9254e6c56f9ab632c8d8cb337a8c5aa (diff)
downloadbdwgc-e700c781a5783cb232e4b47b1ae94a53a6c77378.tar.gz
Return free memory to OS explicitly before getting new memory from OS
* allchblk.c [USE_MUNMAP] (MUNMAP_THRESHOLD, GC_unmap_threshold): Move to alloc.c. * allchblk.c [USE_MUNMAP] (GC_unmap_threshold): Change type from int to unsigned. * include/private/gc_priv.h [USE_MUNMAP] (GC_unmap_threshold): Likewise. * allchblk.c [USE_MUNMAP] (GC_unmap_old): Add threshold parameter. * include/private/gc_priv.h [USE_MUNMAP] (GC_unmap_old): Likewise. * allchblk.c [USE_MUNMAP] (GC_unmap_old): Do not skip unmapping if GC_unmap_threshold is 0; use threshold instead of GC_unmap_threshold. * alloc.c [USE_MUNMAP] (GC_finish_collection): Do not call GC_unmap_old if GC_unmap_threshold is 0; pass GC_unmap_threshold to GC_unmap_old. * alloc.c [USE_MUNMAP] (GC_collect_or_expand): Call GC_unmap_old(0) before GC_expand_hp_inner if GC_unmap_threshold > 1; add comment.
Diffstat (limited to 'alloc.c')
-rw-r--r--alloc.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/alloc.c b/alloc.c
index bb2071cf..61798f82 100644
--- a/alloc.c
+++ b/alloc.c
@@ -791,6 +791,11 @@ GC_API int GC_CALL GC_collect_a_little(void)
#endif /* !NO_CLOCK */
#ifdef USE_MUNMAP
+# ifndef MUNMAP_THRESHOLD
+# define MUNMAP_THRESHOLD 7
+# endif
+ GC_INNER unsigned GC_unmap_threshold = MUNMAP_THRESHOLD;
+
# define IF_USE_MUNMAP(x) x
# define COMMA_IF_USE_MUNMAP(x) /* comma */, x
#else
@@ -1193,8 +1198,9 @@ STATIC void GC_finish_collection(void)
GC_start_reclaim(FALSE);
# ifdef USE_MUNMAP
- if (EXPECT(GC_gc_no != 1, TRUE)) /* do not unmap during GC init */
- GC_unmap_old();
+ if (GC_unmap_threshold > 0 /* unmapping enabled? */
+ && EXPECT(GC_gc_no != 1, TRUE)) /* do not unmap during GC init */
+ GC_unmap_old(GC_unmap_threshold);
GC_ASSERT(GC_heapsize >= GC_unmapped_bytes);
# endif
@@ -1705,6 +1711,13 @@ GC_INNER GC_bool GC_collect_or_expand(word needed_blocks,
blocks_to_get = divHBLKSZ(GC_WORD_MAX);
}
+# ifdef USE_MUNMAP
+ if (GC_unmap_threshold > 1) {
+ /* Return as much memory to the OS as possible before */
+ /* trying to get memory from it. */
+ GC_unmap_old(0);
+ }
+# endif
if (!GC_expand_hp_inner(blocks_to_get)
&& (blocks_to_get == needed_blocks
|| !GC_expand_hp_inner(needed_blocks))) {