To avoid writing so much on my SSD I’ve moved the swap partition to a 32 GB drive which goes for $7 nowadays and if it dies it won’t hurt unlike if the SSD dies.

I’ve also lowered the swappiness from 60 to 10.

I assumed it would be faster on a USB than on the hard drive. Was this a good idea?

Flashdrives die sooner than good quality SSDs, but in general are at least a bit more resilient than microSD cards. Even I’m considering starting to use a small USB pen as extra swap space for my Raspberry Pi 3; for what they cost, even if they will eventually break, they are good value.

Why is it slow for you? Here are some things to consider:

  • USB speeds: USB as a protocol is generally slower than SATA, even version 3. If your drive or your port are 2.0, then you will deal with a theoretical max bandwidth of 480 mbps (but the practical one is much lower!). If they are 3.x, check that the flashdrive makes proper contact in the port with not only the main big 4 pins, but also the small pins hidden deeper inside the connector (I have no idea how on Linux tho :/); most USB A 3.0 connectors and ports have issues connecting together for some reason, and it may happen that the SuperSpeed pins can’t get close and thus the connection will degrade to 2.0 speeds.

  • Cheap chips (pun intended): Cheap USB pen drives nowadays use both low-quality controller chips and memory chips. From experience I can say that some inexpensive modern flashdrives that are sold as USB 3.0, and get connected as 3.0 to an host system, actually work at around 2.0 speeds. Why? Sometimes it’s because low-quality memory chips are used, that won’t work properly if accessed with high speeds, and thus the controller chips in the drives are programmed to limit read/write speeds… some other times, the controller chip is also crappy, and transfers slow down because it overheats. Also, bandwidth is not the only thing that suffers: on cheap flashdrives you can experience high latency.

Both limited bandwidth and high latency impact a lot when you use any storage medium for OS or program storage, or even swap memory. If you want some decent but easy to read statistics to test those values (with graphs too), install GNOME Disks and use its disk benchmark tool. You can verify how well your USB pen drive performs, and even compare it to your SSD.

As a side note, from most of my flashdrives (including one which connects via USB 3.0) I always get no more than 15 MB/s read + 5 MB/s write… that’s a practical speed of 160 mbps, a mere 1/3 of the theoretical for 2.0.

Kromonos
link
fedilink
22M

Wouldn’t it make more sense to get a small SSD instead of a USB stick and connect it via USB using an external enclosure? There shouldn’t be much difference regarding performance, but there should be in lifespan. You could also split partitions up and use the free space for other things.

On the Pi I already use an HDD for data and most of my programs, plus some megabytes (64 today, yesterday it was 32) of swap in addition to the 128 MB I have on my slow microSD, (which apart from that only holds the base system, really).
Considering that an SSD on the Pi3 is wasteful due to the USB 2.0 limit, that I don’t have any spare, and that the smallest SSD I can find (128 GB) is still at least twice the cost of my 320 GB HDD, guess what 2.5" external drive I’ll keep as main currently.

System and programs aren’t running slow right now, so, since I need more swap, I could try adding some more on the HDD, and only then actually try pendrives, just for 1 o 2 GB of swap at max. I can add them, since I have some spare and they are cheap to get anyways.

But yeah, if I had USB 3.0 on a SBC with 1 GB of RAM, I would get the SSD.

poVoq
link
fedilink
42M

Just disable swap? It works perfectly fine without it if you have more than 8GB RAM or so.

Amicese
link
fedilink
22M

What if they don’t have that much RAM?

ronny
link
fedilink
22M

@Amicchan @poVoq planning RAM with included swap is never a good idea. Swap is great for virtually upgrading your ‘useable’ RAM from the Software Perspektive, but the reason for using it by design makes no sense to me. Even on really fast NVME drives saving memory temporally to disk will be noticeable, at least at the system load.

poVoq
link
fedilink
2
edit-2
2M

First I would configure some zram then (ram compression). And then I would upgrade my PC to have more RAM :p

krolden
link
fedilink
2
edit-2
2M

You should look into enabling zram swap

https://wiki.archlinux.org/title/Improving_performance#zram_or_zswap

Usb flash is slower than sata flash which is slower than ram cache.

@flux@lemmy.ml
link
fedilink
1
edit-2
2M

Maybe instead of moving swap to a USB stick for to preserve SSD longetivity you should monitor your SSD wear with smartctl? You may discover that you won’t be consuming a lot of it, compared to what the spec for the SSD gives you (TBW, terabytes written, is a metric to watch for).

In addition you can also install a tool such as sar (from sysstat package) to track how much you’re writing in to the SSD. You may discover that it’s not a lot.

Byte
link
fedilink
12M

@OptimusPrime this requires a fast usb, but isn’t then the usb more expensive then additional RAM would be?

jdw
link
fedilink
12M
ronny
link
fedilink
12M

@OptimusPrime no. Only for raising the virtual size of available RAM, but not for using.

@OptimusPrime That’s an interesting idea. Sadly I have no idea if it’s a good or a bad one. :P

I would guess though that swap partitions/files and SSD’s have a lot of failsafes and various features to lengthen the life of the SSD. I doubt USB drives and such have the same kind of features though as this is not a common usecase. But this is all just an uneducated guess by me.

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word “Linux” in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

  • Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
  • No misinformation
  • No NSFW content
  • No hate speech, bigotry, etc

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

  • 0 users online
  • 2 users / day
  • 15 users / week
  • 55 users / month
  • 231 users / 6 months
  • 13 subscribers
  • 476 Posts
  • 1.12K Comments
  • Modlog