confd: dagger: Reduce memory usage

When reconfiguring the system many times (seen during regression
testing), the RAM usage of keeping all generations around starts to
add up.

A tmpfs file, no matter how small, will always consume at least one
full page (4k). So one generation of tiny setup scripts and log files
can end up locking a 1 MB (!) of memory.

Therefore: Once we're done with a generation, archive it in a
compressed tarball, which typically fits inside a single 4k
page. Limit the total number of archives to 10. This should give full
visibility into the history of a system in all normal situations,
while still allowing hammering systems with reconfig cycles in testing
scenarios.
This commit is contained in:
Tobias Waldekranz
2024-12-09 13:35:17 +01:00
parent 219c61081d
commit c076f0a770
2 changed files with 35 additions and 1 deletions
+23 -1
View File
@@ -104,7 +104,9 @@ do_abandon()
[ "$next" ] && [ -d "$basedir/$next" ] \
|| abort "Next generation does not exist"
mv "$basedir/$next" "$basedir/$next-ABANDONED-$(date +%F-%T)"
tar caf "$basedir/$next-ABANDONED-$(date +%F-%t).tar.gz" "$basedir/$next"
rm -rf "$basedir/$next"
rm "$basedir/next"
inform info "Abandoned generation $next"
}
@@ -128,6 +130,19 @@ do_evolve()
mv "$basedir/next" "$basedir/current"
inform info "Evolved to generation $next"
if [ "$current" ]; then
(cd "$basedir" && tar caf "$current.tar.gz" "$current")
rm -rf "$basedir/$current"
fi
}
do_prune()
{
local keep=${1:-10}
cd "$basedir"
rm -f old=$(ls -rv *.tar.gz | tail "+$((keep + 1))")
}
usage()
@@ -158,6 +173,10 @@ Commands:
exec <action>
Run the specified action of the current generation.
prune [<num-generations>]
Remove all but the last <num-generations>, or 10 by default,
archived generations.
help
Show this message.
@@ -201,6 +220,9 @@ case $cmd in
"exec")
do_exec "$@"
;;
"prune")
do_prune "$@"
;;
*)
usage && exit 1
+12
View File
@@ -114,11 +114,23 @@ int dagger_evolve(struct dagger *d)
return exitcode;
}
static int dagger_prune(struct dagger *d)
{
int exitcode;
exitcode = systemf("dagger -C %s prune", d->path);
DEBUG("dagger(%d->%d): prune: exitcode=%d\n",
d->current, d->next, exitcode);
return exitcode;
}
int dagger_evolve_or_abandon(struct dagger *d)
{
int exitcode, err;
exitcode = dagger_evolve(d);
dagger_prune(d);
if (!exitcode)
return 0;