Skip to content

Commit

Permalink
Add emerge --jobs-tmpdir-space-threshold option
Browse files Browse the repository at this point in the history
Bug: https://bugs.gentoo.org/934382
Signed-off-by: Zac Medico <[email protected]>
  • Loading branch information
zmedico committed Jun 16, 2024
1 parent 19e750b commit 9e29391
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
29 changes: 28 additions & 1 deletion lib/_emerge/Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ def __init__(
if max_jobs is None:
max_jobs = 1
self._set_max_jobs(max_jobs)

self._jobs_tmpdir_space_threshold = myopts.get("--jobs-tmpdir-space-threshold")

self._running_root = trees[trees._running_eroot]["root_config"]
self.edebug = 0
if settings.get("PORTAGE_DEBUG", "") == "1":
Expand Down Expand Up @@ -1573,7 +1576,10 @@ def _main_loop(self):
self._main_exit = self._event_loop.create_future()

if (
self._max_load is not None
(
self._max_load is not None
or self._jobs_tmpdir_space_threshold is not None
)
and self._loadavg_latency is not None
and (self._max_jobs is True or self._max_jobs > 1)
):
Expand Down Expand Up @@ -1792,6 +1798,27 @@ def _is_work_scheduled(self):
def _running_job_count(self):
return self._jobs

def _can_add_job(self):
if not super()._can_add_job():
return False

if self._jobs_tmpdir_space_threshold is not None and hasattr(os, "statvfs"):
try:
vfs_stat = os.statvfs(self.settings["PORTAGE_TMPDIR"])
except OSError as e:
writemsg_level(
f"!!! statvfs('{self.settings['PORTAGE_TMPDIR']}'): {e}\n",
noiselevel=-1,
level=logging.ERROR,
)
else:
if (
(vfs_stat.f_blocks - vfs_stat.f_bavail) / vfs_stat.f_blocks
) > self._jobs_tmpdir_space_threshold:
return False

return True

def _schedule_tasks(self):
while True:
state_change = 0
Expand Down
25 changes: 24 additions & 1 deletion lib/_emerge/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 1999-2023 Gentoo Authors
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

import argparse
Expand Down Expand Up @@ -165,6 +165,7 @@ def __contains__(self, s):
"--getbinpkgonly": y_or_n,
"--ignore-world": y_or_n,
"--jobs": valid_integers,
"--jobs-tmpdir-space-threshold": valid_floats,
"--keep-going": y_or_n,
"--load-average": valid_floats,
"--onlydeps-with-ideps": y_or_n,
Expand Down Expand Up @@ -523,6 +524,10 @@ def parse_opts(tmpcmdline, silent=False):
"help": "Specifies the number of packages to build " + "simultaneously.",
"action": "store",
},
"--jobs-tmpdir-space-threshold": {
"help": "Specifies maximum used space ratio when starting a new job.",
"action": "store",
},
"--keep-going": {
"help": "continue as much as possible after an error",
"choices": true_y_or_n,
Expand Down Expand Up @@ -1033,6 +1038,24 @@ def parse_opts(tmpcmdline, silent=False):

myoptions.jobs = jobs

if myoptions.jobs_tmpdir_space_threshold == "True":
myoptions.jobs_tmpdir_space_threshold = None

if myoptions.jobs_tmpdir_space_threshold:
try:
jobs_tmpdir_space_threshold = float(myoptions.jobs_tmpdir_space_threshold)
except ValueError:
jobs_tmpdir_space_threshold = 0.0

if jobs_tmpdir_space_threshold <= 0.0:
jobs_tmpdir_space_threshold = None
if not silent:
parser.error(
f"Invalid --jobs-tmpdir-space-threshold: '{myoptions.jobs_tmpdir_space_threshold}'\n"
)

myoptions.jobs_tmpdir_space_threshold = jobs_tmpdir_space_threshold

if myoptions.load_average == "True":
myoptions.load_average = None

Expand Down
7 changes: 6 additions & 1 deletion man/emerge.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "EMERGE" "1" "May 2024" "Portage @VERSION@" "Portage"
.TH "EMERGE" "1" "Jun 2024" "Portage @VERSION@" "Portage"
.SH "NAME"
emerge \- Command\-line interface to the Portage system
.SH "SYNOPSIS"
Expand Down Expand Up @@ -693,6 +693,11 @@ Note that interactive packages currently force a setting
of \fI\-\-jobs=1\fR. This issue can be temporarily avoided
by specifying \fI\-\-accept\-properties=\-interactive\fR.
.TP
.BR \-\-jobs\-tmpdir\-space\-threshold[=RATIO]
Specifies the maximum ratio of used space allowed (a floating\-point
number) in \fBPORTAGE_TMPDIR\fR when starting a new job. With no
argument, removes a previous space ratio threshold.
.TP
.BR "\-\-keep\-going [ y | n ]"
Continue as much as possible after an error. When an error occurs,
dependencies are recalculated for remaining packages and any with
Expand Down

0 comments on commit 9e29391

Please sign in to comment.