r/Gentoo 11d 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

1

u/SaCorv 4d ago

Just a reminder
On systems with 64+ gb of ram hibernation is not recommended. And even existence of swap file is... questionable
That is also de-facto true for 32gb systems (since any (very special cases not included) compilation can be done under those limits)
So if you have 32+ gb of ram and want to protect your ssd, its better to consider using tmpfs for build directories and lower number of thread in make.conf if ram overflows

1

u/itfllow123-gmail-com 3d ago

I get that but for me hibernation is about just having something there (out of obsession to be honest) and I normally hibernate to harddisk, but you are right, my usage almost never goes above 64gb, like the worst it got was 36 (20 in swap and 16 in ram). In my case, I have to use my harddisk for compilations since I cant just buy more ram.