* Allow the size of the GC reserved file to be specified in nix.conf

through the new `gc-reserved-space' option.
This commit is contained in:
Eelco Dolstra 2006-02-16 13:58:10 +00:00
parent 651ab439cf
commit 345a95afe9
5 changed files with 62 additions and 14 deletions

View file

@ -52,6 +52,26 @@ env-keep-derivations = false
</varlistentry> </varlistentry>
<varlistentry id="conf-gc-reserved-space"><term><literal>gc-reserved-space</literal></term>
<listitem><para>This option specifies how much space should be
reserved in normal use so that the garbage collector can run
succesfully. Since the garbage collector must perform Berkeley DB
transactions, it needs some disk space for itself. However, when
the disk is full, this space is not available, so the collector
would not be able to run precisely when it is most needed.</para>
<para>For this reason, when Nix is run, it allocates a file
<filename>/nix/var/nix/db/reserved</filename> of the size
specified by this option. When the garbage collector is run, this
file is deleted before the Berkeley DB environment is opened.
This should give it enough room to proceed.</para>
<para>The default is <literal>1048576</literal> (1
MiB).</para></listitem>
</varlistentry>
<varlistentry><term><literal>env-keep-derivations</literal></term> <varlistentry><term><literal>env-keep-derivations</literal></term>
<listitem><para>If <literal>false</literal> (default), derivations <listitem><para>If <literal>false</literal> (default), derivations

View file

@ -11,7 +11,7 @@
# build time (e.g., the C compiler, or source tarballs downloaded from # build time (e.g., the C compiler, or source tarballs downloaded from
# the network). To prevent it from doing so, set this option to # the network). To prevent it from doing so, set this option to
# `true'. # `true'.
gc-keep-outputs = false #gc-keep-outputs = false
### Option `gc-keep-derivations' ### Option `gc-keep-derivations'
@ -26,7 +26,26 @@ gc-keep-outputs = false
# store path was built), so by default this option is on. Turn it off # store path was built), so by default this option is on. Turn it off
# to safe a bit of disk space (or a lot if `gc-keep-outputs' is also # to safe a bit of disk space (or a lot if `gc-keep-outputs' is also
# turned on). # turned on).
gc-keep-derivations = true #gc-keep-derivations = true
### Option `gc-reserved-space'
#
# This option specifies how much space should be reserved in normal
# use so that the garbage collector can run succesfully. Since the
# garbage collector must perform Berkeley DB transactions, it needs
# some disk space for itself. However, when the disk is full, this
# space is not available, so the collector would not be able to run
# precisely when it is most needed.
#
# For this reason, when Nix is run, it allocates a file
# /nix/var/nix/db/reserved of the size specified by this option. When
# the garbage collector is run, this file is deleted before the
# Berkeley DB environment is opened. This should give it enough room
# to proceed.
#
# The default is "1048576" (1 MiB).
#gc-reserved-space = 1048576
### Option `env-keep-derivations' ### Option `env-keep-derivations'
@ -46,7 +65,7 @@ gc-keep-derivations = true
# this one is `sticky': it applies to any user environment created # this one is `sticky': it applies to any user environment created
# while this option was enabled, while `gc-keep-derivations' only # while this option was enabled, while `gc-keep-derivations' only
# applies at the moment the garbage collector is run. # applies at the moment the garbage collector is run.
env-keep-derivations = false #env-keep-derivations = false
### Option `build-allow-root' ### Option `build-allow-root'
@ -56,7 +75,7 @@ env-keep-derivations = false
# performed under the `root' user. If `false', builds are performed # performed under the `root' user. If `false', builds are performed
# under one of the users listed in the `build-users' option (see # under one of the users listed in the `build-users' option (see
# below). # below).
build-allow-root = true #build-allow-root = true
### Option `build-users' ### Option `build-users'
@ -77,4 +96,4 @@ build-allow-root = true
# #
# Example: # Example:
# build-users = nix-builder-1 nix-builder-2 nix-builder-3 # build-users = nix-builder-1 nix-builder-2 nix-builder-3
build-users = #build-users =

View file

@ -75,17 +75,22 @@ Strings querySetting(const string & name, const Strings & def)
} }
bool queryBoolSetting(const string & name, bool def) string querySetting(const string & name, const string & def)
{ {
Strings defs; Strings defs;
if (def) defs.push_back("true"); else defs.push_back("false"); defs.push_back(def);
Strings value = querySetting(name, defs); Strings value = querySetting(name, defs);
if (value.size() != 1) if (value.size() != 1)
throw Error(format("configuration option `%1%' should be either `true' or `false', not a list") throw Error(format("configuration option `%1%' should not be a list") % name);
% name);
return value.front();
string v = value.front(); }
bool queryBoolSetting(const string & name, bool def)
{
string v = querySetting(name, def ? "true" : "false");
if (v == "true") return true; if (v == "true") return true;
else if (v == "false") return false; else if (v == "false") return false;
else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'") else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'")

View file

@ -56,6 +56,8 @@ extern bool readOnlyMode;
Strings querySetting(const string & name, const Strings & def); Strings querySetting(const string & name, const Strings & def);
string querySetting(const string & name, const string & def);
bool queryBoolSetting(const string & name, bool def); bool queryBoolSetting(const string & name, bool def);

View file

@ -82,12 +82,14 @@ void openDB(bool reserveSpace)
try { try {
Path reservedPath = nixDBPath + "/reserved"; Path reservedPath = nixDBPath + "/reserved";
off_t reservedSize = 1024 * 1024; string s = querySetting("gc-reserved-space", "");
int reservedSize;
if (!string2Int(s, reservedSize)) reservedSize = 1024 * 1024;
if (reserveSpace) { if (reserveSpace) {
struct stat st; struct stat st;
if (stat(reservedPath.c_str(), &st) == -1 || if (stat(reservedPath.c_str(), &st) == -1 ||
st.st_size != reservedSize) st.st_size != reservedSize)
writeFile(reservedPath, string(1024 * 1024, 'X')); writeFile(reservedPath, string(reservedSize, 'X'));
} }
else else
deletePath(reservedPath); deletePath(reservedPath);