aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Chagin <dchagin@FreeBSD.org>2022-03-31 18:04:44 +0000
committerDmitry Chagin <dchagin@FreeBSD.org>2022-03-31 18:04:44 +0000
commitb7df7b987e8fac05006aa5f132c424e2b2bcf156 (patch)
treefb782ef4d6c5e65fbfb768622e94fd8d72aaffe4
parentd5dc757e84d8dc1db987f3a17052e32621d6ea87 (diff)
downloadsrc-b7df7b987e8fac05006aa5f132c424e2b2bcf156.tar.gz
src-b7df7b987e8fac05006aa5f132c424e2b2bcf156.zip
linprocfs: Add /proc/self/oom_score_adj.
To avoid annoyng messages from LTP test suites add the simple implementation of /proc/self/oom_score_adj which is do nothing. Reviewed by: emaste Differential revision: https://reviews.freebsd.org/D34710 MFC after: 2 weeks
-rw-r--r--sys/compat/linprocfs/linprocfs.c30
-rw-r--r--sys/compat/linux/linux_emul.c1
-rw-r--r--sys/compat/linux/linux_emul.h1
-rw-r--r--sys/compat/linux/linux_misc.h4
4 files changed, 36 insertions, 0 deletions
diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 6a1a680f622a..8a9525b4375d 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -80,6 +80,7 @@ __FBSDID("$FreeBSD$");
#include <sys/vmmeter.h>
#include <sys/vnode.h>
#include <sys/bus.h>
+#include <sys/uio.h>
#include <net/if.h>
#include <net/if_var.h>
@@ -104,6 +105,7 @@ __FBSDID("$FreeBSD$");
#endif /* __i386__ || __amd64__ */
#include <compat/linux/linux.h>
+#include <compat/linux/linux_emul.h>
#include <compat/linux/linux_mib.h>
#include <compat/linux/linux_misc.h>
#include <compat/linux/linux_util.h>
@@ -1933,6 +1935,32 @@ linprocfs_doauxv(PFS_FILL_ARGS)
}
/*
+ * Filler function for proc/self/oom_score_adj
+ */
+static int
+linprocfs_do_oom_score_adj(PFS_FILL_ARGS)
+{
+ struct linux_pemuldata *pem;
+ long oom;
+
+ pem = pem_find(p);
+ if (pem == NULL || uio == NULL)
+ return (EOPNOTSUPP);
+ if (uio->uio_rw == UIO_READ) {
+ sbuf_printf(sb, "%d\n", pem->oom_score_adj);
+ } else {
+ sbuf_trim(sb);
+ sbuf_finish(sb);
+ oom = strtol(sbuf_data(sb), NULL, 10);
+ if (oom < LINUX_OOM_SCORE_ADJ_MIN ||
+ oom > LINUX_OOM_SCORE_ADJ_MAX)
+ return (EINVAL);
+ pem->oom_score_adj = oom;
+ }
+ return (0);
+}
+
+/*
* Constructor
*/
static int
@@ -2018,6 +2046,8 @@ linprocfs_init(PFS_INIT_ARGS)
NULL, &procfs_candebug, NULL, PFS_RD|PFS_RAWRD);
pfs_create_file(dir, "limits", &linprocfs_doproclimits,
NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(dir, "oom_score_adj", &linprocfs_do_oom_score_adj,
+ procfs_attr_rw, &procfs_candebug, NULL, PFS_RDWR);
/* /proc/<pid>/task/... */
dir = pfs_create_dir(dir, "task", linprocfs_dotaskattr, NULL, NULL, 0);
diff --git a/sys/compat/linux/linux_emul.c b/sys/compat/linux/linux_emul.c
index eb132d97db4a..12e078546ac6 100644
--- a/sys/compat/linux/linux_emul.c
+++ b/sys/compat/linux/linux_emul.c
@@ -187,6 +187,7 @@ linux_proc_init(struct thread *td, struct thread *newtd, bool init_thread)
pem = pem_find(p);
KASSERT(pem != NULL, ("proc_exit: proc emuldata not found.\n"));
pem->persona = 0;
+ pem->oom_score_adj = 0;
}
}
diff --git a/sys/compat/linux/linux_emul.h b/sys/compat/linux/linux_emul.h
index 70646cc93847..4e35da64606f 100644
--- a/sys/compat/linux/linux_emul.h
+++ b/sys/compat/linux/linux_emul.h
@@ -75,6 +75,7 @@ struct linux_pemuldata {
struct sx pem_sx; /* lock for this struct */
uint32_t persona; /* process execution domain */
uint32_t ptrace_flags; /* used by ptrace(2) */
+ uint32_t oom_score_adj; /* /proc/self/oom_score_adj */
};
#define LINUX_PEM_XLOCK(p) sx_xlock(&(p)->pem_sx)
diff --git a/sys/compat/linux/linux_misc.h b/sys/compat/linux/linux_misc.h
index a2dd5eb9f82b..0f134fc62e72 100644
--- a/sys/compat/linux/linux_misc.h
+++ b/sys/compat/linux/linux_misc.h
@@ -157,6 +157,10 @@ extern int stclohz;
/* Linux seccomp flags */
#define LINUX_SECCOMP_GET_ACTION_AVAIL 2
+/* Linux /proc/self/oom_score_adj */
+#define LINUX_OOM_SCORE_ADJ_MIN -1000
+#define LINUX_OOM_SCORE_ADJ_MAX 1000
+
#if defined(__aarch64__) || (defined(__amd64__) && !defined(COMPAT_LINUX32))
int linux_ptrace_status(struct thread *td, int pid, int status);
#endif