ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: Permanently disable swap on Raspbian Buster

Sun Aug 18, 2019 2:29 pm

Ok, I re-read the conversation, and it indeed appears that we misunderstood each other.

To get to the point, Debian and Raspbian are not in the list of operating systems that run entirely from RAM.
https://en.wikipedia.org/wiki/List_of_L ... n_from_RAM

Which means that they do access the swap partition.
There's no real documentation on when or how much Raspbian is accessing the Swap file, but in my case on the 3B+, the swap file is 80MB.
This indicates that 80MB is at least being used at some point, though "free -h" shows 100-500 MB of free memory in most conditions.

I understand that Debian is pretty good with RAM and swap allocation, but in cases where a regular SD card is used (a non-A1), responsiveness can plummet if it was just to access 1kb of data from the swap file.

User avatar
PeterO
Posts: 5032
Joined: Sun Jul 22, 2012 4:14 pm

Re: Permanently disable swap on Raspbian Buster

Sun Aug 18, 2019 2:51 pm

ProDigit wrote:
Sun Aug 18, 2019 2:29 pm
Ok, I re-read the conversation, and it indeed appears that we misunderstood each other.

To get to the point, Debian and Raspbian are not in the list of operating systems that run entirely from RAM https://en.wikipedia.org/wiki/List_of_L ... n_from_RAM
What has that got to do with it ? That's a totally different subject to "using swap space".

Which means that they do access the swap partition.
Non sequitur !
There's no real documentation on when or how much Raspbian is accessing the Swap file, but in my case on the 3B+, the swap file is 80MB.
This indicates that 80MB is at least being used at some point, though "free -h" shows 100-500 MB of free memory in most conditions.
Size of the swap file is determined at boot time.
On my Pi4 (with 4Gb RAM)

Code: Select all

pi@raspberrypi:/var $ ls -lrth /var/swap
-rw------- 1 root root 100M Jun 20 18:20 /var/swap
pi@raspberrypi:/var $ free 
              total        used        free      shared  buff/cache   available
Mem:        3947004      194004     3459920       44752      293080     3582972
Swap:        102396           0      102396
pi@raspberrypi:/var $ 

On my Mint Desk top (with 12Gb RAM)

Code: Select all

petero@EliteDesktop1:/$ ls -lrth /swapfile 
-rw------- 1 root root 2.0G Jul 18  2018 /swapfile
petero@EliteDesktop1:/$  free
              total        used        free      shared  buff/cache   available
Mem:       12185048     2874968     5321208      510112     3988872     8545084
Swap:       2097148           0     2097148
petero@EliteDesktop1:/$ 

Neither of these machines has done any swapping since they were turned on but both have swap files.
The existence of a swap file does not prove swapping is happening (or has happend).

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
thagrol
Posts: 1851
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Permanently disable swap on Raspbian Buster

Sun Aug 18, 2019 4:21 pm

ProDigit wrote:
Sun Aug 18, 2019 2:29 pm
Ok, I re-read the conversation, and it indeed appears that we misunderstood each other.

To get to the point, Debian and Raspbian are not in the list of operating systems that run entirely from RAM.
https://en.wikipedia.org/wiki/List_of_L ... n_from_RAM

Which means that they do access the swap partition.
No. No it doesn't. "Run from RAM" means that during boot the entire OS filesystem is loaded into RAM. To a RAM disc. Then run from there. "Run from RAM" doesn't mean "doesn't use swap" though a "run from RAM" distro probably won't as it has nowhere to swap to. It means once booted doesn't use any storage media whether it's swap or not. It also means you lose everything on a poweroff.

If you were to add a swap file/partition to a "run from RAM" distro I'd expect it to swap more often than the equivalent run from HDD install.
There's no real documentation on when or how much Raspbian is accessing the Swap file, but in my case on the 3B+, the swap file is 80MB.
This indicates that 80MB is at least being used at some point, though "free -h" shows 100-500 MB of free memory in most conditions.
That implies something on your system is using enough RAM to cause it to swap. Not surprising if you only have 100MB free. Taking away swap won't improve anything. You need to run less and/or adjust the value on your OS for swapiness as has already been suggested.

Oh and is that "100-500MB" the figure in the "free" column or the "available" column?

My 4B shows free as 539Mi and available as 794Mi with swap used as 0B:

Code: Select all

              total        used        free      shared  buff/cache   available
Mem:          974Mi       107Mi       539Mi       7.0Mi       327Mi       794Mi
Swap:         2.5Gi          0B       2.5Gi
"free" is what's currently unused. Available is "free" plus RAM used by caches etc than can be trivially reclaimed without swaping.

edit:
I understand that Debian is pretty good with RAM and swap allocation, but in cases where a regular SD card is used (a non-A1), responsiveness can plummet if it was just to access 1kb of data from the swap file.
No one is disagreeing with that. What we're saying ist:
  • Disabling swap is not the solution. (The correct solution being to add more RAM - can't do that on a pi - or to move the swap space to a faster device)
  • That swap space exists does not mean it is being used. Think of it like a cupboard - if it's empty it's unused but still exists and takes up space in your kitchen.
  • Having swap space configured but unused has no impact on performance.
  • Not having any swap space will cause more problems than you tihnk it will solve.
  • You need to review what you have running on your Pi.
  • You need to adjust your swap settings so it's less agressive.
May I politely suggest you read up more on swap, RAM usage, linux and modern OS in general before arguing further.
This space unintentionally left blank.

bjtheone
Posts: 261
Joined: Mon May 20, 2019 11:28 pm
Location: Kanata, Ontario, Canada

Re: Permanently disable swap on Raspbian Buster

Tue Aug 20, 2019 8:21 pm

Further to this. On a Pi 3b+ 100 Mb of swap is not your friend if you are trying to run Chromium and open multiple tabs on fat sites. The machine runs out of resources and deadlocks. Move to an SSD and and 1 Gb of swap and magically it runs fairly well. Are you paying a performance penalty moving stuff to and from memory to storage (swapping) absolutely. But it does not freeze or become so messed up trying to manage the RAM that you have to pull the plug (cannot even ssh in to kill Chromium).

However, given that we can't add ram, the alternative is either don't run the apps I want in the manner I wish to or provide swap. When I am not doing activities that require absurd memory footprints (Chromium I am looking at you), as has been repeatedly pointed out, my 1 Gb swap file just sits there unused. On a 4Gb 4B running the same workload, it fits quite happily into the available RAM with no need to increase the swap file from the default.

ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: Permanently disable swap on Raspbian Buster

Tue Aug 20, 2019 9:32 pm

I'm just used to optimize the system to the hardware.
Minimize ram usage, by using a plain background, minimalistic theme, and uninstall most programs I'd never use or need.
Also, the Pi3 for me isn't really to open a lot of tabs; I would open 2 to 3 tabs at most, and mostly sites that provide updates, programs, or just plain information (forums, wiki, articles,...).

Loading mobile sites instead of full sites helps too.

With being frugal, the Pi 3B+ provides plenty of RAM for everyday use. Or, update the OS to tinycore, and run the entire system from 50MB of RAM.

User avatar
rpdom
Posts: 15242
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Permanently disable swap on Raspbian Buster

Tue Aug 20, 2019 9:36 pm

Uninstalling most programs will save a bit of space on the main storage device, but won't make any difference to RAM or CPU usage.

User avatar
thagrol
Posts: 1851
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Permanently disable swap on Raspbian Buster

Tue Aug 20, 2019 9:45 pm

ProDigit wrote:
Tue Aug 20, 2019 9:32 pm
I'm just used to optimize the system to the hardware.
Minimize ram usage, by using a plain background, minimalistic theme, and uninstall most programs I'd never use or need.
Also, the Pi3 for me isn't really to open a lot of tabs; I would open 2 to 3 tabs at most, and mostly sites that provide updates, programs, or just plain information (forums, wiki, articles,...).

Loading mobile sites instead of full sites helps too.

With being frugal, the Pi 3B+ provides plenty of RAM for everyday use. Or, update the OS to tinycore, and run the entire system from 50MB of RAM.
If that's the case how on earth did you manage to misunderstand swap and "run from RAM" distros the way you did? Not attacking, just curious.
This space unintentionally left blank.

ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: Permanently disable swap on Raspbian Buster

Tue Aug 20, 2019 10:44 pm

rpdom wrote:
Tue Aug 20, 2019 9:36 pm
Uninstalling most programs will save a bit of space on the main storage device, but won't make any difference to RAM or CPU usage.
Sometimes it does.
in Windows, and Android, doing this will reduce registry entries, so for instance file associations are removed.
removed App or program notifications are also removed, which frees ram and background tasks and activity.

There's a small amount of RAM to be saved this way; and I'm sure the same is true for any Linux distribution.
The less is installed, the more barebones the OS, the less ram it uses.

You could go the other way, and install headless with just the programs you need, and possibly X Window System, and a browser (like w3m) if you'd want to go extreme.

But I prefer to trim down the full desktop install, rather than add on to the light version of Raspbian.

bjtheone
Posts: 261
Joined: Mon May 20, 2019 11:28 pm
Location: Kanata, Ontario, Canada

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 2:16 am

You have a rather odd way of doing things. If you want bare bones either get a stripped tiny OS or just start with Raspbian Lite and add only the cmdline apps you absolutely need. Starting with a distro with X and a desktop and trying to strip it out without breaking stuff is a total pita.

If you are starting with a full install and trimming and then at the same time quibbling about the potential saving from removing things like file associations, you are definitely following a different drummer than most. Also, apps that are installed and not running consume exactly no resources beyond the "disk space" they consume. If you are being total pedantic, yes they may setup things like file associations, that may take a extra byte or two in a associative table that gets loaded by the desktop. Will not change the performance of the Pi in any meaningful and even measurable way when they are not running.

Starting with Raspbian Lite and then adding the basic X packages and the bare bones of whatever desktop you want will get you the same thing without all the drama/trauma and breakage of trying to remove stuff.

User avatar
thagrol
Posts: 1851
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 12:10 pm

ProDigit wrote:
Tue Aug 20, 2019 10:44 pm
rpdom wrote:
Tue Aug 20, 2019 9:36 pm
Uninstalling most programs will save a bit of space on the main storage device, but won't make any difference to RAM or CPU usage.
Sometimes it does.
in Windows, and Android, doing this will reduce registry entries, so for instance file associations are removed.
removed App or program notifications are also removed, which frees ram and background tasks and activity.

There's a small amount of RAM to be saved this way; and I'm sure the same is true for any Linux distribution.
The saving is tiny, even more so when compared to the effort involved.

And comparing linux and windows is comparing apples and oranges.
The less is installed, the more barebones the OS
Yes, but...
, the less ram it uses.
That doesn't follow. It's prefectly posible to have a small OS running memory hevay processes. And apart from the disc cache (which is trvialy recoverable) the impact of an installed but not running prgroam is neglible at most.
You could go the other way, and install headless with just the programs you need, and possibly X Window System, and a browser (like w3m) if you'd want to go extreme.
I do and doing so leads to a more tailored and lighter system.
But I prefer to trim down the full desktop install, rather than add on to the light version of Raspbian.
That's your choice though I and others consider it a poor one that is more complex and requires more effort than doing it the other way.

Whichever way you choose, it's my opinion that the most efficient way would be to do your config once then image the SD card. All you need to change then for a new Pi is likely the hostname and (if static) the IP address. Well, excluding moves between major OS versions.
This space unintentionally left blank.

ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 12:35 pm

bjtheone wrote:
Wed Aug 21, 2019 2:16 am
You have a rather odd way of doing things. If you want bare bones either get a stripped tiny OS or just start with Raspbian Lite and add only the cmdline apps you absolutely need. Starting with a distro with X and a desktop and trying to strip it out without breaking stuff is a total pita.

If you are starting with a full install and trimming and then at the same time quibbling about the potential saving from removing things like file associations, you are definitely following a different drummer than most. Also, apps that are installed and not running consume exactly no resources beyond the "disk space" they consume. If you are being total pedantic, yes they may setup things like file associations, that may take a extra byte or two in a associative table that gets loaded by the desktop. Will not change the performance of the Pi in any meaningful and even measurable way when they are not running.

Starting with Raspbian Lite and then adding the basic X packages and the bare bones of whatever desktop you want will get you the same thing without all the drama/trauma and breakage of trying to remove stuff.
But it's more work.
And the full desktop is correctly configured.
It saves time to go the other way around.

User avatar
PeterO
Posts: 5032
Joined: Sun Jul 22, 2012 4:14 pm

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 12:52 pm

ProDigit wrote:
Wed Aug 21, 2019 12:35 pm
bjtheone wrote:
Wed Aug 21, 2019 2:16 am
You have a rather odd way of doing things. If you want bare bones either get a stripped tiny OS or just start with Raspbian Lite and add only the cmdline apps you absolutely need. Starting with a distro with X and a desktop and trying to strip it out without breaking stuff is a total pita.

If you are starting with a full install and trimming and then at the same time quibbling about the potential saving from removing things like file associations, you are definitely following a different drummer than most. Also, apps that are installed and not running consume exactly no resources beyond the "disk space" they consume. If you are being total pedantic, yes they may setup things like file associations, that may take a extra byte or two in a associative table that gets loaded by the desktop. Will not change the performance of the Pi in any meaningful and even measurable way when they are not running.

Starting with Raspbian Lite and then adding the basic X packages and the bare bones of whatever desktop you want will get you the same thing without all the drama/trauma and breakage of trying to remove stuff.
But it's more work.
And the full desktop is correctly configured.
It saves time to go the other way around.
There are 1000's of web pages showing how easy it is to add a GUI to Raspbian Lite. You just need to go and find some to find out how... :lol:
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

bjtheone
Posts: 261
Joined: Mon May 20, 2019 11:28 pm
Location: Kanata, Ontario, Canada

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 1:05 pm

ProDigit wrote:
Wed Aug 21, 2019 12:35 pm
bjtheone wrote:
Wed Aug 21, 2019 2:16 am
Starting with Raspbian Lite and then adding the basic X packages and the bare bones of whatever desktop you want will get you the same thing without all the drama/trauma and breakage of trying to remove stuff.
But it's more work.
And the full desktop is correctly configured.
It saves time to go the other way around.
Your claims and statements of inherently contradictory.

Raspbian Lite is correctly configured and works. Installing xorg and xinit adds in a clean X setup. Installing a minimal desktop, say Mate, and you are done. Taking apart a full desktop without breaking it is way more work, and is very very likely to be larger.

Assuming you are starting from a booted Pi, with Raspbian Lite installed and configured, such that you have an internet connection, from the command prompt, it is 5 commands:

Code: Select all

sudo apt-get install --no-install-recommends xserver-xorg
sudo app-get install --no-install-recommends xinit
sudo apt-get install mate-desktop-environment-core
sudo apt-get install lightdm
sudo reboot
Please feel free to list the steps and results that you use to get from a full desktop install to what you are calling a bare bones setup.

User avatar
thagrol
Posts: 1851
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 1:08 pm

ProDigit wrote:
Wed Aug 21, 2019 12:35 pm
But it's more work.
And the full desktop is correctly configured.
It saves time to go the other way around.
It's not.
That's not guaranteed.
It doesn't

When installing packages apt will handle all the dependancies. When removing it often doesn't. Which leaves alot of unsed files present on the system (and remember according to you that's bad from RAM use and performance).

Remvoe the wrong thing and you can easily break your dekstop.

Removing packages doen't require them to be downloaded (installing does, obviously) but really the only difference is when you do the download - in the initial image or at install time.

Regardles of the OS you're running you'll almost always get a lighter, faster install by starting with the bare minimum and adding only what you need.

If you're not using the package manager (apt or whatever is in the gui) to remove the stuff you don't want you're A. removing nothing except menu entries and/or desktop links, and B. likely to break your system (if you're just deleting files).

At the end of the day it's your choice whether to do it the hard way or the easy way (yeah, I know we disagree on which is which). Whichever you pick, make an image of the finished SD card so you have to do it a lot less. Or write a script to add/remove the packages and keep it off the SD card so you don't lose it when re-burning an image to it.

You seem to have some strange, fixed idea about how linux works and how to administer it...
This space unintentionally left blank.

User avatar
thagrol
Posts: 1851
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 1:14 pm

bjtheone wrote:
Wed Aug 21, 2019 1:05 pm

Code: Select all

sudo apt-get install mate-desktop-environment-core
Replacing that with

Code: Select all

sudo apt install raspberrypi-ui-mods
should get you the foundation's GUI.
This space unintentionally left blank.

User avatar
rpdom
Posts: 15242
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 1:19 pm

bjtheone wrote:
Wed Aug 21, 2019 1:05 pm
Assuming you are starting from a booted Pi, with Raspbian Lite installed and configured, such that you have an internet connection, from the command prompt, it is 5 commands:

Code: Select all

sudo apt-get install --no-install-recommends xserver-xorg
sudo app-get install --no-install-recommends xinit
sudo apt-get install mate-desktop-environment-core
sudo apt-get install lightdm
sudo reboot
I didn't like when "recommended" software started to be installed by default.

Now I always create a file /etc/apt/apt.conf.d/90local with the contents

Code: Select all

APT::Install-Recommends "false";
which means that "recommended" software isn't installed unless I specifically ask for it. I can only recall one occasion in the last 15 years when I have actually needed one of the "recommended" packages, and in that case I just installed it with apt.

bjtheone
Posts: 261
Joined: Mon May 20, 2019 11:28 pm
Location: Kanata, Ontario, Canada

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 2:06 pm

thagrol wrote:
Wed Aug 21, 2019 1:14 pm
bjtheone wrote:
Wed Aug 21, 2019 1:05 pm

Code: Select all

sudo apt-get install mate-desktop-environment-core
Replacing that with

Code: Select all

sudo apt install raspberrypi-ui-mods
should get you the foundation's GUI.
Which would be good if one liked LXDE... Personally I find it a tad too bare bones and will happily live with the small amount of extra RAM usage to get Mate. I will concede that part of that is just familiarity with the GUI, but I have run all of the mainline distros and desktops over the last 20+ years, and Unix before that. I can remember when X11 was that new fangled windows thing. Heck can even remember when we actually could support "full screen editors" on terminals.

bjtheone
Posts: 261
Joined: Mon May 20, 2019 11:28 pm
Location: Kanata, Ontario, Canada

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 2:55 pm

rpdom wrote:
Wed Aug 21, 2019 1:19 pm
I didn't like when "recommended" software started to be installed by default.

Now I always create a file /etc/apt/apt.conf.d/90local with the contents

Code: Select all

APT::Install-Recommends "false";
which means that "recommended" software isn't installed unless I specifically ask for it. I can only recall one occasion in the last 15 years when I have actually needed one of the "recommended" packages, and in that case I just installed it with apt.
I think it came about as the safer/simpler option as the "average user" changed, as Linux moved from sysadmins and tinfoil wearing geeks to regular folks, lots of whom have never installed an operating system. Most Windows users just buy a PC with a preloaded OS. Plus disk is so so cheap now. Even on a corner case like a Pi, "disk" is cheap in that going from a 16 Gb to a 32 Gb SD card adds a few dollars.

The fact that I can get from Raspbian Lite to a fully working Mate desktop in 5 commands, without messing with one unmet dependency or having to edit and compile anything is amazing. Even bringing in a build environment and compiling rar-unfree to address a need was utterly painless.

User avatar
PeterO
Posts: 5032
Joined: Sun Jul 22, 2012 4:14 pm

Re: Permanently disable swap on Raspbian Buster

Wed Aug 21, 2019 4:15 pm

ProDigit wrote: But it's more work.
And the full desktop is correctly configured.
It saves time to go the other way around.
bjtheone wrote:
Wed Aug 21, 2019 2:55 pm
The fact that I can get from Raspbian Lite to a fully working Mate desktop in 5 commands, without messing with one unmet dependency or having to edit and compile anything is amazing. Even bringing in a build environment and compiling rar-unfree to address a need was utterly painless.
Was that the sound of a gauntlet being thrown down :?: :lol:
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
jcyr
Posts: 358
Joined: Sun Apr 23, 2017 1:31 pm
Location: Atlanta

Re: Permanently disable swap on Raspbian Buster

Fri Aug 30, 2019 9:18 pm

Back to the original post. I can only think of a few reasons to disable the swap file, both dubious at best.

- On a 4G Pi4, I've never seen it used at all, despite running it though its paces rebuilding the GNU toolchain with an 8 thread make (make -j8).
- Disabling the dphys-swap daemon, might save a few CPU cycles and free up a little RAM.
It's um...uh...well it's kinda like...and it's got a bit of...

PiGraham
Posts: 3613
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Permanently disable swap on Raspbian Buster

Sun Sep 01, 2019 10:56 am

jcyr wrote:
Fri Aug 30, 2019 9:18 pm
Back to the original post. I can only think of a few reasons to disable the swap file, both dubious at best.

- On a 4G Pi4, I've never seen it used at all, despite running it though its paces rebuilding the GNU toolchain with an 8 thread make (make -j8).
- Disabling the dphys-swap daemon, might save a few CPU cycles and free up a little RAM.
The point remains, if the swapfile exists but is not used at all nothing is gained by disabling it.
You have to assume it is used ineffectively / to no good purpose and at some cost to have any potential gain. You seem to be assuming it uses some CPU cycles and some RAM while not used.

Return to “Troubleshooting”