Ubuntu freezing with high memory usage
From WickyWiki
To fix this you need to set the following setting to something around 5%-6% of your total physical RAM, divided by the number of cores in the computer:
Keep in mind that this is a per-core setting, so if I have 2GB RAM and two Cores, then I calculated 6% of only 1 GB and added a little extra just to be safe.
This forces the computer to try to keep this amount of RAM free, and in doing so limits the ability to cache disk files. Of course it still tries to cache them and immediately swap them out, so you should probably limit your swapping as well.
sudo gedit /etc/sysctl.conf # limit swappiness vm.swappiness=5 # limit proces memory usage # 6% of 2Gb * 1024 / 2 cores plus some bits vm.min_free_kbytes=65536