spcharc
Posts: 20
Joined: Tue Jul 02, 2019 12:23 am

Why it started to use swap when only 100MB of RAM is used?

Sat Dec 14, 2019 1:28 am

Image
I have a 3B. It starts to use swap when there isn't much RAM consumption...
I'm running some python scripts, and took this screenshot just after the orange bar filled the slot. You can see it started to write something into swap.
I've seen this several times, but don't know why. What does that longest orange bar mean here?
I also looked at the man page of htop https://linux.die.net/man/1/htop and still confused. If all the memory is already used, htop should show 967/967 not 115/967, right? It's misleading.

epoch1970
Posts: 5131
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Why it started to use swap when only 100MB of RAM is used?

Sat Dec 14, 2019 4:36 pm

Htop, see https://serverfault.com/a/180724 for a description of the color code.
As to swap, 8 out of 2,000 equates to 0.4% if my math is right. I suppose that is the overhead required to manage the swap partition.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

trejan
Posts: 2118
Joined: Tue Jul 02, 2019 2:28 pm

Re: Why it started to use swap when only 100MB of RAM is used?

Sat Dec 14, 2019 4:49 pm

You're doing or done something with a high amount of I/O as htop shows the cache to be consuming most of memory. The Linux swap algorithm tries to weigh up the benefits of keeping inactive pages in memory vs using those pages for cache. It doesn't just wait until a predefined threshold to start swapping. You can adjust how likely it is to swap out pages by altering the swappiness sysctl.
epoch1970 wrote:
Sat Dec 14, 2019 4:36 pm
As to swap, 8 out of 2,000 equates to 0.4% if my math is right. I suppose that is the overhead required to manage the swap partition.
The overhead for the swap isn't included in the totals. It has actually swapped out 8MB.

spcharc
Posts: 20
Joined: Tue Jul 02, 2019 12:23 am

Re: Why it started to use swap when only 100MB of RAM is used?

Sat Dec 14, 2019 8:16 pm

trejan wrote:
Sat Dec 14, 2019 4:49 pm
You're doing or done something with a high amount of I/O as htop shows the cache to be consuming most of memory. The Linux swap algorithm tries to weigh up the benefits of keeping inactive pages in memory vs using those pages for cache. It doesn't just wait until a predefined threshold to start swapping. You can adjust how likely it is to swap out pages by altering the swappiness sysctl.
epoch1970 wrote:
Sat Dec 14, 2019 4:36 pm
As to swap, 8 out of 2,000 equates to 0.4% if my math is right. I suppose that is the overhead required to manage the swap partition.
The overhead for the swap isn't included in the totals. It has actually swapped out 8MB.
Yes I was rearranging some of my containers and I'm surprised it can spare some disk IO brandwith for swap.
Thanks for your detailed explanation!

Return to “Beginners”