diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -80,6 +80,7 @@ #include #include #include +#include #include #include @@ -104,6 +105,7 @@ #endif /* __i386__ || __amd64__ */ #include +#include #include #include #include @@ -1932,6 +1934,32 @@ return (error); } +/* + * 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 */ @@ -2018,6 +2046,8 @@ 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//task/... */ dir = pfs_create_dir(dir, "task", linprocfs_dotaskattr, NULL, NULL, 0); diff --git a/sys/compat/linux/linux_emul.h b/sys/compat/linux/linux_emul.h --- a/sys/compat/linux/linux_emul.h +++ b/sys/compat/linux/linux_emul.h @@ -75,6 +75,7 @@ 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_emul.c b/sys/compat/linux/linux_emul.c --- a/sys/compat/linux/linux_emul.c +++ b/sys/compat/linux/linux_emul.c @@ -187,6 +187,7 @@ 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_misc.h b/sys/compat/linux/linux_misc.h --- a/sys/compat/linux/linux_misc.h +++ b/sys/compat/linux/linux_misc.h @@ -157,6 +157,10 @@ /* 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