2

I've been often annoyed on Ubuntu when there's a peak in RAM -- for example when starting Android Studio's emulator or when a Chrome tab freezes -- the whole GUI freezes and so I'm forced to either wait for it come back or go to TTY and kill the culprit.

Is it possible that Ubuntu manages RAM very differently than Windows does? On Windows, the app itself freezes but not the whole GUI. Is there a way to make Ubuntu behave more like Windows in that respect?

wjandrea
  • 14,504
Daniel
  • 153

2 Answers2

3

Modern OSs use paging to manage memory. It gives some advantadges to the system like being able to use more memory than you have physically, securing some sensitive memory area (like the kernel reserved memory) amongst other things that I can point some reference to if you want to learn more about paging.

But what is paging?

I'll skip the technicals and give you an analogy. Imagine you have an encyclopedia collection, A to Z, and being a curious person you like to spend afternoons reading it. You keep all of the encyclopedias on your bookshelf and you have a reading table which you can have 4 books on.

One day you are reading about "Sailing", which is on the letter S encyclopedia. At some point you might need to read about something else related, like "Winds" on letter W book. As long as you have it on your reading table you can quickly open it and read what you need, then go back to the "Sailing" book. Problem is, since your reading table can only fit 4 books, the chances are high you will need a book that isn't there already. Then you would need to take one of the books from the table back to the shelf, grab the book you need to the reading table and read it.

Ok, what does this whole book story has to do with my freezes? Well, the computer does something similar all the time. To be able to use more memory than it physically has, the computer divide memory in pages, which are small continuous blocks of memory. Those don't need to be on RAM (the "reading table") all the time, they might be stored on your disk (the "bookshelf"). If the RAM is full and the CPU needs to read/write on those pages stored on disk, one of the pages on RAM will be stored on disk, and the page requested will be loaded on RAM.

This is a Kernel job, so it is transparent to the user and programs. But since reading and writing to the disk is much slower than reading and writing on RAM, you will notice those freezes.

On Linux, there is a partition called swap, which is used to store those extra pages. Windows does the same thing, but I think it uses a file. The system kernel itself won't freeze, since it will be on locked ("non-swappable") pages.

The image below (from an wikipedia article) illustrates the concept of paging (and virtual memory, which we don't need to go into). Those blocks represents the pages being allocated on both memory or disk. Virtual Memory Paging

I believe the reason it might look like Linux is freezing too, is because Unity (the desktop GUI) might experience the delays caused by this swapping, while on Windows they might keep the desktop GUI code in locked ("non-swappable") pages. This is just a brainstorm theory though.

IanC
  • 951
1

I had similar problems in the past. I changed swappiness of ubuntu in order to make the OS write RAM to HD much later.

Read an answer to change swappiness here: How do I configure swappiness?

I can not guarantee this helps to solve your problem, but in my opinion it is the best bet.

mondjunge
  • 3,336