How swap space is used in Linux and Unix

Post Reply
Message
Author
User avatar
BitJam
Developer
Posts: 2283
Joined: Sat Aug 22, 2009 11:36 pm

How swap space is used in Linux and Unix

#1 Post by BitJam »

I learned a lot from this article: What has to happen with Unix virtual memory when you have no swap space

TL;DR:
1) Running out of memory with no swap will bring your system to its knees (or worse).

2) Swap is only used for memory that does not already have a copy on disk. Libraries and executables are usually available on disk and therefore don't use swap space.

3) Therefore if you are running out of memory and have no swap then the disk will still thrash as it swaps out libraries and executables that may be needed right away.
"The first principle is that you must not fool yourself -- and you are the easiest person to fool."

-- Richard Feynman

User avatar
Adrian
Developer
Posts: 8268
Joined: Wed Jul 12, 2006 1:42 am

Re: How swap space is used in Linux and Unix

#2 Post by Adrian »

Oh, interesting didn't know about no. 3.

User avatar
manyroads
Posts: 2624
Joined: Sat Jun 30, 2018 6:33 pm

Re: How swap space is used in Linux and Unix

#3 Post by manyroads »

I have found that my swap is almost 100% idle. Could be because I have 24GB of RAM.... Anyway on all my new builds I just add RAM and ignore swap. Sloppy programmer behavior I guess. :needcoffee:
Pax vobiscum,
Mark Rabideau - ManyRoads Genealogy -or- eirenicon llc. (geeky stuff)
i3wm, bspwm, hlwm, dwm, spectrwm ~ Linux #449130
"For every complex problem there is an answer that is clear, simple, and wrong." -- H. L. Mencken

User avatar
mxer
Posts: 211
Joined: Fri Sep 21, 2018 9:09 am

Re: How swap space is used in Linux and Unix

#4 Post by mxer »

As long as you have enough ram to cover your computer use needs, you don't need any swap, but if you do work that requires a lot of ram use, compiling big programs/intensive video work, etc, then you'd better have some. probably the equal of the amount of ram you have installed.

Me? I used to get away with no swap on a 1GB machine, but now have at least 2GB, because of how much a modern web browser wants to use. :happy:
(FOSS, Linux, & BSD since 1999)

User avatar
Richard
Posts: 1577
Joined: Fri Dec 12, 2008 10:31 am

Re: How swap space is used in Linux and Unix

#5 Post by Richard »

I use a 1 GB swap file on /media/SWAPFS of the T430, just in case. And I occasionally see a small usage.
Probably for my use even ½ GB would suffice.

I believe it has reduced some occasional lags that I noticed while running without any swap.
All subjective but it feels right.
Thinkpad T430 & Dell Latitude E7450, both with MX-21.3.1
kernal 5.10.0-26-amd64 x86_64; Xfce-4.18.0; 8 GB RAM
Intel Core i5-3380M, Graphics, Audio, Video; & SSDs.

Post Reply

Return to “General”