From 8bc0ad2e099b348db6a1e100ea774545d6087c1b Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 7 Jan 2025 09:13:31 -0800 Subject: vmon: introduce -L,--mem-locked flag This can be necessary for headless mode on cramped embedded devices to prevent vmon from being delayed excessively due to page faults/thrashing. Even with Adherence visually indicated, it complicates comparisons across snapshots to have this be inconsistent/thrashing-severity-dependent. Use this flag in combination with something like SCHED_RR to make vmon more immune to memory and scheduling contention. If you use SCHED_RR, it's wise to also use LimitRTTIME to prevent potential bugs from bogarting the system. --- src/vmon.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/vmon.c b/src/vmon.c index 93855e8..e49b360 100644 --- a/src/vmon.c +++ b/src/vmon.c @@ -17,11 +17,13 @@ */ #include +#include #include #include #include #include #include +#include #include #include #include @@ -46,6 +48,7 @@ typedef struct vmon_t { int done; int linger; int dump_procs; + int mem_locked; time_t start_time; int snapshots_interval; int snapshot; @@ -201,6 +204,7 @@ static void print_help(void) " -w --wip-name Name to use for work-in-progress snapshot filename\n" " -v --version Print version\n" " -D --dump-procs Dump libvmon internal processes table (debugging aid)\n" + " -L --mem-locked Lock in memory using mlockall(MCL_CURRENT|MCL_FUTURE)\n" " -W --width Chart width\n" " -z --hertz Sample rate in hertz\n" "-------------------------------------------------------------------------------" @@ -491,6 +495,9 @@ static int vmon_handle_argv(vmon_t *vmon, int argc, const char * const *argv) } else if (is_flag(*argv, "-D", "--dump-procs")) { vmon->dump_procs = 1; last = argv; + } else if (is_flag(*argv, "-L", "--mem-locked")) { + vmon->mem_locked = 1; + last = argv; } else if ((*argv)[0] == '-') { VWM_ERROR("Unrecognized argument: \"%s\", try --help\n", argv[0]); exit(EXIT_FAILURE); @@ -692,6 +699,13 @@ static vmon_t * vmon_startup(int argc, const char * const *argv) goto _err_win; } + if (vmon->mem_locked) { + if (mlockall(MCL_CURRENT|MCL_FUTURE) < 0) { + VWM_ERROR("unable to lock in memory: %s", strerror(errno)); + goto _err_win; + } + } + return vmon; _err_win: -- cgit v1.2.3