[PATCH] daemon: Sacrifice builders on OOM.

  • Open
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • Tobias Geerinckx-Rice
Owner
unassigned
Submitted by
Tobias Geerinckx-Rice
Severity
normal
T
T
Tobias Geerinckx-Rice wrote on 3 Dec 2023 01:00
(address . guix-patches@gnu.org)
20231203000032.29995-1-me@tobias.gr
* nix/libstore/build.cc (DerivationGoal::runChild):
Maximise our OOM score adjustment.

Change-Id: I418c763b499ca16e1ffe3c6033319112b9744f51
---
nix/libstore/build.cc | 6 ++++++
1 file changed, 6 insertions(+)

Toggle diff (19 lines)
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index e8259aa4e8..9241418abc 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -2154,6 +2154,12 @@ void DerivationGoal::runChild()
determinism. */
int cur = personality(0xffffffff);
if (cur != -1) personality(cur | ADDR_NO_RANDOMIZE);
+
+ /* Ask the kernel to eagerly kill us & our children if it runs out of
+ memory, regardless of blame, to preserve ‘real’ user data & state. */
+ try {
+ writeFile("/proc/self/oom_score_adj", "1000"); // 100%
+ } catch (...) { ignoreException(); }
#endif
/* Fill in the environment. */
--
2.41.0
T
T
Tobias Geerinckx-Rice wrote on 3 Dec 2023 01:00
[PATCH v2] daemon: Sacrifice builders on OOM.
(address . 67733@debbugs.gnu.org)
20231203000124.30383-1-me@tobias.gr
* nix/libstore/build.cc (DerivationGoal::runChild):
Maximise our OOM score adjustment.

Change-Id: I418c763b499ca16e1ffe3c6033319112b9744f51
---

v2: Tabs tabs tabs tabs.

nix/libstore/build.cc | 6 ++++++
1 file changed, 6 insertions(+)

Toggle diff (21 lines)
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index e8259aa4e8..54555b92d7 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -2154,6 +2154,12 @@ void DerivationGoal::runChild()
determinism. */
int cur = personality(0xffffffff);
if (cur != -1) personality(cur | ADDR_NO_RANDOMIZE);
+
+ /* Ask the kernel to eagerly kill us & our children if it runs out of
+ memory, regardless of blame, to preserve ‘real’ user data & state. */
+ try {
+ writeFile("/proc/self/oom_score_adj", "1000"); // 100%
+ } catch (...) { ignoreException(); }
#endif
/* Fill in the environment. */

base-commit: e796c68025aca372ff8e16eb0c235155af92f743
--
2.41.0
T
T
Tobias Geerinckx-Rice wrote on 3 Dec 2023 01:00
[PATCH v3] daemon: Sacrifice builders on OOM.
(address . 67733@debbugs.gnu.org)
20231203000111.30681-1-me@tobias.gr
* nix/libstore/build.cc (DerivationGoal::runChild):
Maximise our OOM score adjustment.

Change-Id: I418c763b499ca16e1ffe3c6033319112b9744f51
---

v3: In my defens, I'm on a fone.

nix/libstore/build.cc | 6 ++++++
1 file changed, 6 insertions(+)

Toggle diff (21 lines)
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index e8259aa4e8..54555b92d7 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -2154,6 +2154,12 @@ void DerivationGoal::runChild()
determinism. */
int cur = personality(0xffffffff);
if (cur != -1) personality(cur | ADDR_NO_RANDOMIZE);
+
+ /* Ask the kernel to eagerly kill us & our children if it runs out of
+ memory, regardless of blame, to preserve ‘real’ user data & state. */
+ try {
+ writeFile("/proc/self/oom_score_adj", "1000"); // 100%
+ } catch (...) { ignoreException(); }
#endif
/* Fill in the environment. */

base-commit: e796c68025aca372ff8e16eb0c235155af92f743
--
2.41.0
L
L
Ludovic Courtès wrote on 10 Dec 2023 22:51
(name . Tobias Geerinckx-Rice)(address . me@tobias.gr)(address . 67733@debbugs.gnu.org)
87h6kp3ewc.fsf@gnu.org
Hullo!

Tobias Geerinckx-Rice <me@tobias.gr> skribis:

Toggle quote (8 lines)
> * nix/libstore/build.cc (DerivationGoal::runChild):
> Maximise our OOM score adjustment.
>
> Change-Id: I418c763b499ca16e1ffe3c6033319112b9744f51
> ---
>
> v3: In my defens, I'm on a fone.

Nooo, you’re a hero.

Toggle quote (6 lines)
> + /* Ask the kernel to eagerly kill us & our children if it runs out of
> + memory, regardless of blame, to preserve ‘real’ user data & state. */
> + try {
> + writeFile("/proc/self/oom_score_adj", "1000"); // 100%
> + } catch (...) { ignoreException(); }

Sounds like a good idea. LGTM!

Ludo’.
?