Better HN
topnewbestaskshowjobs
Log inSign up

ypsu

8 karma · joined Jan 4, 2018 (8y ago) · 4 submissions

Submissions

comment 4y ago · link · parent

I'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.

comment 4y ago · link · parent

Thanks, 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.

comment 4y ago · link · parent

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

comment 8y ago · link · parent

I see a few people complaining about oom killing. Allow me to make a case for it. I think oom killing is a very pragmatic solution to deal with low memory. Without overcommit you don't need the oom killer. But just simply disabling overcommit will make your system unusable during low memory situation just as much. Imagine that one job ate all your memory. How do you restore your system? You cannot allocate more memory so you can no longer start up a new shell to kill the bad process. So you are just as stuck with an unusable system. I wrote about this here: https://superuser.com/a/984715

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?