SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've run without swap since I started using SSDs and had enough RAM to not need it. It's not required for memory-sleep which I use on this machine multiple times a day. This is one current (12C/24T) slackware machine:
Code:
notzed@shitzone:~$ free
total used free shared buff/cache available
Mem: 32834960 6963784 12213896 117208 13657280 25081600
Swap: 0 0 0
notzed@shitzone:~$
All you do is not setup a swap partition and ignore any warnings about it during setup.
I only installed swap on my (8C/8T) laptop because memory-sleep doesn't work due to a broken BIOS (sigh, clevo) and it is required for disk-sleep (hibernate). And needing that 32GB of swap was a huge cost out of the ~200GB SSD I got it with and in part forced me to upgrade to a 1TB - and it's still a costly chunk out of that. So in practice it's just a huge waste of storage and almost never gets used apart from hibernate - currently sitting at 200MB used despite running a gentoo update which is by far the heaviest load it ever faces. The whole machine didn't even get over 2GB RAM/5GB cache used until it compiled firefox - after 33 other packages and hammering all 8 cores - and even then it only peaked around 10GB RAM/10GB cache.
There's certainly workloads where it will be beneficial to have it because it opens up more effective RAM if there are many stale pages and idle processes, but for a typical single-user desktop with >=16GB RAM it isn't likely to do much if anything. Take the recommendation above about 1GB swap for example, if you have 32GB of RAM another 1GB available at most is SFA and effectively irrelevant. If you've used enough of your RAM for that amount to matter then you already need more of it! Even 1GB is quite a lot of stale daemons for a single-user desktop, the large spikes you get will be for transient operations like compiling rust or c++ concurrently across many cores so increasing swap is unlikely to effectively increase your RAM further. Yes you will be able to more before running out of it but as soon as the working set needs to swap in and out you will be in a world of pain (i've had to just hit the power button in the past since the kernel just can't seem to recover some times, beware of low swappiness values too).
There's a lot of cargo cult nonsense with computers in general and especially for things like swap, and someone like Chris Down will recommend it because both he's worked with the code and because he knows all the sound technical reasons it absolutely does make good sense. But due to changes in the baselines of modern hardware (i.e. gobs of RAM) those technical reasons don't always have any practical impact*.
* You know, depending on use-cases and work loads and so on and so forth.
If you are on a SSD, you should not use hibernation, sleep works fine.
Why? Suspend still uses power and may not be ideal depending on your situation.
If you're worried about NAND wear limits, it is very unlikely for anyone to run them on any modern SSD/NVMe device. I've been using my current NVMe drive since 2017, with the root partition, /tmp/, /var/, /home/, and a swap partition all on the same drive (4 separate partitions for the root partition, /home/, EFI, and swap) and I'm only at like 4% of wear. I do a *lot* of compiling on this system and have written 25TB to the device so far (that's an average of 13GB per day... the equivalent of a whole install of Slackware every single day for 5 years). It's rated for 400TB of written data, however, most drives will go far beyond those limits. Even if I just went to the 400TB limit, I could go an additional 34 years if I maintain the same data writing as the last 5 years. This is on 5 year old hardware, so newer hardware will have even higher limits.
Even with 100GB/day, the drive would still last almost 11 years... far beyond the likely usefulness of the device. Especially considering the massive price drops these have had over the last few years. When I bought my Samsung EVO 1TB NVMe drive 5 years ago, it was $500US. The newest generation of Samsung EVO 1TB NVMe drives now go for like $150US.
People can stop babying NAND devices. Use and abuse them to benefit from the massive speed gains over platter harddrives and you'll never hit the NAND wear limit.
Quote:
Originally Posted by jmccue
IIRC, sleep is "suspend to RAM", so I very much doubt swap is needed for sleep.
Correct. If you simply suspend, swap is not needed. Power to the RAM is maintained to keep it active until the battery is depleted, then all data in RAM is lost and it will be a fresh boot when you start it back up (unless the system automatically hibernates when power is low). Hibernation fully powers off the computer, so the contents of RAM need to be transferred elsewhere, which for Linux is typically a swap partition or file. This allows the current session to be saved indefinitely.
I've run without swap since I started using SSDs and had enough RAM to not need it.
You may not need it, but the system can still benefit from it.
Code:
jbhansen@craven-moorhead:~$ free -h
total used free shared buff/cache available
Mem: 62Gi 21Gi 491Mi 312Mi 40Gi 40Gi
Swap: 15Gi 1.6Gi 14Gi
I have an 40GB of RAM effectively available, but the kernel still decided to swap 1.6GB of data. I assume kernel devs know how to best utilize my hardware when it comes to memory usage.
Why? Suspend still uses power and may not be ideal depending on your situation.
Correct. If you simply suspend, swap is not needed. Power to the RAM is maintained to keep it active until the battery is depleted, then all data in RAM is lost and it will be a fresh boot when you start it back up (unless the system automatically hibernates when power is low). Hibernation fully powers off the computer, so the contents of RAM need to be transferred elsewhere, which for Linux is typically a swap partition or file. This allows the current session to be saved indefinitely.
It drains 2 or 3% of the battery per hour here (vs. 0% during hibernation)
So, for me, hibernation is not an option
This is my use case on my desktop. This is after 22:50 of uptime.
Code:
free -h
total used free shared buff/cache available
Mem: 7.8Gi 2.7Gi 1.8Gi 87Mi 3.4Gi 4.7Gi
Swap: 8.1Gi 1.1Gi 7.1Gi
I always end up with swap being used at one point or another. This is from lots of Firefox video watching, virtualBox and compiling during the 22:50 period.
My laptop after a power on.
Code:
free -h
total used free shared buff/cache available
Mem: 3.7Gi 134Mi 3.2Gi 1.0Mi 406Mi 3.4Gi
Swap: 2.0Gi 0B 2.0Gi
I use hibernate on this laptop. I use append="resume=/dev/sda1" in the kernel images section of lilo.conf
With my four Slackware VirtualBox machines I do not use swap.
Last edited by chrisretusn; 04-12-2022 at 03:51 AM.
Not sure what memory fragmentation has to do with swap, to be honest. Memory fragmentation happens within a specific address space, and no amount of swapping will help alleviate it. Keep in mind that we’re talking virtual addresses here, not physical RAM addresses. If fact, a chunk of memory that was allocated by a process (and, therefore, is located at a specific virtual address in the address space of the process) may be swapped out and, consequently, not even have a physical address in RAM at any point in time.
What does “memory fragmentation” actually mean, then?
Well, let’s, for example’s sake, assume for a moment that you are running a certain computer architecture that provides each process (i.e., roughly, each running program) with a (virtualised) RAM address space of 100 MiB. Program “A” keeps allocating chunks of memory, 1 MiB at a time, until it fills up its 100-MiB address space. It has now fully allocated 100% of its address space. Next, it begins to free up every other 1-MiB chunk of memory that it allocated, freeing up a total of 50 chunks, which amounts to 50 MiB. It now has 50% of its address space in use, and the other 50% is free. However, the largest available consecutive chunk of memory is just 1 MiB. Next, it attempts to allocate a 2-MiB chunk. Well, no matter how hard it tries, a 2-MiB chunk won’t fit in any of the 1-MiB chunks that it has at its disposal. No amount of swapping will help, either: the address space is 50% full, and 50% empty, but the biggest empty chunk is and will remain just 1 MiB in size.
All the while, a Program “B” (which has its own 100-MiB virtualised RAM address space available to play with) may have allocated a single chunk of, say, 60 MiB. It still has 40 MiB of free memory, most likely in one 40-MiB chunk (in theory, the memory allocator could have placed the 60-MiB chunk somewhere in the middle of the 100-MiB address space, but, for simplicity’s sake, let’s assume it didn’t do that). It now needs another 10-MiB chunk. No problem: the biggest (and even, the only) chunk of free memory that it has at its disposal, is 40 MiB in size, from which a 10-MiB chunk can easily be taken.
I've not used swap for the last 10 years. No issues at all. In fact I always mount /tmp as a tmpfs (to use more the RAM), this makes things like compiling really fast. Why, just because now computers have a lot of RAM.
I don’t use swap, either, with no noticeable ill effects. My computer has 32 GiB of RAM and, on the Slackware partition that I use to build packages from SlackBuilds, I mount “/tmp” as a 24-GiB tmpfs. I can compile the “gcc5” package just fine that way. I do realize that I may run out of memory some day, when building a really, really,really humongous package, but so be it. In fact, let’s agree that I’ll post here about it when it happens.
Quote:
I don't hybernate my laptop. My laptop can be suspended for a couple days without problem. If I'm going to power it off for more time I just shut it down, but I don't remember the last time I needed to do that.
I’m not that much of a laptopper anyway, I’m mostly using a desktop computer. I don’t hibernate or suspend or let my computers go to sleep or whatever, I simply perform a shutdown when I’m done. Works more than good enough for me, but: “Your Mileage May Vary”.
Consider my system having 4gb ram. It is recommended to have 4 gb swap (as per rhel documentation).
I have possibility of increasing it to 8 gb.
Now, in case I increase it to 8 gb, does my swap need disappear?
If no, what could be the reason?
If no, is it possible to set swap as "in-memory"? If yes, and I set it as 4gb swap, then my system will again be 4gb for OS + 4 gb for swap.
It drains 2 or 3% of the battery per hour here (vs. 0% during hibernation)
So, for me, hibernation is not an option
Wait, so your reason to not use swap is because saves more power?
Quote:
Originally Posted by USUARIONUEVO
I never use swap , dont like see my ssd used as ram to read/write , and nothing fails or im not see.
Why wouldn't you want to use the second fastest storage on your system for fast read/write? It is pretty much impossible to exceed the write capacity of modern NAND without purposefully finding a way to do it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.