How to completely disable swap?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
27
down vote

favorite
13












I am using Debian sid, hard drive formatted with ext4, running on linux 3.1



I remember on previous linux versions (maybe before 3.0), if I run out of memory, and swap is not enabled, programs will usually crash. This is perfect for my environment: simple web browsing with no critical operations. That is, if I accidentally run across a bad website which uses up too much memory, it just crashes without rendering my terminal unusable.



But in my current setup, the computer hangs with violent I/O throughput in the background. iotop reveals kswapd0 to be the culprit, which means it is due to swapping. After using swapon -s to determine any swaps that were enabled, I used swapoff -a to disable all swaps and swapon -s again to confirm that all swaps were disabled.



Then I tried maximizing my memory usage again. Alas, the behavior I expected didn't happen. Instead, kswapd0 tries over and over to swap out the RAM and fails as there is no swap space. Because it never gives up, my computer is locked in eternal I/O heavy freeze, bad for my disk's health.



Am I doing something wrong in trying to swapoff -a? Why is the behavior different than what it used to be (probably pre-3.0 times)?










share|improve this question





















  • That doesn't really make sense. Doing the swapoff -a itself, if there was stuff in the swap, will generate a lot of I/O (and can result in processes getting killed if there is not enough real RAM availabe). Are you sure it's not the swapoff -a that caused the I/O "storm"?
    – Mat
    Nov 15 '11 at 11:40











  • I suppose it is enough to comment the fstab line about swap. Try if the behavior is the same.
    – enzotib
    Nov 15 '11 at 11:48










  • @Mat swapoff -a should disable swap permanently, meaning it should stay disabled after next reboot. I confirmed this. Yet, I/O "storm" still happens during the session after next reboot. For the record, I/O "storm" didn't happen at the moment I did swapoff -a because swap was 0 at that time.
    – syockit
    Nov 15 '11 at 11:48











  • @enzotib I have no swap in my fstab.
    – syockit
    Nov 15 '11 at 11:49






  • 9




    @syockit: swapoff -a is not permanent.
    – Mat
    Nov 15 '11 at 11:51














up vote
27
down vote

favorite
13












I am using Debian sid, hard drive formatted with ext4, running on linux 3.1



I remember on previous linux versions (maybe before 3.0), if I run out of memory, and swap is not enabled, programs will usually crash. This is perfect for my environment: simple web browsing with no critical operations. That is, if I accidentally run across a bad website which uses up too much memory, it just crashes without rendering my terminal unusable.



But in my current setup, the computer hangs with violent I/O throughput in the background. iotop reveals kswapd0 to be the culprit, which means it is due to swapping. After using swapon -s to determine any swaps that were enabled, I used swapoff -a to disable all swaps and swapon -s again to confirm that all swaps were disabled.



Then I tried maximizing my memory usage again. Alas, the behavior I expected didn't happen. Instead, kswapd0 tries over and over to swap out the RAM and fails as there is no swap space. Because it never gives up, my computer is locked in eternal I/O heavy freeze, bad for my disk's health.



Am I doing something wrong in trying to swapoff -a? Why is the behavior different than what it used to be (probably pre-3.0 times)?










share|improve this question





















  • That doesn't really make sense. Doing the swapoff -a itself, if there was stuff in the swap, will generate a lot of I/O (and can result in processes getting killed if there is not enough real RAM availabe). Are you sure it's not the swapoff -a that caused the I/O "storm"?
    – Mat
    Nov 15 '11 at 11:40











  • I suppose it is enough to comment the fstab line about swap. Try if the behavior is the same.
    – enzotib
    Nov 15 '11 at 11:48










  • @Mat swapoff -a should disable swap permanently, meaning it should stay disabled after next reboot. I confirmed this. Yet, I/O "storm" still happens during the session after next reboot. For the record, I/O "storm" didn't happen at the moment I did swapoff -a because swap was 0 at that time.
    – syockit
    Nov 15 '11 at 11:48











  • @enzotib I have no swap in my fstab.
    – syockit
    Nov 15 '11 at 11:49






  • 9




    @syockit: swapoff -a is not permanent.
    – Mat
    Nov 15 '11 at 11:51












up vote
27
down vote

favorite
13









up vote
27
down vote

favorite
13






13





I am using Debian sid, hard drive formatted with ext4, running on linux 3.1



I remember on previous linux versions (maybe before 3.0), if I run out of memory, and swap is not enabled, programs will usually crash. This is perfect for my environment: simple web browsing with no critical operations. That is, if I accidentally run across a bad website which uses up too much memory, it just crashes without rendering my terminal unusable.



But in my current setup, the computer hangs with violent I/O throughput in the background. iotop reveals kswapd0 to be the culprit, which means it is due to swapping. After using swapon -s to determine any swaps that were enabled, I used swapoff -a to disable all swaps and swapon -s again to confirm that all swaps were disabled.



Then I tried maximizing my memory usage again. Alas, the behavior I expected didn't happen. Instead, kswapd0 tries over and over to swap out the RAM and fails as there is no swap space. Because it never gives up, my computer is locked in eternal I/O heavy freeze, bad for my disk's health.



Am I doing something wrong in trying to swapoff -a? Why is the behavior different than what it used to be (probably pre-3.0 times)?










share|improve this question













I am using Debian sid, hard drive formatted with ext4, running on linux 3.1



I remember on previous linux versions (maybe before 3.0), if I run out of memory, and swap is not enabled, programs will usually crash. This is perfect for my environment: simple web browsing with no critical operations. That is, if I accidentally run across a bad website which uses up too much memory, it just crashes without rendering my terminal unusable.



But in my current setup, the computer hangs with violent I/O throughput in the background. iotop reveals kswapd0 to be the culprit, which means it is due to swapping. After using swapon -s to determine any swaps that were enabled, I used swapoff -a to disable all swaps and swapon -s again to confirm that all swaps were disabled.



Then I tried maximizing my memory usage again. Alas, the behavior I expected didn't happen. Instead, kswapd0 tries over and over to swap out the RAM and fails as there is no swap space. Because it never gives up, my computer is locked in eternal I/O heavy freeze, bad for my disk's health.



Am I doing something wrong in trying to swapoff -a? Why is the behavior different than what it used to be (probably pre-3.0 times)?







swap freeze






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '11 at 11:27









syockit

3841414




3841414











  • That doesn't really make sense. Doing the swapoff -a itself, if there was stuff in the swap, will generate a lot of I/O (and can result in processes getting killed if there is not enough real RAM availabe). Are you sure it's not the swapoff -a that caused the I/O "storm"?
    – Mat
    Nov 15 '11 at 11:40











  • I suppose it is enough to comment the fstab line about swap. Try if the behavior is the same.
    – enzotib
    Nov 15 '11 at 11:48










  • @Mat swapoff -a should disable swap permanently, meaning it should stay disabled after next reboot. I confirmed this. Yet, I/O "storm" still happens during the session after next reboot. For the record, I/O "storm" didn't happen at the moment I did swapoff -a because swap was 0 at that time.
    – syockit
    Nov 15 '11 at 11:48











  • @enzotib I have no swap in my fstab.
    – syockit
    Nov 15 '11 at 11:49






  • 9




    @syockit: swapoff -a is not permanent.
    – Mat
    Nov 15 '11 at 11:51
















  • That doesn't really make sense. Doing the swapoff -a itself, if there was stuff in the swap, will generate a lot of I/O (and can result in processes getting killed if there is not enough real RAM availabe). Are you sure it's not the swapoff -a that caused the I/O "storm"?
    – Mat
    Nov 15 '11 at 11:40











  • I suppose it is enough to comment the fstab line about swap. Try if the behavior is the same.
    – enzotib
    Nov 15 '11 at 11:48










  • @Mat swapoff -a should disable swap permanently, meaning it should stay disabled after next reboot. I confirmed this. Yet, I/O "storm" still happens during the session after next reboot. For the record, I/O "storm" didn't happen at the moment I did swapoff -a because swap was 0 at that time.
    – syockit
    Nov 15 '11 at 11:48











  • @enzotib I have no swap in my fstab.
    – syockit
    Nov 15 '11 at 11:49






  • 9




    @syockit: swapoff -a is not permanent.
    – Mat
    Nov 15 '11 at 11:51















That doesn't really make sense. Doing the swapoff -a itself, if there was stuff in the swap, will generate a lot of I/O (and can result in processes getting killed if there is not enough real RAM availabe). Are you sure it's not the swapoff -a that caused the I/O "storm"?
– Mat
Nov 15 '11 at 11:40





That doesn't really make sense. Doing the swapoff -a itself, if there was stuff in the swap, will generate a lot of I/O (and can result in processes getting killed if there is not enough real RAM availabe). Are you sure it's not the swapoff -a that caused the I/O "storm"?
– Mat
Nov 15 '11 at 11:40













I suppose it is enough to comment the fstab line about swap. Try if the behavior is the same.
– enzotib
Nov 15 '11 at 11:48




I suppose it is enough to comment the fstab line about swap. Try if the behavior is the same.
– enzotib
Nov 15 '11 at 11:48












@Mat swapoff -a should disable swap permanently, meaning it should stay disabled after next reboot. I confirmed this. Yet, I/O "storm" still happens during the session after next reboot. For the record, I/O "storm" didn't happen at the moment I did swapoff -a because swap was 0 at that time.
– syockit
Nov 15 '11 at 11:48





@Mat swapoff -a should disable swap permanently, meaning it should stay disabled after next reboot. I confirmed this. Yet, I/O "storm" still happens during the session after next reboot. For the record, I/O "storm" didn't happen at the moment I did swapoff -a because swap was 0 at that time.
– syockit
Nov 15 '11 at 11:48













@enzotib I have no swap in my fstab.
– syockit
Nov 15 '11 at 11:49




@enzotib I have no swap in my fstab.
– syockit
Nov 15 '11 at 11:49




9




9




@syockit: swapoff -a is not permanent.
– Mat
Nov 15 '11 at 11:51




@syockit: swapoff -a is not permanent.
– Mat
Nov 15 '11 at 11:51










6 Answers
6






active

oldest

votes

















up vote
14
down vote













A better solution than turning off swap, which will at best cause random processes to be killed when memory runs low, is to set the per process data segment limit for processes that pull stuff off the net. This way a runaway browser will hit the limit and die, rather than cause the whole system to become unusable. Example, from the shell



(ulimit -d 400000; firefox) &


The number after -d is in kilobytes. You should experiment with this on your system to choose the best value for your browsing habits. The parentheses cause a subshell to be created; the ulimit command only affects that shell and its children, isolating its effects from the parent shell.






share|improve this answer




















  • Will this work for chromium, say, where we have a bunch of chromium processes using small chunks of memory?
    – jberryman
    Jun 25 '15 at 16:37










  • @jberryman No, the memory limits are per-process rather than per-user.
    – Kyle Jones
    Jun 26 '15 at 14:36










  • Is there a way to send it a specified signal (e.g., SIGHUP) when it reaches the memory limit?
    – Geremia
    Feb 24 '17 at 16:16






  • 1




    @Geremia No. The brk and sbrk system calls stop working, which will make most things curl up and die.
    – Kyle Jones
    Feb 24 '17 at 16:23

















up vote
12
down vote













Disabling swap won't do what you want. You will still get violent I/O throughput, but it will be of clean pages rather than dirty ones.



With no swap, the system will compress the cache of clean (unmodified) pages to near zero, because those are the only pages it can evict from physical memory. It can only evict dirty (modified) pages from memory by writing them to swap, with no swap, it has no way to evict dirty pages.



As you run low on physical memory, each process will have to load its code pages from disk as it evicts the previous process code pages. The result will be violent thrashing and excessive work done by the swap subsystem.



This is a special case of a very important principle: For a well-designed system, you can't make it run better by reducing its choices. Linux is a well-designed system. Removing swap just gives it fewer choices, so it's not surprising that it behaves worse.






share|improve this answer
















  • 1




    Just short of all memory will pretty much always be allocated. Linux is specifically tuned this way. Do a cat /proc/meminfo on any typical Linux box after a few hours of load.
    – David Schwartz
    Nov 15 '11 at 18:43






  • 2




    @syockit If you disable paging, you can't run any programs. Paging is the mechanism by which files are read in when mapped into memory.
    – David Schwartz
    Nov 16 '11 at 16:39






  • 1




    @psusi : When you have no swap, clean pages are evicted from cache because dirty pages cannot be evicted fast enough (if at all). This is what causes the violent thrashing. Long before any processes are killed, the cache will be squeezed to near zero. This means everything that's not a dirty, anonymous page will be gone. That's what causes the thrashing -- the majority of code pages are not dirty, anonymous pages. So almost every code page faults.
    – David Schwartz
    Nov 26 '11 at 4:29






  • 2




    @psusi : Clean pages will not be reduced to a minimum when you have swap. It will instead swap out dirty, anonymous pages that haven't been recently used. Of course, either way you'll get violent thrashing eventually if the working set exceeds physical memory. The point is, with or without swap, you will get lots of violent thrashing before you actually run out of memory. The difference is, with swap the violent thrashing will be swapping (dirty pages, write and read). Without swap, the violent thrashing will be code faults (clean pages, read only).
    – David Schwartz
    Nov 28 '11 at 4:57







  • 2




    @psusi: You are correct if the concern is a runaway process that rapidly blows up in memory consumption. But that's not what the OP is talking about, which is a process that consumes excessive, but not unbounded or massively excessive, memory. As it grows through the large sweet spot (where the cache is squeezed) it will grow more and more slowly as the system thrashes.
    – David Schwartz
    Feb 2 '12 at 23:44

















up vote
4
down vote













To make sure that swap is not used, you'd be better off preventing any swap being added at boot. This can be done, depending on the system, by disabling the swap boot service or just commenting out the swap entry in /etc/fstab.



As far as your hangup is concerned, the stop() function in /etc/init.d/swap might give a clue:



stop()
OpenBSD) swapctl -U -t noblk >/dev/null;;
*) swapoff -a >/dev/null;;
esac
eend 0



Notice the part about deadlock. You can try doing umount -a -t tmpfs yourself before turning swap off.




Edit:



Probably, you might also achieve your goal by modifying sysctl settings (see this question).






share|improve this answer






















  • I don't have swap in init.d, nor do I have it on fstab, but I do have /etc/init.d/mountoverflowtmp that mounts tmpfs for emergency log writes. Does the swap daemon use tmpfs too?
    – syockit
    Nov 15 '11 at 11:58










  • You might have it enabled elsewhere - do grep -RF swap /etc/ if you wish to find it. But to disable a service, you'd use a command like service (IIRC; I don't use Debian myself).
    – rozcietrzewiacz
    Nov 15 '11 at 12:02






  • 1




    Swap itself does not use tmpfs, because tmpfs is an in-memory (RAM) filesystem. But other services/programs that use tmpfs might rely on swap in a special manner. I don't really know, but it might have something to do with caching or a special way in which tmpfs driver claims access to swap space.
    – rozcietrzewiacz
    Nov 15 '11 at 12:04











  • There's something about how Linux handles virtual memory that I don't understand. I've disabled swap in most ways possible: via swapoff, and via vm.swappiness=0. Yet kswapd0 still runs! I wonder if this is a regression from the 2.4 days…
    – syockit
    Nov 15 '11 at 15:36






  • 4




    @syockit It's expected behavior. The system is still swapping clean pages (pages that contain copies of file data). It requires no swap space to swap clean pages, since they can be read back from sources other than swap.
    – David Schwartz
    Nov 15 '11 at 16:58

















up vote
2
down vote













It is better to comment out swap partition entry in /etc/fstab than running swapoff -a after each boot.



I have the same issue with kswapd0 on my hardware.



Tuning vm.swappiness system parameter does not help for me.



sysctl -w vm.swappiness=0


I googled and read a lot of posts, mailing lists, and now I think that this is kernel bug.



When there is no active swap partition and free memory becomes less then some threshold (about 300MB in my case) the system becomes unresponsive due to kswapd0 madness.



Probably it is reproduced with special configuration and conditions.



For somebody it is solved by system re-installation with re-partitioning for others by building custom kernel with kswapd0 disabled.






share|improve this answer






















  • If kswapd0 goes mad and you don't have swap activated you're out of RAM. Your choices are OOM Killer or kswapd0. Linux goes with kswapd0 because the kernel assumes that it's more important to finish slowly than to abort the process. For casual humans, the threshold where kernel thinks that enough forward progress still does happen is already glacially slow and nearly anybody would rather select OOM Killer.
    – Mikko Rantalainen
    Aug 31 at 10:35

















up vote
0
down vote













On my system (debian sid 2016-11-15), I did this:




  1. disable the swap now:



    swapoff -a



  2. comment the line with swap partition in /etc/fstab



    #### #UUID=c6ddbc95-3bb5-49e1-ab25-b1c505e5360c none swap sw 0 0



  3. disable the mounting of swap in systemd:



    systemctl --type swap
    systemctl stop dev-sda6.swap
    systemctl mask dev-sda6.swap


It would be enought. There is reference of the swap in /etc/initramfs-tools/conf.d/resume file. I don't know what is the purpose of this. Maybe this file will be a problem on the next reboot (I don't try to reboot yet, my uptime is precious ;)).






share|improve this answer





























    up vote
    0
    down vote














    the computer hangs with violent I/O throughput in the background.
    iotop reveals kswapd0 to be the culprit




    I've found one way (so far) to avoid that. If you want to test it and see how it does on your system, see the kernel patch inside this question. Basically, it doesn't evict Active(file) pages (at least) when under memory pressure, thus the disk thrashing (constant reading) is reduced to almost nothing and OOM-killer is allowed to trigger within 1 second, instead of freezing the OS for what seems like permanently(or at least for many minutes). I am hoping that actual programmers(of which I'm not) would improve the patch and make it into an actual solution, now that they see that what it does is working for these situations.






    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f24625%2fhow-to-completely-disable-swap%23new-answer', 'question_page');

      );

      Post as a guest






























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      14
      down vote













      A better solution than turning off swap, which will at best cause random processes to be killed when memory runs low, is to set the per process data segment limit for processes that pull stuff off the net. This way a runaway browser will hit the limit and die, rather than cause the whole system to become unusable. Example, from the shell



      (ulimit -d 400000; firefox) &


      The number after -d is in kilobytes. You should experiment with this on your system to choose the best value for your browsing habits. The parentheses cause a subshell to be created; the ulimit command only affects that shell and its children, isolating its effects from the parent shell.






      share|improve this answer




















      • Will this work for chromium, say, where we have a bunch of chromium processes using small chunks of memory?
        – jberryman
        Jun 25 '15 at 16:37










      • @jberryman No, the memory limits are per-process rather than per-user.
        – Kyle Jones
        Jun 26 '15 at 14:36










      • Is there a way to send it a specified signal (e.g., SIGHUP) when it reaches the memory limit?
        – Geremia
        Feb 24 '17 at 16:16






      • 1




        @Geremia No. The brk and sbrk system calls stop working, which will make most things curl up and die.
        – Kyle Jones
        Feb 24 '17 at 16:23














      up vote
      14
      down vote













      A better solution than turning off swap, which will at best cause random processes to be killed when memory runs low, is to set the per process data segment limit for processes that pull stuff off the net. This way a runaway browser will hit the limit and die, rather than cause the whole system to become unusable. Example, from the shell



      (ulimit -d 400000; firefox) &


      The number after -d is in kilobytes. You should experiment with this on your system to choose the best value for your browsing habits. The parentheses cause a subshell to be created; the ulimit command only affects that shell and its children, isolating its effects from the parent shell.






      share|improve this answer




















      • Will this work for chromium, say, where we have a bunch of chromium processes using small chunks of memory?
        – jberryman
        Jun 25 '15 at 16:37










      • @jberryman No, the memory limits are per-process rather than per-user.
        – Kyle Jones
        Jun 26 '15 at 14:36










      • Is there a way to send it a specified signal (e.g., SIGHUP) when it reaches the memory limit?
        – Geremia
        Feb 24 '17 at 16:16






      • 1




        @Geremia No. The brk and sbrk system calls stop working, which will make most things curl up and die.
        – Kyle Jones
        Feb 24 '17 at 16:23












      up vote
      14
      down vote










      up vote
      14
      down vote









      A better solution than turning off swap, which will at best cause random processes to be killed when memory runs low, is to set the per process data segment limit for processes that pull stuff off the net. This way a runaway browser will hit the limit and die, rather than cause the whole system to become unusable. Example, from the shell



      (ulimit -d 400000; firefox) &


      The number after -d is in kilobytes. You should experiment with this on your system to choose the best value for your browsing habits. The parentheses cause a subshell to be created; the ulimit command only affects that shell and its children, isolating its effects from the parent shell.






      share|improve this answer












      A better solution than turning off swap, which will at best cause random processes to be killed when memory runs low, is to set the per process data segment limit for processes that pull stuff off the net. This way a runaway browser will hit the limit and die, rather than cause the whole system to become unusable. Example, from the shell



      (ulimit -d 400000; firefox) &


      The number after -d is in kilobytes. You should experiment with this on your system to choose the best value for your browsing habits. The parentheses cause a subshell to be created; the ulimit command only affects that shell and its children, isolating its effects from the parent shell.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Feb 1 '12 at 19:05









      Kyle Jones

      11.3k13048




      11.3k13048











      • Will this work for chromium, say, where we have a bunch of chromium processes using small chunks of memory?
        – jberryman
        Jun 25 '15 at 16:37










      • @jberryman No, the memory limits are per-process rather than per-user.
        – Kyle Jones
        Jun 26 '15 at 14:36










      • Is there a way to send it a specified signal (e.g., SIGHUP) when it reaches the memory limit?
        – Geremia
        Feb 24 '17 at 16:16






      • 1




        @Geremia No. The brk and sbrk system calls stop working, which will make most things curl up and die.
        – Kyle Jones
        Feb 24 '17 at 16:23
















      • Will this work for chromium, say, where we have a bunch of chromium processes using small chunks of memory?
        – jberryman
        Jun 25 '15 at 16:37










      • @jberryman No, the memory limits are per-process rather than per-user.
        – Kyle Jones
        Jun 26 '15 at 14:36










      • Is there a way to send it a specified signal (e.g., SIGHUP) when it reaches the memory limit?
        – Geremia
        Feb 24 '17 at 16:16






      • 1




        @Geremia No. The brk and sbrk system calls stop working, which will make most things curl up and die.
        – Kyle Jones
        Feb 24 '17 at 16:23















      Will this work for chromium, say, where we have a bunch of chromium processes using small chunks of memory?
      – jberryman
      Jun 25 '15 at 16:37




      Will this work for chromium, say, where we have a bunch of chromium processes using small chunks of memory?
      – jberryman
      Jun 25 '15 at 16:37












      @jberryman No, the memory limits are per-process rather than per-user.
      – Kyle Jones
      Jun 26 '15 at 14:36




      @jberryman No, the memory limits are per-process rather than per-user.
      – Kyle Jones
      Jun 26 '15 at 14:36












      Is there a way to send it a specified signal (e.g., SIGHUP) when it reaches the memory limit?
      – Geremia
      Feb 24 '17 at 16:16




      Is there a way to send it a specified signal (e.g., SIGHUP) when it reaches the memory limit?
      – Geremia
      Feb 24 '17 at 16:16




      1




      1




      @Geremia No. The brk and sbrk system calls stop working, which will make most things curl up and die.
      – Kyle Jones
      Feb 24 '17 at 16:23




      @Geremia No. The brk and sbrk system calls stop working, which will make most things curl up and die.
      – Kyle Jones
      Feb 24 '17 at 16:23












      up vote
      12
      down vote













      Disabling swap won't do what you want. You will still get violent I/O throughput, but it will be of clean pages rather than dirty ones.



      With no swap, the system will compress the cache of clean (unmodified) pages to near zero, because those are the only pages it can evict from physical memory. It can only evict dirty (modified) pages from memory by writing them to swap, with no swap, it has no way to evict dirty pages.



      As you run low on physical memory, each process will have to load its code pages from disk as it evicts the previous process code pages. The result will be violent thrashing and excessive work done by the swap subsystem.



      This is a special case of a very important principle: For a well-designed system, you can't make it run better by reducing its choices. Linux is a well-designed system. Removing swap just gives it fewer choices, so it's not surprising that it behaves worse.






      share|improve this answer
















      • 1




        Just short of all memory will pretty much always be allocated. Linux is specifically tuned this way. Do a cat /proc/meminfo on any typical Linux box after a few hours of load.
        – David Schwartz
        Nov 15 '11 at 18:43






      • 2




        @syockit If you disable paging, you can't run any programs. Paging is the mechanism by which files are read in when mapped into memory.
        – David Schwartz
        Nov 16 '11 at 16:39






      • 1




        @psusi : When you have no swap, clean pages are evicted from cache because dirty pages cannot be evicted fast enough (if at all). This is what causes the violent thrashing. Long before any processes are killed, the cache will be squeezed to near zero. This means everything that's not a dirty, anonymous page will be gone. That's what causes the thrashing -- the majority of code pages are not dirty, anonymous pages. So almost every code page faults.
        – David Schwartz
        Nov 26 '11 at 4:29






      • 2




        @psusi : Clean pages will not be reduced to a minimum when you have swap. It will instead swap out dirty, anonymous pages that haven't been recently used. Of course, either way you'll get violent thrashing eventually if the working set exceeds physical memory. The point is, with or without swap, you will get lots of violent thrashing before you actually run out of memory. The difference is, with swap the violent thrashing will be swapping (dirty pages, write and read). Without swap, the violent thrashing will be code faults (clean pages, read only).
        – David Schwartz
        Nov 28 '11 at 4:57







      • 2




        @psusi: You are correct if the concern is a runaway process that rapidly blows up in memory consumption. But that's not what the OP is talking about, which is a process that consumes excessive, but not unbounded or massively excessive, memory. As it grows through the large sweet spot (where the cache is squeezed) it will grow more and more slowly as the system thrashes.
        – David Schwartz
        Feb 2 '12 at 23:44














      up vote
      12
      down vote













      Disabling swap won't do what you want. You will still get violent I/O throughput, but it will be of clean pages rather than dirty ones.



      With no swap, the system will compress the cache of clean (unmodified) pages to near zero, because those are the only pages it can evict from physical memory. It can only evict dirty (modified) pages from memory by writing them to swap, with no swap, it has no way to evict dirty pages.



      As you run low on physical memory, each process will have to load its code pages from disk as it evicts the previous process code pages. The result will be violent thrashing and excessive work done by the swap subsystem.



      This is a special case of a very important principle: For a well-designed system, you can't make it run better by reducing its choices. Linux is a well-designed system. Removing swap just gives it fewer choices, so it's not surprising that it behaves worse.






      share|improve this answer
















      • 1




        Just short of all memory will pretty much always be allocated. Linux is specifically tuned this way. Do a cat /proc/meminfo on any typical Linux box after a few hours of load.
        – David Schwartz
        Nov 15 '11 at 18:43






      • 2




        @syockit If you disable paging, you can't run any programs. Paging is the mechanism by which files are read in when mapped into memory.
        – David Schwartz
        Nov 16 '11 at 16:39






      • 1




        @psusi : When you have no swap, clean pages are evicted from cache because dirty pages cannot be evicted fast enough (if at all). This is what causes the violent thrashing. Long before any processes are killed, the cache will be squeezed to near zero. This means everything that's not a dirty, anonymous page will be gone. That's what causes the thrashing -- the majority of code pages are not dirty, anonymous pages. So almost every code page faults.
        – David Schwartz
        Nov 26 '11 at 4:29






      • 2




        @psusi : Clean pages will not be reduced to a minimum when you have swap. It will instead swap out dirty, anonymous pages that haven't been recently used. Of course, either way you'll get violent thrashing eventually if the working set exceeds physical memory. The point is, with or without swap, you will get lots of violent thrashing before you actually run out of memory. The difference is, with swap the violent thrashing will be swapping (dirty pages, write and read). Without swap, the violent thrashing will be code faults (clean pages, read only).
        – David Schwartz
        Nov 28 '11 at 4:57







      • 2




        @psusi: You are correct if the concern is a runaway process that rapidly blows up in memory consumption. But that's not what the OP is talking about, which is a process that consumes excessive, but not unbounded or massively excessive, memory. As it grows through the large sweet spot (where the cache is squeezed) it will grow more and more slowly as the system thrashes.
        – David Schwartz
        Feb 2 '12 at 23:44












      up vote
      12
      down vote










      up vote
      12
      down vote









      Disabling swap won't do what you want. You will still get violent I/O throughput, but it will be of clean pages rather than dirty ones.



      With no swap, the system will compress the cache of clean (unmodified) pages to near zero, because those are the only pages it can evict from physical memory. It can only evict dirty (modified) pages from memory by writing them to swap, with no swap, it has no way to evict dirty pages.



      As you run low on physical memory, each process will have to load its code pages from disk as it evicts the previous process code pages. The result will be violent thrashing and excessive work done by the swap subsystem.



      This is a special case of a very important principle: For a well-designed system, you can't make it run better by reducing its choices. Linux is a well-designed system. Removing swap just gives it fewer choices, so it's not surprising that it behaves worse.






      share|improve this answer












      Disabling swap won't do what you want. You will still get violent I/O throughput, but it will be of clean pages rather than dirty ones.



      With no swap, the system will compress the cache of clean (unmodified) pages to near zero, because those are the only pages it can evict from physical memory. It can only evict dirty (modified) pages from memory by writing them to swap, with no swap, it has no way to evict dirty pages.



      As you run low on physical memory, each process will have to load its code pages from disk as it evicts the previous process code pages. The result will be violent thrashing and excessive work done by the swap subsystem.



      This is a special case of a very important principle: For a well-designed system, you can't make it run better by reducing its choices. Linux is a well-designed system. Removing swap just gives it fewer choices, so it's not surprising that it behaves worse.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 15 '11 at 16:57









      David Schwartz

      3,9001325




      3,9001325







      • 1




        Just short of all memory will pretty much always be allocated. Linux is specifically tuned this way. Do a cat /proc/meminfo on any typical Linux box after a few hours of load.
        – David Schwartz
        Nov 15 '11 at 18:43






      • 2




        @syockit If you disable paging, you can't run any programs. Paging is the mechanism by which files are read in when mapped into memory.
        – David Schwartz
        Nov 16 '11 at 16:39






      • 1




        @psusi : When you have no swap, clean pages are evicted from cache because dirty pages cannot be evicted fast enough (if at all). This is what causes the violent thrashing. Long before any processes are killed, the cache will be squeezed to near zero. This means everything that's not a dirty, anonymous page will be gone. That's what causes the thrashing -- the majority of code pages are not dirty, anonymous pages. So almost every code page faults.
        – David Schwartz
        Nov 26 '11 at 4:29






      • 2




        @psusi : Clean pages will not be reduced to a minimum when you have swap. It will instead swap out dirty, anonymous pages that haven't been recently used. Of course, either way you'll get violent thrashing eventually if the working set exceeds physical memory. The point is, with or without swap, you will get lots of violent thrashing before you actually run out of memory. The difference is, with swap the violent thrashing will be swapping (dirty pages, write and read). Without swap, the violent thrashing will be code faults (clean pages, read only).
        – David Schwartz
        Nov 28 '11 at 4:57







      • 2




        @psusi: You are correct if the concern is a runaway process that rapidly blows up in memory consumption. But that's not what the OP is talking about, which is a process that consumes excessive, but not unbounded or massively excessive, memory. As it grows through the large sweet spot (where the cache is squeezed) it will grow more and more slowly as the system thrashes.
        – David Schwartz
        Feb 2 '12 at 23:44












      • 1




        Just short of all memory will pretty much always be allocated. Linux is specifically tuned this way. Do a cat /proc/meminfo on any typical Linux box after a few hours of load.
        – David Schwartz
        Nov 15 '11 at 18:43






      • 2




        @syockit If you disable paging, you can't run any programs. Paging is the mechanism by which files are read in when mapped into memory.
        – David Schwartz
        Nov 16 '11 at 16:39






      • 1




        @psusi : When you have no swap, clean pages are evicted from cache because dirty pages cannot be evicted fast enough (if at all). This is what causes the violent thrashing. Long before any processes are killed, the cache will be squeezed to near zero. This means everything that's not a dirty, anonymous page will be gone. That's what causes the thrashing -- the majority of code pages are not dirty, anonymous pages. So almost every code page faults.
        – David Schwartz
        Nov 26 '11 at 4:29






      • 2




        @psusi : Clean pages will not be reduced to a minimum when you have swap. It will instead swap out dirty, anonymous pages that haven't been recently used. Of course, either way you'll get violent thrashing eventually if the working set exceeds physical memory. The point is, with or without swap, you will get lots of violent thrashing before you actually run out of memory. The difference is, with swap the violent thrashing will be swapping (dirty pages, write and read). Without swap, the violent thrashing will be code faults (clean pages, read only).
        – David Schwartz
        Nov 28 '11 at 4:57







      • 2




        @psusi: You are correct if the concern is a runaway process that rapidly blows up in memory consumption. But that's not what the OP is talking about, which is a process that consumes excessive, but not unbounded or massively excessive, memory. As it grows through the large sweet spot (where the cache is squeezed) it will grow more and more slowly as the system thrashes.
        – David Schwartz
        Feb 2 '12 at 23:44







      1




      1




      Just short of all memory will pretty much always be allocated. Linux is specifically tuned this way. Do a cat /proc/meminfo on any typical Linux box after a few hours of load.
      – David Schwartz
      Nov 15 '11 at 18:43




      Just short of all memory will pretty much always be allocated. Linux is specifically tuned this way. Do a cat /proc/meminfo on any typical Linux box after a few hours of load.
      – David Schwartz
      Nov 15 '11 at 18:43




      2




      2




      @syockit If you disable paging, you can't run any programs. Paging is the mechanism by which files are read in when mapped into memory.
      – David Schwartz
      Nov 16 '11 at 16:39




      @syockit If you disable paging, you can't run any programs. Paging is the mechanism by which files are read in when mapped into memory.
      – David Schwartz
      Nov 16 '11 at 16:39




      1




      1




      @psusi : When you have no swap, clean pages are evicted from cache because dirty pages cannot be evicted fast enough (if at all). This is what causes the violent thrashing. Long before any processes are killed, the cache will be squeezed to near zero. This means everything that's not a dirty, anonymous page will be gone. That's what causes the thrashing -- the majority of code pages are not dirty, anonymous pages. So almost every code page faults.
      – David Schwartz
      Nov 26 '11 at 4:29




      @psusi : When you have no swap, clean pages are evicted from cache because dirty pages cannot be evicted fast enough (if at all). This is what causes the violent thrashing. Long before any processes are killed, the cache will be squeezed to near zero. This means everything that's not a dirty, anonymous page will be gone. That's what causes the thrashing -- the majority of code pages are not dirty, anonymous pages. So almost every code page faults.
      – David Schwartz
      Nov 26 '11 at 4:29




      2




      2




      @psusi : Clean pages will not be reduced to a minimum when you have swap. It will instead swap out dirty, anonymous pages that haven't been recently used. Of course, either way you'll get violent thrashing eventually if the working set exceeds physical memory. The point is, with or without swap, you will get lots of violent thrashing before you actually run out of memory. The difference is, with swap the violent thrashing will be swapping (dirty pages, write and read). Without swap, the violent thrashing will be code faults (clean pages, read only).
      – David Schwartz
      Nov 28 '11 at 4:57





      @psusi : Clean pages will not be reduced to a minimum when you have swap. It will instead swap out dirty, anonymous pages that haven't been recently used. Of course, either way you'll get violent thrashing eventually if the working set exceeds physical memory. The point is, with or without swap, you will get lots of violent thrashing before you actually run out of memory. The difference is, with swap the violent thrashing will be swapping (dirty pages, write and read). Without swap, the violent thrashing will be code faults (clean pages, read only).
      – David Schwartz
      Nov 28 '11 at 4:57





      2




      2




      @psusi: You are correct if the concern is a runaway process that rapidly blows up in memory consumption. But that's not what the OP is talking about, which is a process that consumes excessive, but not unbounded or massively excessive, memory. As it grows through the large sweet spot (where the cache is squeezed) it will grow more and more slowly as the system thrashes.
      – David Schwartz
      Feb 2 '12 at 23:44




      @psusi: You are correct if the concern is a runaway process that rapidly blows up in memory consumption. But that's not what the OP is talking about, which is a process that consumes excessive, but not unbounded or massively excessive, memory. As it grows through the large sweet spot (where the cache is squeezed) it will grow more and more slowly as the system thrashes.
      – David Schwartz
      Feb 2 '12 at 23:44










      up vote
      4
      down vote













      To make sure that swap is not used, you'd be better off preventing any swap being added at boot. This can be done, depending on the system, by disabling the swap boot service or just commenting out the swap entry in /etc/fstab.



      As far as your hangup is concerned, the stop() function in /etc/init.d/swap might give a clue:



      stop()
      OpenBSD) swapctl -U -t noblk >/dev/null;;
      *) swapoff -a >/dev/null;;
      esac
      eend 0



      Notice the part about deadlock. You can try doing umount -a -t tmpfs yourself before turning swap off.




      Edit:



      Probably, you might also achieve your goal by modifying sysctl settings (see this question).






      share|improve this answer






















      • I don't have swap in init.d, nor do I have it on fstab, but I do have /etc/init.d/mountoverflowtmp that mounts tmpfs for emergency log writes. Does the swap daemon use tmpfs too?
        – syockit
        Nov 15 '11 at 11:58










      • You might have it enabled elsewhere - do grep -RF swap /etc/ if you wish to find it. But to disable a service, you'd use a command like service (IIRC; I don't use Debian myself).
        – rozcietrzewiacz
        Nov 15 '11 at 12:02






      • 1




        Swap itself does not use tmpfs, because tmpfs is an in-memory (RAM) filesystem. But other services/programs that use tmpfs might rely on swap in a special manner. I don't really know, but it might have something to do with caching or a special way in which tmpfs driver claims access to swap space.
        – rozcietrzewiacz
        Nov 15 '11 at 12:04











      • There's something about how Linux handles virtual memory that I don't understand. I've disabled swap in most ways possible: via swapoff, and via vm.swappiness=0. Yet kswapd0 still runs! I wonder if this is a regression from the 2.4 days…
        – syockit
        Nov 15 '11 at 15:36






      • 4




        @syockit It's expected behavior. The system is still swapping clean pages (pages that contain copies of file data). It requires no swap space to swap clean pages, since they can be read back from sources other than swap.
        – David Schwartz
        Nov 15 '11 at 16:58














      up vote
      4
      down vote













      To make sure that swap is not used, you'd be better off preventing any swap being added at boot. This can be done, depending on the system, by disabling the swap boot service or just commenting out the swap entry in /etc/fstab.



      As far as your hangup is concerned, the stop() function in /etc/init.d/swap might give a clue:



      stop()
      OpenBSD) swapctl -U -t noblk >/dev/null;;
      *) swapoff -a >/dev/null;;
      esac
      eend 0



      Notice the part about deadlock. You can try doing umount -a -t tmpfs yourself before turning swap off.




      Edit:



      Probably, you might also achieve your goal by modifying sysctl settings (see this question).






      share|improve this answer






















      • I don't have swap in init.d, nor do I have it on fstab, but I do have /etc/init.d/mountoverflowtmp that mounts tmpfs for emergency log writes. Does the swap daemon use tmpfs too?
        – syockit
        Nov 15 '11 at 11:58










      • You might have it enabled elsewhere - do grep -RF swap /etc/ if you wish to find it. But to disable a service, you'd use a command like service (IIRC; I don't use Debian myself).
        – rozcietrzewiacz
        Nov 15 '11 at 12:02






      • 1




        Swap itself does not use tmpfs, because tmpfs is an in-memory (RAM) filesystem. But other services/programs that use tmpfs might rely on swap in a special manner. I don't really know, but it might have something to do with caching or a special way in which tmpfs driver claims access to swap space.
        – rozcietrzewiacz
        Nov 15 '11 at 12:04











      • There's something about how Linux handles virtual memory that I don't understand. I've disabled swap in most ways possible: via swapoff, and via vm.swappiness=0. Yet kswapd0 still runs! I wonder if this is a regression from the 2.4 days…
        – syockit
        Nov 15 '11 at 15:36






      • 4




        @syockit It's expected behavior. The system is still swapping clean pages (pages that contain copies of file data). It requires no swap space to swap clean pages, since they can be read back from sources other than swap.
        – David Schwartz
        Nov 15 '11 at 16:58












      up vote
      4
      down vote










      up vote
      4
      down vote









      To make sure that swap is not used, you'd be better off preventing any swap being added at boot. This can be done, depending on the system, by disabling the swap boot service or just commenting out the swap entry in /etc/fstab.



      As far as your hangup is concerned, the stop() function in /etc/init.d/swap might give a clue:



      stop()
      OpenBSD) swapctl -U -t noblk >/dev/null;;
      *) swapoff -a >/dev/null;;
      esac
      eend 0



      Notice the part about deadlock. You can try doing umount -a -t tmpfs yourself before turning swap off.




      Edit:



      Probably, you might also achieve your goal by modifying sysctl settings (see this question).






      share|improve this answer














      To make sure that swap is not used, you'd be better off preventing any swap being added at boot. This can be done, depending on the system, by disabling the swap boot service or just commenting out the swap entry in /etc/fstab.



      As far as your hangup is concerned, the stop() function in /etc/init.d/swap might give a clue:



      stop()
      OpenBSD) swapctl -U -t noblk >/dev/null;;
      *) swapoff -a >/dev/null;;
      esac
      eend 0



      Notice the part about deadlock. You can try doing umount -a -t tmpfs yourself before turning swap off.




      Edit:



      Probably, you might also achieve your goal by modifying sysctl settings (see this question).







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Apr 13 '17 at 12:36









      Community♦

      1




      1










      answered Nov 15 '11 at 11:49









      rozcietrzewiacz

      28.2k37191




      28.2k37191











      • I don't have swap in init.d, nor do I have it on fstab, but I do have /etc/init.d/mountoverflowtmp that mounts tmpfs for emergency log writes. Does the swap daemon use tmpfs too?
        – syockit
        Nov 15 '11 at 11:58










      • You might have it enabled elsewhere - do grep -RF swap /etc/ if you wish to find it. But to disable a service, you'd use a command like service (IIRC; I don't use Debian myself).
        – rozcietrzewiacz
        Nov 15 '11 at 12:02






      • 1




        Swap itself does not use tmpfs, because tmpfs is an in-memory (RAM) filesystem. But other services/programs that use tmpfs might rely on swap in a special manner. I don't really know, but it might have something to do with caching or a special way in which tmpfs driver claims access to swap space.
        – rozcietrzewiacz
        Nov 15 '11 at 12:04











      • There's something about how Linux handles virtual memory that I don't understand. I've disabled swap in most ways possible: via swapoff, and via vm.swappiness=0. Yet kswapd0 still runs! I wonder if this is a regression from the 2.4 days…
        – syockit
        Nov 15 '11 at 15:36






      • 4




        @syockit It's expected behavior. The system is still swapping clean pages (pages that contain copies of file data). It requires no swap space to swap clean pages, since they can be read back from sources other than swap.
        – David Schwartz
        Nov 15 '11 at 16:58
















      • I don't have swap in init.d, nor do I have it on fstab, but I do have /etc/init.d/mountoverflowtmp that mounts tmpfs for emergency log writes. Does the swap daemon use tmpfs too?
        – syockit
        Nov 15 '11 at 11:58










      • You might have it enabled elsewhere - do grep -RF swap /etc/ if you wish to find it. But to disable a service, you'd use a command like service (IIRC; I don't use Debian myself).
        – rozcietrzewiacz
        Nov 15 '11 at 12:02






      • 1




        Swap itself does not use tmpfs, because tmpfs is an in-memory (RAM) filesystem. But other services/programs that use tmpfs might rely on swap in a special manner. I don't really know, but it might have something to do with caching or a special way in which tmpfs driver claims access to swap space.
        – rozcietrzewiacz
        Nov 15 '11 at 12:04











      • There's something about how Linux handles virtual memory that I don't understand. I've disabled swap in most ways possible: via swapoff, and via vm.swappiness=0. Yet kswapd0 still runs! I wonder if this is a regression from the 2.4 days…
        – syockit
        Nov 15 '11 at 15:36






      • 4




        @syockit It's expected behavior. The system is still swapping clean pages (pages that contain copies of file data). It requires no swap space to swap clean pages, since they can be read back from sources other than swap.
        – David Schwartz
        Nov 15 '11 at 16:58















      I don't have swap in init.d, nor do I have it on fstab, but I do have /etc/init.d/mountoverflowtmp that mounts tmpfs for emergency log writes. Does the swap daemon use tmpfs too?
      – syockit
      Nov 15 '11 at 11:58




      I don't have swap in init.d, nor do I have it on fstab, but I do have /etc/init.d/mountoverflowtmp that mounts tmpfs for emergency log writes. Does the swap daemon use tmpfs too?
      – syockit
      Nov 15 '11 at 11:58












      You might have it enabled elsewhere - do grep -RF swap /etc/ if you wish to find it. But to disable a service, you'd use a command like service (IIRC; I don't use Debian myself).
      – rozcietrzewiacz
      Nov 15 '11 at 12:02




      You might have it enabled elsewhere - do grep -RF swap /etc/ if you wish to find it. But to disable a service, you'd use a command like service (IIRC; I don't use Debian myself).
      – rozcietrzewiacz
      Nov 15 '11 at 12:02




      1




      1




      Swap itself does not use tmpfs, because tmpfs is an in-memory (RAM) filesystem. But other services/programs that use tmpfs might rely on swap in a special manner. I don't really know, but it might have something to do with caching or a special way in which tmpfs driver claims access to swap space.
      – rozcietrzewiacz
      Nov 15 '11 at 12:04





      Swap itself does not use tmpfs, because tmpfs is an in-memory (RAM) filesystem. But other services/programs that use tmpfs might rely on swap in a special manner. I don't really know, but it might have something to do with caching or a special way in which tmpfs driver claims access to swap space.
      – rozcietrzewiacz
      Nov 15 '11 at 12:04













      There's something about how Linux handles virtual memory that I don't understand. I've disabled swap in most ways possible: via swapoff, and via vm.swappiness=0. Yet kswapd0 still runs! I wonder if this is a regression from the 2.4 days…
      – syockit
      Nov 15 '11 at 15:36




      There's something about how Linux handles virtual memory that I don't understand. I've disabled swap in most ways possible: via swapoff, and via vm.swappiness=0. Yet kswapd0 still runs! I wonder if this is a regression from the 2.4 days…
      – syockit
      Nov 15 '11 at 15:36




      4




      4




      @syockit It's expected behavior. The system is still swapping clean pages (pages that contain copies of file data). It requires no swap space to swap clean pages, since they can be read back from sources other than swap.
      – David Schwartz
      Nov 15 '11 at 16:58




      @syockit It's expected behavior. The system is still swapping clean pages (pages that contain copies of file data). It requires no swap space to swap clean pages, since they can be read back from sources other than swap.
      – David Schwartz
      Nov 15 '11 at 16:58










      up vote
      2
      down vote













      It is better to comment out swap partition entry in /etc/fstab than running swapoff -a after each boot.



      I have the same issue with kswapd0 on my hardware.



      Tuning vm.swappiness system parameter does not help for me.



      sysctl -w vm.swappiness=0


      I googled and read a lot of posts, mailing lists, and now I think that this is kernel bug.



      When there is no active swap partition and free memory becomes less then some threshold (about 300MB in my case) the system becomes unresponsive due to kswapd0 madness.



      Probably it is reproduced with special configuration and conditions.



      For somebody it is solved by system re-installation with re-partitioning for others by building custom kernel with kswapd0 disabled.






      share|improve this answer






















      • If kswapd0 goes mad and you don't have swap activated you're out of RAM. Your choices are OOM Killer or kswapd0. Linux goes with kswapd0 because the kernel assumes that it's more important to finish slowly than to abort the process. For casual humans, the threshold where kernel thinks that enough forward progress still does happen is already glacially slow and nearly anybody would rather select OOM Killer.
        – Mikko Rantalainen
        Aug 31 at 10:35














      up vote
      2
      down vote













      It is better to comment out swap partition entry in /etc/fstab than running swapoff -a after each boot.



      I have the same issue with kswapd0 on my hardware.



      Tuning vm.swappiness system parameter does not help for me.



      sysctl -w vm.swappiness=0


      I googled and read a lot of posts, mailing lists, and now I think that this is kernel bug.



      When there is no active swap partition and free memory becomes less then some threshold (about 300MB in my case) the system becomes unresponsive due to kswapd0 madness.



      Probably it is reproduced with special configuration and conditions.



      For somebody it is solved by system re-installation with re-partitioning for others by building custom kernel with kswapd0 disabled.






      share|improve this answer






















      • If kswapd0 goes mad and you don't have swap activated you're out of RAM. Your choices are OOM Killer or kswapd0. Linux goes with kswapd0 because the kernel assumes that it's more important to finish slowly than to abort the process. For casual humans, the threshold where kernel thinks that enough forward progress still does happen is already glacially slow and nearly anybody would rather select OOM Killer.
        – Mikko Rantalainen
        Aug 31 at 10:35












      up vote
      2
      down vote










      up vote
      2
      down vote









      It is better to comment out swap partition entry in /etc/fstab than running swapoff -a after each boot.



      I have the same issue with kswapd0 on my hardware.



      Tuning vm.swappiness system parameter does not help for me.



      sysctl -w vm.swappiness=0


      I googled and read a lot of posts, mailing lists, and now I think that this is kernel bug.



      When there is no active swap partition and free memory becomes less then some threshold (about 300MB in my case) the system becomes unresponsive due to kswapd0 madness.



      Probably it is reproduced with special configuration and conditions.



      For somebody it is solved by system re-installation with re-partitioning for others by building custom kernel with kswapd0 disabled.






      share|improve this answer














      It is better to comment out swap partition entry in /etc/fstab than running swapoff -a after each boot.



      I have the same issue with kswapd0 on my hardware.



      Tuning vm.swappiness system parameter does not help for me.



      sysctl -w vm.swappiness=0


      I googled and read a lot of posts, mailing lists, and now I think that this is kernel bug.



      When there is no active swap partition and free memory becomes less then some threshold (about 300MB in my case) the system becomes unresponsive due to kswapd0 madness.



      Probably it is reproduced with special configuration and conditions.



      For somebody it is solved by system re-installation with re-partitioning for others by building custom kernel with kswapd0 disabled.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 8 '13 at 11:45









      Anthon

      58.9k1796160




      58.9k1796160










      answered Apr 24 '13 at 4:47









      gumkins

      4121822




      4121822











      • If kswapd0 goes mad and you don't have swap activated you're out of RAM. Your choices are OOM Killer or kswapd0. Linux goes with kswapd0 because the kernel assumes that it's more important to finish slowly than to abort the process. For casual humans, the threshold where kernel thinks that enough forward progress still does happen is already glacially slow and nearly anybody would rather select OOM Killer.
        – Mikko Rantalainen
        Aug 31 at 10:35
















      • If kswapd0 goes mad and you don't have swap activated you're out of RAM. Your choices are OOM Killer or kswapd0. Linux goes with kswapd0 because the kernel assumes that it's more important to finish slowly than to abort the process. For casual humans, the threshold where kernel thinks that enough forward progress still does happen is already glacially slow and nearly anybody would rather select OOM Killer.
        – Mikko Rantalainen
        Aug 31 at 10:35















      If kswapd0 goes mad and you don't have swap activated you're out of RAM. Your choices are OOM Killer or kswapd0. Linux goes with kswapd0 because the kernel assumes that it's more important to finish slowly than to abort the process. For casual humans, the threshold where kernel thinks that enough forward progress still does happen is already glacially slow and nearly anybody would rather select OOM Killer.
      – Mikko Rantalainen
      Aug 31 at 10:35




      If kswapd0 goes mad and you don't have swap activated you're out of RAM. Your choices are OOM Killer or kswapd0. Linux goes with kswapd0 because the kernel assumes that it's more important to finish slowly than to abort the process. For casual humans, the threshold where kernel thinks that enough forward progress still does happen is already glacially slow and nearly anybody would rather select OOM Killer.
      – Mikko Rantalainen
      Aug 31 at 10:35










      up vote
      0
      down vote













      On my system (debian sid 2016-11-15), I did this:




      1. disable the swap now:



        swapoff -a



      2. comment the line with swap partition in /etc/fstab



        #### #UUID=c6ddbc95-3bb5-49e1-ab25-b1c505e5360c none swap sw 0 0



      3. disable the mounting of swap in systemd:



        systemctl --type swap
        systemctl stop dev-sda6.swap
        systemctl mask dev-sda6.swap


      It would be enought. There is reference of the swap in /etc/initramfs-tools/conf.d/resume file. I don't know what is the purpose of this. Maybe this file will be a problem on the next reboot (I don't try to reboot yet, my uptime is precious ;)).






      share|improve this answer


























        up vote
        0
        down vote













        On my system (debian sid 2016-11-15), I did this:




        1. disable the swap now:



          swapoff -a



        2. comment the line with swap partition in /etc/fstab



          #### #UUID=c6ddbc95-3bb5-49e1-ab25-b1c505e5360c none swap sw 0 0



        3. disable the mounting of swap in systemd:



          systemctl --type swap
          systemctl stop dev-sda6.swap
          systemctl mask dev-sda6.swap


        It would be enought. There is reference of the swap in /etc/initramfs-tools/conf.d/resume file. I don't know what is the purpose of this. Maybe this file will be a problem on the next reboot (I don't try to reboot yet, my uptime is precious ;)).






        share|improve this answer
























          up vote
          0
          down vote










          up vote
          0
          down vote









          On my system (debian sid 2016-11-15), I did this:




          1. disable the swap now:



            swapoff -a



          2. comment the line with swap partition in /etc/fstab



            #### #UUID=c6ddbc95-3bb5-49e1-ab25-b1c505e5360c none swap sw 0 0



          3. disable the mounting of swap in systemd:



            systemctl --type swap
            systemctl stop dev-sda6.swap
            systemctl mask dev-sda6.swap


          It would be enought. There is reference of the swap in /etc/initramfs-tools/conf.d/resume file. I don't know what is the purpose of this. Maybe this file will be a problem on the next reboot (I don't try to reboot yet, my uptime is precious ;)).






          share|improve this answer














          On my system (debian sid 2016-11-15), I did this:




          1. disable the swap now:



            swapoff -a



          2. comment the line with swap partition in /etc/fstab



            #### #UUID=c6ddbc95-3bb5-49e1-ab25-b1c505e5360c none swap sw 0 0



          3. disable the mounting of swap in systemd:



            systemctl --type swap
            systemctl stop dev-sda6.swap
            systemctl mask dev-sda6.swap


          It would be enought. There is reference of the swap in /etc/initramfs-tools/conf.d/resume file. I don't know what is the purpose of this. Maybe this file will be a problem on the next reboot (I don't try to reboot yet, my uptime is precious ;)).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '16 at 10:57









          Archemar

          19.1k93467




          19.1k93467










          answered Nov 15 '16 at 10:34









          homer242

          11




          11




















              up vote
              0
              down vote














              the computer hangs with violent I/O throughput in the background.
              iotop reveals kswapd0 to be the culprit




              I've found one way (so far) to avoid that. If you want to test it and see how it does on your system, see the kernel patch inside this question. Basically, it doesn't evict Active(file) pages (at least) when under memory pressure, thus the disk thrashing (constant reading) is reduced to almost nothing and OOM-killer is allowed to trigger within 1 second, instead of freezing the OS for what seems like permanently(or at least for many minutes). I am hoping that actual programmers(of which I'm not) would improve the patch and make it into an actual solution, now that they see that what it does is working for these situations.






              share|improve this answer
























                up vote
                0
                down vote














                the computer hangs with violent I/O throughput in the background.
                iotop reveals kswapd0 to be the culprit




                I've found one way (so far) to avoid that. If you want to test it and see how it does on your system, see the kernel patch inside this question. Basically, it doesn't evict Active(file) pages (at least) when under memory pressure, thus the disk thrashing (constant reading) is reduced to almost nothing and OOM-killer is allowed to trigger within 1 second, instead of freezing the OS for what seems like permanently(or at least for many minutes). I am hoping that actual programmers(of which I'm not) would improve the patch and make it into an actual solution, now that they see that what it does is working for these situations.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote










                  the computer hangs with violent I/O throughput in the background.
                  iotop reveals kswapd0 to be the culprit




                  I've found one way (so far) to avoid that. If you want to test it and see how it does on your system, see the kernel patch inside this question. Basically, it doesn't evict Active(file) pages (at least) when under memory pressure, thus the disk thrashing (constant reading) is reduced to almost nothing and OOM-killer is allowed to trigger within 1 second, instead of freezing the OS for what seems like permanently(or at least for many minutes). I am hoping that actual programmers(of which I'm not) would improve the patch and make it into an actual solution, now that they see that what it does is working for these situations.






                  share|improve this answer













                  the computer hangs with violent I/O throughput in the background.
                  iotop reveals kswapd0 to be the culprit




                  I've found one way (so far) to avoid that. If you want to test it and see how it does on your system, see the kernel patch inside this question. Basically, it doesn't evict Active(file) pages (at least) when under memory pressure, thus the disk thrashing (constant reading) is reduced to almost nothing and OOM-killer is allowed to trigger within 1 second, instead of freezing the OS for what seems like permanently(or at least for many minutes). I am hoping that actual programmers(of which I'm not) would improve the patch and make it into an actual solution, now that they see that what it does is working for these situations.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 31 at 8:56









                  Marcus Linsner

                  18414




                  18414



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f24625%2fhow-to-completely-disable-swap%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay