0

Been going through this topic - https://askubuntu.com/questions/157793/why-is-swap-being-used-even-though-i-have-plenty-of-free-ram.

Turned down swappiness to 10 and then to 0 but my installation is never able to reach out into 70%+ of RAM before turning to the swap area. So I am wrestling my lunix system with the help of that script from the link above, but still no joy. I am getting:

kellogs@kellogs-K52Jc ~/workspace/xgate_git/tigase-server $ sudo unswap.sh
Free memory:    1525024 kB (1489 MB)
Used swap:      938196 kB (916 MB)
Freeing swap...
swapoff: /dev/sda4: swapoff failed: Cannot allocate memory

and even:

kellogs-K52Jc tigase-server # unswap.sh
Free memory:    1212956 kB (1184 MB)
Used swap:      478516 kB (467 MB)
Freeing swap...
swapoff: /dev/sda4: swapoff failed: Cannot allocate memory

It must be something keeping the OS from using the 30% remainder of RAM. But what ?

EDIT:

Original: vm.overcommit_memory = 0 vm.overcommit_ratio = 50

Set to vm.overcommit_memory = 2 vm.overcommit_ratio = 100

And RAM usage would stall at about 50%; After this programs would not launch any longer and complain about memory shortage. Swap remained at 0% usage.

Set to: vm.overcommit_memory = 1 vm.overcommit_ratio = 100

Managed to go to about 83% RAM and 22% swap usage. Then I have called that script for emptying swap-into-RAM and hell broke loose. libflash crashing, the rest of programs unresponsive and having gone into broken pipes and stuff like that.

kellogs
  • 161
  • Duplicate of http://serverfault.com/questions/420778/why-swap-is-used-when-plenty-of-free-memory-is-left – enedil Feb 14 '14 at 01:35
  • @enedil - It's OK to have duplicates across the SE sites. Just not within one site. I should qualify that these duplicates should be geared to the specific SE site that they're on, and they shouldn't be merely a cross-post by the OP. – slm Feb 14 '14 at 02:08
  • @enedil - you're welcome to take pieces from the answers to the SE sites and create an appropriate A on this site as well. – slm Feb 14 '14 at 02:08
  • This one on U&L seems like the duplicate: http://unix.stackexchange.com/questions/77939/turning-off-swapping-for-only-one-process-with-cgroups/77955#77955. It explains why you can't go < 30% as you're finding. – slm Feb 14 '14 at 02:11
  • @slm: not exactly clear. Why not <30% ? – kellogs Feb 14 '14 at 03:04
  • Because having so little ram left would be bad for performance, thus it is a good thing that some unused ram in idle applications is swapped out to make room for data that is actually being used. – psusi Feb 14 '14 at 03:47
  • 1
    Nothing in that answer says you can't go below 30% mem free. The only thing I can think of that would prevent you from using all RAM is setting vm.overcommit_ratio to less than 100. @kellogs, what is the result of sysctl -a | grep vm.overcommit? – phemmer Feb 14 '14 at 04:39
  • @Patrick nice one. Can't really see how overcommitting might be affecting simple committing, but hey, I have put down my adventures with those two in the edited post. – kellogs Feb 14 '14 at 08:15
  • @kellogs well vm.overcommit_memory=0 is the default and usually sensible option. I doubt it's the problem. Setting to 1 disables the restrictions entirely. You definitely don't want to set it to 2 without thorough research on what to set the ratio at. The reason it went nuts when you set it to 1 is that the kernel no longer protected you from using all your ram, and that's exactly what happened, 100% memory usage. – phemmer Feb 14 '14 at 13:27
  • What's the unswap.sh script you're using? What makes you think you can't go over 30% of RAM: what are the figures you're comparing? Why are you fiddling with overcommit (if you switch to unrestrained overcommitting, programs crashes when the system runs out of memory is to be expected)? – Gilles 'SO- stop being evil' Feb 14 '14 at 15:15

1 Answers1

1

Why exactly are you worrying about swap? The most important rule when tuning for performance (or anything else, for that matter) is to check if performance is adequate, if not measure where the bottlenecks are, then work on them. Jon Bentley's "Writing efficient programs" (sadly out of print) should be required reading; but look for his "Programming pearls".

vonbrand
  • 18,253