From e11e6fb1c6709ca3f0e596a7b1fb988df2fbd9b1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 28 Oct 2010 12:29:40 +0000 Subject: * Handle out of memory condition. --- src/libmain/Makefile.am | 2 +- src/libmain/shared.cc | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/libmain') diff --git a/src/libmain/Makefile.am b/src/libmain/Makefile.am index a9ee6604255e..1a2146e0448f 100644 --- a/src/libmain/Makefile.am +++ b/src/libmain/Makefile.am @@ -2,7 +2,7 @@ pkglib_LTLIBRARIES = libmain.la libmain_la_SOURCES = shared.cc -libmain_la_LIBADD = ../libstore/libstore.la +libmain_la_LIBADD = ../libstore/libstore.la @boehmgc_lib@ pkginclude_HEADERS = shared.hh diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index eddc4e64b3d7..440949bd2a0a 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -13,6 +13,10 @@ #include #include +#if HAVE_BOEHMGC +#include +#endif + namespace nix { @@ -314,6 +318,14 @@ static void setuidInit() } +/* Called when the Boehm GC runs out of memory. */ +static void * oomHandler(size_t requested) +{ + /* Convert this to a proper C++ exception. */ + throw std::bad_alloc(); +} + + } @@ -335,6 +347,14 @@ int main(int argc, char * * argv) std::ios::sync_with_stdio(false); +#if HAVE_BOEHMGC + /* Initialise the Boehm garbage collector. This isn't necessary + on most platforms, but for portability we do it anyway. */ + GC_INIT(); + + GC_oom_fn = oomHandler; +#endif + try { try { initAndRun(argc, argv); -- cgit 1.4.1 From 14fbf85380b23efcc19c8479b65336fc7275d90b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 29 Oct 2010 13:11:50 +0000 Subject: * Set libgc's initial heap size to 384 MiB to prevent garbage collection in most cases (and therefore its performance overhead). --- src/libmain/shared.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/libmain') diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 440949bd2a0a..82309544a62d 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -353,6 +353,18 @@ int main(int argc, char * * argv) GC_INIT(); GC_oom_fn = oomHandler; + + /* Set the initial heap size to something fairly big (384 MiB) so + that in most cases we don't need to garbage collect at all. + (Collection has a fairly significant overhead, some.) The heap + size can be overriden through libgc's GC_INITIAL_HEAP_SIZE + environment variable. We should probably also provide a + nix.conf setting for this. Note that GC_expand_hp() causes a + lot of virtual, but not physical (resident) memory to be + allocated. This might be a problem on systems that don't + overcommit. */ + if (!getenv("GC_INITIAL_HEAP_SIZE")) + GC_expand_hp(384000000); #endif try { -- cgit 1.4.1 From 26def5392f6f6364aa0939a2d4fc7705e786d38d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 29 Oct 2010 14:44:02 +0000 Subject: * Document Boehm GC support. --- doc/manual/env-common.xml | 11 +++++++++++ doc/manual/installation.xml | 7 +++++++ doc/manual/release-notes.xml | 21 +++++++++++++++++++++ src/libmain/shared.cc | 2 +- 4 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src/libmain') diff --git a/doc/manual/env-common.xml b/doc/manual/env-common.xml index d67ef714d0f9..99acc5949044 100644 --- a/doc/manual/env-common.xml +++ b/doc/manual/env-common.xml @@ -271,6 +271,17 @@ $ mount -o bind /mnt/otherdisk/nix /nix + +GC_INITIAL_HEAP_SIZE + + If Nix has been configured to use the Boehm garbage + collector, this variable sets the initial size of the heap in bytes. + It defaults to 384 MiB. Setting it to a low value reduces memory + consumption, but will increase runtime due to the overhead of + garbage collection. + + + diff --git a/doc/manual/installation.xml b/doc/manual/installation.xml index bc5e21f0d39a..87a6c446a2d5 100644 --- a/doc/manual/installation.xml +++ b/doc/manual/installation.xml @@ -105,6 +105,13 @@ this packages. Alternatively, if you already have it installed, you can use configure's options to point to their respective locations. +Nix can optionally use the Boehm +garbage collector to reduce the evaluator’s memory consumption. +To enable it, install pkgconfig and the Boehm +garbage collector, and pass the flag to +configure. + diff --git a/doc/manual/release-notes.xml b/doc/manual/release-notes.xml index 5b1c30bf8292..1e579a37b017 100644 --- a/doc/manual/release-notes.xml +++ b/doc/manual/release-notes.xml @@ -6,6 +6,27 @@ + + +
Release 1.0 (TBA) + +This release has the following improvements: + + + + + Nix can now optionally use the Boehm garbage collector. + This significantly reduces the Nix evaluator’s memory footprint, + especially when evaluating large NixOS system configurations. It + can be enabled using the configure + option. + + + + +
+ +
Release 0.16 (August 17, 2010) diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 82309544a62d..29fc13e33627 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -364,7 +364,7 @@ int main(int argc, char * * argv) allocated. This might be a problem on systems that don't overcommit. */ if (!getenv("GC_INITIAL_HEAP_SIZE")) - GC_expand_hp(384000000); + GC_expand_hp(384 * 1024 * 1024); #endif try { -- cgit 1.4.1