8 karma · joined Jan 4, 2018 (8y ago) · 4 submissions
comment 4y ago · link · parent
comment 4y ago · link · parent
This is my pet peeve when using linux as desktop. Does anyone know if this can be disabled entirely? Something like mlockall(MCL_ONFAULT) but for all the processes. I wish there was a knob for this (e.g. vm.swappiness=-1) but I haven't found one. :(
On my desktop the most common problem I have is that I have a runaway binary or a runaway chrome tab. 90% I simply want that killed so swap is not being helpful. Unfortunately it takes ages for the OOM killer to activate. I have indicators for how much free memory I have left, and I can manage accordingly. I'd prefer a snappier desktop than pretending I have infinite memory. If I feel I have too little memory, I can just buy more, but that still doesn't protect against linux locking up if you accidentally use up everything.
Here's a simple repro:
// gcc -std=c99 -Wall -Wextra -Werror -g -o eatmem eatmem.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char** argv)
{
int limit = 123456789;
if (argc >= 2) limit = atoi(argv[1]);
setbuf(stdout, NULL);
for (int i = 1; i <= limit; i++) {
memset(malloc(1 << 20), 1, 1 << 20);
printf("\rAllocated %5d MiB.", i);
}
sleep(10000);
return 0;
}
And here is how you use it: $ gcc -std=c99 -Wall -Wextra -Werror -g -o eatmem eatmem.c
$ ./eatmem
Allocated 31118 MiB.Killed
$ ./eatmem 31110
Allocated 31110 MiB.
Without args it keeps allocating RAM until the kernel kills it. Basically it tells you how much free ram you have. The second time you ask it to allocate a little less to create a near-oom condition on your machine.This pretty much locks up my machine (e.g. the mouse pointer doesn't budge) and I have to invoke the kernel OOM killer to recover (Alt+SysRQ+f). I don't use swap. If I could somehow disable the file paging then I could avoid this problem. (I really don't care how "efficient" file paging is, I want a snappy system instead!)
comment 8y ago · link · parent
What I really want is to have an always responsive system. You cannot get this easily on linux because it doesn't allow to disable all paging (executable pages are still paged out even with swap disabled). This means you can easily lock up your machine if you use a lot of memory (even without swap -- I don't use swap). The above post contains a 20 line C program example that will break your system that you can only cure by applying the oom killer. I mean what other options do you have you have 0 free memory? Could a kernel hacker reading this add such an option to linux to a poor sysadmin like myself?