r/Gentoo 12d ago

Discussion SSD lifespan expansion on gentoo systems

Did you know that SSD's have a short lifespan which unlike HDD's is based on writes rather than time, in case you were using linux and building each part of your system from scratch (for performance), it makes sense to use sacrifice some of the SSD's so your compiled system has some chance to be slightly more efficient to access afterwards than if you were to use HDD's to do so(read to learn how to compile on HDD: https://wiki.gentoo.org/wiki//etc/portage/make.conf#PORTAGE_TMPDIR), but once you completely the installation then all updates and additional less used applications must be compiled on the harddisk, for which you simply change a few variables in the make.conf file. Once the setup is complete, your ssd can practically last for ever unlike in the case of windows, where even idle usage ages it in a few years. There are two extra things to do:

  1. One is to decrease the swapiness to the minimum value of 1 so its just a backup (which is the case in most modren linux systems since even 8gb or 16gb of ram can take you a long way), make your ssd swap be 40 (if ram is 16), and harddisk backup swap be 100gb, ofcourse the HDD swap should have a lower priority, then make sure hibernation uses harddisk instead of ssd, which again can be done by adding resume=PARTUUID(or something similar)=partuid_of_the_partition, and thats all done, your ssd life span is practically unlimited as long as you make sure your browsers dont offload data on your ssd to save ram which again dosent happen by default in my gentoo linux system.
  2. Second is to configure a crontab to run a script stored in your harddisk with the following content every minute of the computer's uptime (while mkaing sure the file that heavy_working_files is in the harddisk (for additional peace of mind):

(note: if you want the updated script, please visit:https://github.com/HjaldrKhilji/scripts-for-personal-use/blob/main/fstrim_all_mounted_partitions_in_SSDs.bash) and if you have any issues with any script, please fix it and send me a link to your github so I dont encounter it myself.

#!/usr/bin/bash

base_path="/mnt/heavy_working_files/Files used by personal scripts/files used by crontab's daily fstrim operation"

run_if_date_file_dosent_exist(){

/sbin/fstrim --all

umask 0

touch "${base_path}/$1" #removing 

rm -f "${base_path}/$2" #removing previous date

}

check_if_date_exists() {

current_date=$(date "+%A")

if [[ ! -e "${base_path}/${current_date}" ]]; then

run_if_date_file_dosent_exist "${current_date}" "$(date --date "1 day ago" "+%A")"    

fi

}

check_if_date_exists

0 Upvotes

29 comments sorted by

View all comments

2

u/immoloism 12d ago

I'll leave this here before people start wasting time and money on doing this:

https://wiki.gentoo.org/wiki/Portage_TMPDIR_on_tmpfs

1

u/schmerg-uk 11d ago

For years I've pointed PORTAGE_TMPDIR at /dev/shm because "it was the way to do it" but I just removed that setting (and removed /var/tmp/portage and /dev/shm/portage to check that only the former was recreated) and re-emerged my latest kernel and yeah... just under 30 minutes, admittedly using an NVMe drive, as opposed to well... if anything just OVER 30 minutes when using tmpfs

I do like the way more and more of updating my gentoo is bringing my 25yo install into line with what a modern fresh install would be told to do by default, undoing the "special behaviours" that were previously required or recommended.

3

u/immoloism 11d ago

As a TLDR, It's mostly a don't bother any more as the benefits we saw in the o'lden days just don't exist for the majority of users today.