0

My computer (running Ubuntu 16.04) has 8GB memory and 8GB of swap. When I use my computer it ends up freezing due to a lack of RAM. How can I make it work on swap when there is no memory left?

The output to free is:

            total        used        free      shared  buff/cache   available
Mem:           7.7G        3.1G        132M        692M        4.4G        3.5G
Swap:          7.9G          0B        7.9G
mook765
  • 15,925
  • What is your output of free command? – Alvin Liang Dec 21 '18 at 02:13
  • Read man swapon – waltinator Dec 21 '18 at 02:27
  • 1
    The applications you use for simulation may need more RAM. Swaps primary purpose is to hold memory pages that are not immediately needed, which should free up RAM for new processes. Aside from getting larger RAM sticks, consider tuning your system - see https://askubuntu.com/q/2194/295286 . I'd say decrease number of services you have starting on boot, use lighter desktop ( if you use any ), consider parallelizing tasks, try to limit resources for certain processes – Sergiy Kolodyazhnyy Dec 21 '18 at 03:08
  • 1
    The bottom line is this... upgrade your memory. Your free -h command shows no swap usage, but you may have used that command when nothing was going on. Sure, you could play with various settings like vm.swappiness, but it wouldn't change the fact that you need more physical RAM. You could also change your script to only read in portions of the text file, so that it doesn't use all of your existing RAM. – heynnema Dec 21 '18 at 03:18
  • I think buy an SSD will improve text file editing throughput scenario the most. When text file reading and swap activating happens at the same time, it will not help you finish the task any quicker. – Alvin Liang Dec 21 '18 at 03:53
  • @Ch.I Your last edits made your question useless, I rolled the edits back to Fabby's edit. – mook765 Dec 22 '18 at 08:26

1 Answers1

2

Many people do not understand the nature of swap: it's very slow!

For an old machine with DDR3 1600 memory:

  • the memory transfer rate is 12800 MB/s,
  • a HDD rate is around 100-200 MB/s,
  • a SSD rate is maximum 600 MB/s

So if the memory pressure is so high that swap usage is frequent, everything will still work, but will slow down tremendously because the speed of swap is less than 1/1000 of the normal memory.

Where swap can help us in daily life is that if you're running multiple programs, less frequently used program can be swapped out but are still retained in the system. You wait 2-3 minutes to allow less active pages to go to swap, then you can use your current Application without much pain. And in many cases the less active pages never swap back again so there's no further penalty.

But when you talk about simulation, which means your data is huge and swap in/out activities will be frequent, it just looks like your system is freezing, because more than 99.9% of the CPU time is in uninterruptible iowait.

So the solution to your problems is:

  • Buy more RAM
  • Have tremendous patience and wait 1000 times longer with your current setup
  • Add an SSD and still have a lot of patience and wait 100 times longer...
Fabby
  • 34,259
Alvin Liang
  • 1,673
  • 2
    I'm not sure I agree that "freezing is the normal behavior", and that it "doesn't help to tune your swap". Between tuning applications vs physical RAM vs swap size/settings, there are things that can be done to improve the status quo. – heynnema Dec 21 '18 at 03:27
  • Well, it depends how much memory he's using for simulator. But when swap is activating heavily, system will be slow to nearly freezed, that is for sure. – Alvin Liang Dec 21 '18 at 03:35
  • 1
    The OP's script that edits a 8G text file in RAM is very suspect from a performance and swapping standpoint. Many modern computers with SSD make swapping almost a non-issue. But as my comment to the OP indicates, they need more RAM, if they change nothing else. – heynnema Dec 21 '18 at 03:37
  • Alvin An edit and an upvote! ;-) @heynnema have a look now. His basic idea is good, just the "freezing" part was incorrect as you and me see it as "sigstop" , whereas Alvin meant it as "looks like a freeze"... – Fabby Dec 21 '18 at 08:21
  • 1
    @AlvinLiang: Please don't forget to also give the OP a clue on how to get out of the situation he's in, not just explain what's happening... ;-) – Fabby Dec 21 '18 at 08:25