ref: 7a9e24c121eb4d2084d38bf55b767b99bb192bef
parent: c660119c2be0afecd22e6e533dd103173be8c361
author: Ori Bernstein <[email protected]>
date: Mon Dec 18 16:12:58 EST 2023
main: 'noswap' ourselves we don't want to get oomkilled, and swapping an fs to itself seems like a bad idea.
--- a/main.c
+++ b/main.c
@@ -28,6 +28,23 @@
Blk *blkbuf;
void **errctx;
+static void
+nokill(void)
+{
+ char buf[128];
+ int fd;
+
+ snprint(buf, sizeof(buf), "/proc/%d/ctl", getpid());
+ if((fd = open(buf, OWRITE)) == -1){
+ fprint(2, "nokill: open %s: %r", buf);
+ return;
+ }
+ if(fprint(fd, "noswap\n") == -1){
+ fprint(2, "nokill: write %s: %r", buf);
+ return;
+ }
+}
+
static uvlong
memsize(void)
{
@@ -162,6 +179,7 @@
if (pid < 0)
sysfatal("can't fork: %r");
if (pid == 0) {
+ nokill();
id = aincl(&fs->nworker, 1);
if((*errctx = mallocz(sizeof(Errctx), 1)) == nil)
sysfatal("malloc: %r");
@@ -342,6 +360,7 @@
}
rfork(RFNOTEG);
+ nokill();
loadfs(dev);
if(check && !checkfs(2))
sysfatal("fishy");