2

I'm planning on installing Lubuntu (16.04 LTS 64-bit) on 2-3 older laptops with similar specs. They're all 2GB RAM (and are max'd out), and I'll use a 32GB SSD as the only drive. I have the same Lubuntu distro on one already which works great, but it's on a 256GB "spinny" drive. That drive has a 2GB swap partition.

My question is on swap partition and swap file, when moving to this SSD. I do not need hibernation. The computers won't see heavy use, and I'm not much concerned with SSD "wear" or lifetime. I'm most concerned with getting the best "user speed" on old machines with modest CPU's. Most usage is not very memory intensive, altho we'll occasionally open some big stuff in GIMP etc, which could max out the 2GB RAM.

After a bunch of searching + reading, it seems I'm best served by NOT using a swap partition, so my questions are:

  1. Does it seem best to go with no swap partition?

  2. If no swap partition- do I need to do anything to create a swap file, or will the normal Lubuntu install do it?

  3. I've read a lot about TRIM, noatime, + a couple other "tweaks" to make Ubuntu 'play nice' with SSDs -- however, a lot of the threads I found were years old, 2 or 3 or 7 or more years. Some threads say that recent Ubuntu distro's have things like trim + noatime built in, and take care of them automatically, so don't need the tweaks.

1
  • 2
    My personal recommendation would be to create a swap partition, but set the swappiness so that it only swaps out at the last second possible before you have an OOM kernel error. Jun 16, 2017 at 22:00

4 Answers 4

1

Swap files versus swap partitions:

Swap partitions can be used by two or more Linux installations on the same PC (e.g. dual boot).

Swap partitions are better in case the disk gets full. Swap files are subject to fragmentation. Swap partitions are not.

Swap files can be better if you need to change the size of the swap capacity since it is easier to resize the swap file than it is to resize the swap partition.

Operationally, swap files will work as well as swap partitions if they are created on non-full disks to avoid fragmentation.

Generally speaking, modern Linux systems typically employ swap partitions since high capacity storage devices are quite inexpensive.

4
  • Thx much, that is very helpful+clear. I also found this- help.ubuntu.com/community/SwapFaq which also helped fill in. One more question- when a system runs out of swap space, can it just drop pages out of RAM, + then retrieve them again from the HD, which of course is slow relative to RAM? Or will running out of swap + dropping pages from RAM usually or always crash the system, or at least the application? - Thx.
    – chriss
    Jun 17, 2017 at 2:27
  • I appreciate the positive response. You've asked numerous, different questions in this single thread. The protocol here is to ask one question for each issue you have. They are clear that this is not a forum. It's a method of building a knowledge base. Best to accept an answer that you think most closely addresses your original question and then open new questions if you want to ask about different matters. It's also polite to upvote any answer or comment that adds value to the search for knowledge. We can chat on IRC if you'd care to talk about swap in depth.
    – jones0610
    Jun 17, 2017 at 2:33
  • Thx for tips on how to use this site ... noob. I have now accepted + upvoted this answer, altho I received a dialog saying that upvotes from users with <15 rep are recorded but don't change the publicly displayed post score. Sorry for that situation, and again appreciate your help. I'm not on IRC chat so can't take advantage of your kind offer. I'll open a separate thread on the follow-on question. Thx much.
    – chriss
    Jun 17, 2017 at 4:19
  • Happy to help. If you plan to stick with Ubuntu you may find the IRC forum to be helpful. It's a lot more informal although the quality of the answers you'll get here are usually a lot better. There is a dedicated #Ubuntu group there.
    – jones0610
    Jun 17, 2017 at 4:22
1
  1. In 16.04.x LTS I would create a swap partition 1 GB or 2 GB, 'just in case' to avoid crashes in the few cases when the RAM is not enough. Edit: Set the swappiness value so it only swaps at the last second, as suggested by @AndroidDev (for example 10 instead of default 60) according to this link: How do I configure swappiness? | Ask Ubuntu

  2. The newest version of Lubuntu will create a swap file instead of a swap partition by default. But it is a short-life version, and I would recommend the LTS version. You can create a swapfile instead of a swap partition, if you wish, but I would not do it.

  3. I think TRIM is used automatically, when the drive is connected via SATA or eSATA, but maybe not via USB (unless built-in in the SSD itself).

    I am rather sure that you have to configure noatime yourself, but it is easy. You can also consider turning off journaling (which has both advantages and disadvantages). See this link: Final system tweaks / Installation / UEFI-and-BIOS | Ubuntu Community Help Wiki

3
  • 1
    Again, I'd suggest setting the swappiness value so it only swaps at the last second. The default value is quite eager to swap. Jun 16, 2017 at 22:07
  • Thx for coming back on it. I understand the value of setting swappiness down, I'm thinking 10 or so. In regard to swap partition vs swap file: I'd like to understand the differences more. Especially, if there's a way to make a swap file's size dynamic, that would be valuable since the 32GB SSD isn't big. What leads you to prefer the swap partition, over the swap file?
    – chriss
    Jun 17, 2017 at 1:36
  • The standard in version 16.04 LTS is a swap partition and it works well. I don't think it is worth the extra trouble to create a swap file, but an advantage might be that you can easily(?) remove a swap file and create a new one that we can hope will be located in a fresh physical location (to spread the wear of memory cells). But if the swapping will only be used in rare occasions, it should not be important. (I don't know about dynamic swap file size in linux.)
    – sudodus
    Jun 17, 2017 at 5:17
1

With Lubuntu 18.04, 2Gb and the zram „swap“ option (which is not actually a swap), I still avoid swapping to an actual SSD. Even in GIMP.

I also keep /tmp, /run and /var/log on ramdrives (tmpfs), and have ext2 (noatime, nodiratime) instead of ext4 in order to avoid constant journal updates.

But I can say I encounter the out-of-memory problems from time to time. Rarely, but they're happen.

This is my fstab:

UUID=blablabla   /         ext2    errors=remount-ro,noatime,nodiratime 0       1
#/swapfile       none      swap    sw                                   0       0
tmpfs            /tmp      tmpfs   rw,size=128m                         0       0
tmpfs            /run      tmpfs   rw                                   0       0
tmpfs            /var/log  tmpfs   rw,size=32m                          0       0
0

You've asked several questions.

Trim: You definitely want to have this enabled and operational. Trim support has been in Ubuntu for a while but depending on the SSD Manufacturer, it may or may not be enabled on your machine. This is simple to accomplish and there are a few very good answers on this site that address how to do it.

As a learning tool, installing Ubuntu on your old gear is a worthy project. However with only 2 GB RAM you will likely find the laptop(s) to be unacceptably pokey. Especially using Gimp which uses a lot of CPU and graphics power to render images.

Creating a swap partition on the SSD will provide better performance than doing so on a HDD. And with only 2 GB of RAM, you can expect a fair amount of swapping which, in itself, will adversely effect performance.

Your comment about RAM being "max'd out" implies that there is more on this laptop than just a sole instance of Lubuntu. Milking every possible cycle out of your equipment is a noble undertaking but if you are talking about a Hypervisor or other software / OS, you may be pushing this poor old laptop a bit too hard.

3
  • Thanks for responding. To clarify about the machines and RAM:
    – chriss
    Jun 17, 2017 at 1:39
  • Thanks for responding. To clarify about the machines' RAM: I meant to say that max RAM capacity is 2GB, + 2GB is already installed. On performance: both small netbooks that are convenient for travel. I understand they will still be limited by CPU, RAM, + a number of other constraints. So I'm aiming to learn about tradeoff's between swap partition vs swap file - which makes the most of the limited CPU + SSD storage space. If a swap file can be dynamically resized, that's valuable on the small SDD. And if a swap file makes sense, how to I create it? Thanks again.
    – chriss
    Jun 17, 2017 at 1:51
  • askubuntu.com/questions/491916/…
    – jones0610
    Jun 17, 2017 at 1:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .