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
This commit is contained in:
Dmitry Chagin 2022-03-31 21:04:44 +03:00
parent d5dc757e84
commit b7df7b987e
4 changed files with 36 additions and 0 deletions

View File

@ -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>
@ -1932,6 +1934,32 @@ linprocfs_doauxv(PFS_FILL_ARGS)
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 @@ 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);

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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