James Ennis pushed to branch jennis/quota_declaration_fix at BuildStream / buildstream
Commits:
2 changed files:
Changes:
| ... | ... | @@ -937,15 +937,22 @@ class ArtifactCache(): | 
| 937 | 937 |                              "Invalid cache quota ({}): ".format(utils._pretty_size(cache_quota)) +
 | 
| 938 | 938 |                              "BuildStream requires a minimum cache quota of 2G.")
 | 
| 939 | 939 |          elif cache_quota > cache_size + available_space:  # Check maximum
 | 
| 940 | +            if '%' in self.context.config_cache_quota:
 | |
| 941 | +                available = (available_space / (stat.f_blocks * stat.f_bsize)) * 100
 | |
| 942 | +                available = '{}% of total disk space'.format(round(available,1))
 | |
| 943 | +            else:
 | |
| 944 | +                available = utils._pretty_size(available_space)
 | |
| 945 | + | |
| 940 | 946 |              raise LoadError(LoadErrorReason.INVALID_DATA,
 | 
| 941 | 947 |                              ("Your system does not have enough available " +
 | 
| 942 | 948 |                               "space to support the cache quota specified.\n" +
 | 
| 943 | -                             "You currently have:\n" +
 | |
| 944 | -                             "- {used} of cache in use at {local_cache_path}\n" +
 | |
| 945 | -                             "- {available} of available system storage").format(
 | |
| 946 | -                                 used=utils._pretty_size(cache_size),
 | |
| 947 | -                                 local_cache_path=self.context.artifactdir,
 | |
| 948 | -                                 available=utils._pretty_size(available_space)))
 | |
| 949 | +                             "\nYou have specified a quota of {quota} of total disk space.\n" +
 | |
| 950 | +                             "- The filesystem containing {local_cache_path} only " +
 | |
| 951 | +                             "has: {available_size} available.")
 | |
| 952 | +                            .format(
 | |
| 953 | +                                quota=self.context.config_cache_quota,
 | |
| 954 | +                                local_cache_path=self.context.artifactdir,
 | |
| 955 | +                                available_size=available))
 | |
| 949 | 956 |  | 
| 950 | 957 |          # Place a slight headroom (2e9 (2GB) on the cache_quota) into
 | 
| 951 | 958 |          # cache_quota to try and avoid exceptions.
 | 
| ... | ... | @@ -147,6 +147,44 @@ The default mirror is defined by its name, e.g. | 
| 147 | 147 |     ``--default-mirror`` command-line option.
 | 
| 148 | 148 |  | 
| 149 | 149 |  | 
| 150 | +Local cache expiry
 | |
| 151 | +~~~~~~~~~~~~~~~~~~
 | |
| 152 | +BuildStream locally caches artifacts, build trees, log files and sources within a
 | |
| 153 | +cache located at ``~/.cache/buildstream`` (unless a $XDG_CACHE_HOME environment
 | |
| 154 | +variable exists). When building large projects, this cache can get very large,
 | |
| 155 | +thus BuildStream will attempt to clean up the cache automatically by expiring the least
 | |
| 156 | +recently *used* artifacts.
 | |
| 157 | + | |
| 158 | +By default, cache expiry will begin once the file system which contains the cache
 | |
| 159 | +approaches maximum usage. However, it is also possible to impose a quota on the local
 | |
| 160 | +cache in the user configuration. This can be done in two ways:
 | |
| 161 | + | |
| 162 | +1. By restricting the maximum size of the cache directory itself.
 | |
| 163 | + | |
| 164 | +For example, to ensure that BuildStream's cache does not grow beyond 100 GB,
 | |
| 165 | +simply declare the following in your user configuration (``~/.config/buildstream.conf``):
 | |
| 166 | + | |
| 167 | +.. code:: yaml
 | |
| 168 | + | |
| 169 | +  cache:
 | |
| 170 | +    quota: 100G
 | |
| 171 | + | |
| 172 | +This quota defines the maximum size of the artifact cache in bytes.
 | |
| 173 | +Other accepted values are: K, M, G or T (or you can simply declare the value in bytes, without the suffix).
 | |
| 174 | +This uses the same format as systemd's
 | |
| 175 | +`resource-control <https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html>`_.
 | |
| 176 | + | |
| 177 | +2. By expiring artifacts once the file system which contains the cache exceeds a specified usage.
 | |
| 178 | + | |
| 179 | +To ensure that we start cleaning the cache once we've used 80% of local disk space (on the file system
 | |
| 180 | +which mounts the cache):
 | |
| 181 | + | |
| 182 | +.. code:: yaml
 | |
| 183 | + | |
| 184 | +  cache:
 | |
| 185 | +    quota: 80%
 | |
| 186 | + | |
| 187 | + | |
| 150 | 188 |  Default configuration
 | 
| 151 | 189 |  ---------------------
 | 
| 152 | 190 |  The default BuildStream configuration is specified here for reference:
 | 
