3 ms·
> Disabling swap does not prevent disk I/O from becoming a problem under memory contention, it simply shifts the disk I/O thrashing from anonymous pages to file
by ypsu 4y ago
> Disabling swap does not prevent disk I/O from becoming a problem under memory contention, it simply shifts the disk I/O thrashing from anonymous pages to file pages.
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!)
- zozbot234 4y ago> 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. :( Looks like the supported way of doing this is to use the vmtouch(8) utility to ensure that the files (or file pages) you care about are resident in RAM. There's also a fadvise utility, packaged within fcoretools, that seems to be similar.
- ypsu 4y agoI've looked into these in the past but I deemed them a too much of a hassle. I don't know what files I care about. The solution I'm proposing is simpler and doesn't require any daemons or figuring out the files I need.
- revertmean 4y agoInstall earlyoom. It's more aggressive than the default oom and you can tell it processes to prefer (so you can have it kill your browser, for example, rather than anything else). Your test program got killed both times without any slowdown on my machine.
- ypsu 4y agoThanks, I guess that could work. But still... I'd prefer a solution that doesn't require a daemon that has to continuously wake up and check for this. I wish for a cleaner solution. Besides, it doesn't fully solve my "snappiness" desire: it doesn't prevent the kernel from paging out pages. I guess the answer for that is to get faster disks but that can get tricky on my old raspberry pi machines.