SWAP...Datei oder Partition ? Größe? Warum SWAP benutzt bei viel freiem RAM?

Liebe Manjaro-Gemeinde,

da ich die nächsten Tage eine Neuinstallation vornehme folgende Frage an die Experten:

Früher hatte ich immer 4 Partitionen gemacht…
/boot
/
/SWAP
/home
…bei dem letzten Rechner (mit SSD) habe ich die SWAP-Partition weggelassen…und stattdessen ein SWAP-FILE erstellt. Ich hab sehr viel gelesen…zumeist von den Vorteilen SWAP als FILE zu nutzen (veränderbare Größe schnell machbar ohne Partitionen zu verändern)…meine Fragen deshalb an die Experten:

  1. gibt es irgend einen Vorteil, SWAP als “Partition” zu nutzen statt als File?
  2. Diese Frage bezieht sich auf einen T420s ThinkPad…ich nutze den Rechner NUR für Office und Surfen (wobei es manchmal vorkommen kann daß ich 100 Tabs auf habe)…und Email… Fotos angucken…also NICHTS sehr SPEICHERINTENSIVES…der Rechner hat 16 GB RAM…ab und an gucke ich auf Conky…wenn ich viele Tabs offen habe…sind dann so 6 oder 8 GB belegt…gebe ich im Terminal swapon ein…zeigt er mir manchmal 0 an…manchmal aber auch 700 oder 800 MB…SWAP-Belegung…obwohl noch 7 GB reiner RAM-Speicher zur Verfügung stehen…weiß jemand eine Erklärung dafür? Weshalb greift der Rechner auf die “Notlösung” SWAP zurück…mit “nur” 800 MB…obwohl im viel schnelleren RAM noch 7 oder 8 GB RAM zur Verfügung stehen?

Also keine “wichtige” Frage…denn alles läuft bestens…aber ich hab bislang noch keine Antort gefunden…vielleicht weiß hier jemand Bescheid? :wink:

…ach so…letzte Frage…die SWAP-Größe…früher war ja die Faustregel 2x RAM-Größe?!? Wegen SUSPEND/HIBERNATION…BEIDES nutze ich NICHT…bei 16GB RAM habe ich 10 GB als swapfile…wäre eine angemessene Größe?

Habe 32 GB und gar keinen Swap, keine Probleme.
Nutze aber Hibernate/Standby nicht da mein System in etwa 10 Sekunden hochgefahren ist.
Swap-Partition hat bei ssds viele schreib/lese Zugriffe auf den selben Bereich. Das könnte die ssd früher killen, darum nutze ich es nicht.

2 Likes

I hope you understand English, because my German is very bad… :frowning_face:

There is an advantage, yes, because a swap file has to be accessed through the filesystem layer ─ and poses restrictions on filesystem-specific optimizations, e.g. no copy-on-write or compression when the swap file lives on a btrfs volume ─ while a swap partition can be accessed by the kernel directly.

On the other hand, swap files are more flexible, as you don’t need to create a fixed-size swap partition during installation.

Web browsers are notorious for consuming memory, and especially with multiple tabs open. The kernel will then swap out unused memory pages in order to make more room for cache. However, you can tune the swappiness of the kernel ─ see this German page at the Arch Wiki.

That said, I too have 16 GiB in my machine here ─ this is a desktop ─ and I have disabled all swap. And it’s running just fine without it. :wink:

In order to disable swap, comment out the line for the swap partition in /etc/fstab, and remove the resume=UUID line from /etc/default/grub, followed by… :arrow_down:

sudo update-grub

Also make sure that systemd-swapd.service is disabled… :arrow_down:

sudo systemctl disable --now systemd-swapd.service

Note: Without swap, you will not be able to hibernate your system, so this is something you should consider.

2 Likes

Hi pappi,
danke für Deine schnelle Antwort! Genau wie ich…Hibernate/Standby nutze ich auch beides nicht…das mit den Lese-/Schreibzugriffen stimmt…aber…der Rechner macht es ja nur (do denke ich) wenn er den Zwischenspeicher dringend braucht…hab jetzt ne neue Micron 1300 SSD mit 1TB…ich glaub da ist genug Platz für eine lange Lebensdauer…aber ich bin da auch so…habe sicherheitshalber bei Firefox die Speicherung der Daten von 15 Sekunden auf 10 Minuten erhöht…fühlt sich besser an…aber ich glaub eigentlich bei den neuen großen Platten spielt das keine Rolle…?!?

Hi Aragorn,
thanks for your fast reply! But there is still the question…why does…for example a browser…use the SWAP-SPACE instead of RAM? I’ve the same experience as you…I’ve installed…all fine…but I’ve forgot to activate swap via systemd…for weeks…and…no problem or slow speed occured…everything was fine as it is now with swap activated…!!! But why then SWAP?

2 Likes

Hi freggel.doe,

thanks for your reply! I will study your link tomorrow carefully!

It’s not the browser that uses swap. The browser uses virtual memory, and virtual memory is comprised of both RAM and swap, but the browser doesn’t know which is which. It simply uses a memory address space.

The application ─ in this case, the browser ─ requests an amount of memory from the kernel, and the kernel provides it with an address space. However, browsers are memory-hungry, and so that means that when you’ve got a browser with lots of tabs open, there will be less free RAM available.

Now, the kernel also uses RAM for caching, which it does for improved performance ─ the more data resides in the cache, the less data has to be read from the drive, which is always going to be a slower process than fetching the data from the RAM.

Therefore, if you have an active swap partition, then the kernel will free up some of the RAM again for caching by temporarily moving unused memory pages from RAM to the swap partition until they are needed again.

It’s all about optimizing performance. :wink: