[Gc] Patch: more flexible unmapping control for GC_gcollect

Ivan Maidanski ivmai at mail.ru
Sun Sep 20 05:40:46 PDT 2009


This patch (ivmai150.diff) adds opportunity for turning on a new mode in which an implicit GC_gcollect (GC_try_to_collect) call would try to immediately unmap as much memory as possible (of course, if unmapping is on). It adds GC_FORCE_UNMAP_ON_GCOLLECT macro and env var, and public GC_set/get_force_unmap_on_gcollect() for switching the mode on and off.

The idea of it comes to me from test.c which calls GC_gcollect on WM_HYBERHATE.

Two usage examples:
- the user preses "GC" button in an application, and it returns as much as possible memory to OS;
- an explication failed to get some system resource (due to the OS failed to get some memory for it), it clears all soft refs, invokes finalizers, calls GC_gcollect() (which unmap as much as possible memory to the OS) before retrying.

ChangeLog entries:

	Add the comment for.
	* alloc.c (GC_unmap_threshold, GC_force_unmap_on_gcollect):
	Declare external variable (only if USE_MUNMAP).
	* alloc.c (GC_try_to_collect): Temporarily set GC_unmap_threshold
	value to 1 if GC_force_unmap_on_gcollect and restore it before
	unlocking (only if USE_MUNMAP).
	* doc/README.environment (GC_FORCE_UNMAP_ON_GCOLLECT): Add
	information for.
	* include/gc.h (GC_set_force_unmap_on_gcollect,
	GC_get_force_unmap_on_gcollect): New public function prototype.
	* include/gc.h (GC_FORCE_UNMAP_ON_GCOLLECT): New macro is
	* misc.c (GC_FORCE_UNMAP_ON_GCOLLECT): Ditto.
	internal macro (used by GC_INIT only).
	* misc.c (GC_force_unmap_on_gcollect): New global variable.
	* misc.c (GC_init): Recognize new "GC_FORCE_UNMAP_ON_GCOLLECT"
	environment variable (and set GC_force_unmap_on_gcollect).
	* misc.c (GC_set_force_unmap_on_gcollect,
	GC_get_force_unmap_on_gcollect): New public function.
	* tests/test.c (window_proc): Call GC_set_force_unmap_on_gcollect
	to force the mode on if WM_HIBERNATE; restore the mode after

PS. If no objections, I'd commit it in several days.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ivmai150.diff
Type: application/octet-stream
Size: 7248 bytes
Desc: not available
Url : https://napali.hpl.hp.com/pipermail/gc/attachments/20090920/b8b3341e/ivmai150.obj

More information about the Gc mailing list