summaryrefslogtreecommitdiff
path: root/src/vmon.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2025-01-07 09:13:31 -0800
committerVito Caputo <vcaputo@pengaru.com>2025-01-07 09:13:31 -0800
commit8bc0ad2e099b348db6a1e100ea774545d6087c1b (patch)
tree3b85fe42dd57cd246caefc36ff6d9f7714cd6b4f /src/vmon.c
parentfabb3860947881b572204705d55eb8f59fa2e25a (diff)
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.
Diffstat (limited to 'src/vmon.c')
-rw-r--r--src/vmon.c14
1 files changed, 14 insertions, 0 deletions
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 <assert.h>
+#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/mman.h>
#include <sys/prctl.h>
#include <time.h>
#include <sys/stat.h>
@@ -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:
© All Rights Reserved