tags:
- gentoo
- linux
- operating-system
- hardware
- software
- notes
- article
source: https://wiki.gentoo.org/wiki/SSD
created: 2024-11-25
What does the term Solid State Drive (SSD) commonly refer to?
The term SSD commonly refers to flash-based block devices.
What does flash-based technology offer compared to Hard Disk Drives (HDDs)?
Compared to HDDs, flash-based technology offers:
- Faster access time.
- Lower latency.
- Silent operation.
- Power savings.
What does flash-based technology have despite its benefits?
Despite its benefits, flash-based technology has issues which require special system attention and care.
What do traditional filesystems do when deleting data?
When deleting data, traditional filesystems flag the data blocks as deleted but don't change the actual data.
What type of flash memory cell can write operations be perform on?
Write operations can be performed on empty flash memory cells.What must be done before a write operation can be done on memory cells which are flagged as deleted but aren't empty, and what effect does it have on performance?
Before a write operation can be done on memory cells which are flagged as deleted but aren't empty, the data must be erased which causes the performance to be slower.What other effect is there by keeping data that's flagged as deleted?
The other effect there is by keeping data that's flagged as deleted is less available empty cells.
What is possible with modern kernels in dealing with empty blocks?
In dealing with empty blocks, it is possible to hint the deleted, not-used data blocks to the SSD.
What is the mechanism called which hints the deleted, not-used data blocks to the SSD?
The mechanism that hints the deleted, not-used data blocks to the SSD is called discard.What are the names for the different implementations of the discard mechanism?
The names for the different implementations of the discard mechanism are:
- TRIM for ATAPI.
- UNMAP for SCSI.
- Deallocate for NVMe.
What is required in order to use discard?
In order to use discard, filesystem support is required.What modern filesystems support discard?
The modern filesystems that support discard include:
- ext4.
- XFS.
- btrfs.
- bcachefs.
What traditional filesystems have had discard support added to them?
The traditional filesystems which have had discard support added to them include:
- FAT.
- NTFS.
What are the two basic approaches to issue the discard command to the SSD?
The two basic approaches to issue the discard command to the SSD are:
mount -o discard
for continuous discard.fstream
utility.What should you keep in mind with the two approaches of issuing the discard command?
With the two approaches of issuing the discard command, you should keep in mind that not all filesystems support both.
What causes wear to a NAND flash cell?
Wear to a NAND flash cell is caused by each write operation.
What doesn't cause wear to a NAND flash cell?
Wear to a NAND flash cell isn't caused by read operations.
What's a basic method for increasing the lifespan of a Solid State Drive (SSD)?
A basic method for increasing the lifespan of an SSD is to uniformly distribute write operations across all blocks.
What is the method of distributing write operations across all blocks in a Solid State Drive (SSD) called?
The method of distributing write operations across all blocks in an SSD is called wear leveling.How is wear leveling deployed?
Wear leveling is deployed with SSD firmware.
What should be verified before performing any form of discarding on a drive?
Before performing any form of discarding on a drive, support for discarding should be verified.
What command can you use to verify if a drive supports discard?
The command you can use to verify if a drive supports discard is:
lsblk --discard
What do you check for in the output of the
lsblk --discard
command to verify that a drive supports discard?
To verify that a drive supports discard, check for non-zero values in theDISC-GRAN
andDISC-MAX
columns in the output of thelsblk --discard
.
lsblk --discard
commandNAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda 0 512B 2G 0
├─sda1 0 512B 2G 0
├─sda2 0 512B 2G 0
└─sda3 0 512B 2G 0
sdb 0 0B 0B 0
└─sdb1 0 0B 0B 0
What varies across different Solid State Drives (SSDs)?
The sizes of internal data structures, like blocks and pages, vary across different SSDs.
What should filesystem data structures not do for optimal performance?
For optimal performance, filesystem data structures shouldn't cross the boundaries of underlying SSD internal data structures.How do you ensure that filesystem data structures don't cross the boundaries of underlying Solid State Drive (SSD) internal data structures?
To ensure that filesystem data structures don't cross the boundaries of underlying SSD internal data structures, align the start of each partition, commonly to 1 MiB.
What two partitioning utilities support partition alignment?
The two partitioning utilities that support partition alignment include:
parted
.fdisk
.How do you use partition alignment with
parted
?
To use partition alignment withparted
, use the-a optimal
flag.How do you use partition alignment with
fdisk
?
To use partition alignment withfdisk
, simply use it as it's turned on by default.
How can you check the alignment for a given partition with parted
?
To check the alignment for a given partition with parted
, run parted /dev/<drive>
.
What program can you use to discard all data blocks on an entire device?
To discard all data blocks on an entire device, you can use blkdiscard
.
...
How do you allow discards to pass through full encrypted devices?
To allow discards to pass through full encrypted devices, they have to be opened by cryptsetup
with the --allow-discards
flag.
/dev/thing
while allowing discardscryptsetup luksOpen --allow-discards /dev/thing luks
What does enabling discards depend on if a root-device exists in the Linux Unified Key Setup (LUKS)?
If a root-device exists in the LUKS, enabling discards depends on the initramfs implementation.
What kernel option do you need to pass in order to enable discards in the generated initramfs depending on the initramfs implementation?
The kernel option that you need to pass in order to enable discards in the generated initramfs depending on the initramfs implementation is:
- genkernel -
root_trim=yes
.- dracut -
rd.luks.allow-discards
.How do you check if discard is enabled on a Linux Unified Key Setup (LUKS) device?
To check if discard is enabled on a LUKS device, rundmsetup table /dev/mapper/crypt_dev -- showkeys
and check the output for the stringallow_discards
.
How can you configure the filesystem to improve performance with a drive?
You can configure the filesystem to improve performance with a drive by aligning its data structures with the size of the drive's internal structures.
What can you do if you know the erase block size of a Solid State Drive (SSD)?
If you know the erase block size of an SSD, you can use it when creating the filesystem.
What does mkfs.ext4
apply to a drive when it is used on an average-sized partition?
On an average sized partition, mkfs.ext4
will apply 4KiB blocks to a drive.
What are the two options you use with
mkfs.ext4
to set the alignment to the erase block size?
To set the alignment to the erase block size, the two options that you use withmkfs.ext4
are:
-E stride=<stride in KiB>
.-E stripe-width=<stripe-width in KiB>
.Since
mkfs.ext4
applies 4KiB blocks to a drive, what value do you setstride
andstripe-width
in order for the filesystem to be aligned with the erase block size?
In order for the filesystem to be aligned with the erase block size, the value you setstride
andstripe-width
to is the erase block size of the drive divided by 4KiB.
mkfs.ext4 -E stride=128,stripe-width=128 /dev/sda3
...
What is the recommended way for using discard on the rootfs?
The recommended way for using discard on the rootfs is to periodically use the fstrim
utility.
What can potentially happen if you use the
discard
mount option with older, poorer-quality Solid State Drives (SSDs)?
If you use thediscard
mount option with older, poorer-quality SSDs, it can potentially cause degradation because of discard being done continuously.
What command do you run to perform a discard operation on the rootfs?
The command you run to perform a discard operation on the rootfs is:
fstrim -v /
What are the two ways you can use the
fstrim
command?
The two ways you can use thefstrim
command are:
- Manually.
- As a periodic job to run once a week.
What are some filesystem drivers that don't support
fstrim
?
Some filesystem drivers that don't supportfstrim
include:
- ntfs3.
- bcachefs.
When should it be safe to mount a Solid State Drive (SSD) with the discard
mount option?
It should be safe to mount an SSD with the discard
mount option if the mount point is going to have a low amount of disk writes occurring on it.
When is it recommended to mount a Solid State Drive (SSD) with the
discard
mount option?
It is recommended to mount an SSD with thediscard
mount option if maintaining performance is required.Where do you set the
discard
mount option for a drive?
You set thediscard
mount option for a drive in/etc/fstab
.What command do you run to remount all drives once
/etc/fstab
has been modified?
Once/etc/fstab
has been modified, the command you run to remount all drives is:mount -a
discard
mount option on a drive./dev/sda3 /mnt/archive ext4 defaults,relatime,discard 0 1
cron
to run fstrim
once a week on all mounted drives# Mins Hours Days Months Day of the week Command
15 13 * * 1 /sbin/fstrim --all
cron
to run fstrim
once a week on rootfs# Mins Hours Days Months Day of the week Command
15 13 * * 1 /sbin/fstrim -v /
...
...
...
What limited lifetime do flash-based Solid State Drives (SSDs) have?
The limited lifetime that flash-based SSDs have is the number of writes performed.
What can theoretically reduce writes to a Solid State Drive (SSD) when building packages with Portage?
When building packages with Portage, you can theoretically reduce writes to an SSD by performing the operations in RAM by using a tmpfs or zram mount.
What can you mount desired mount points as to reduce the amount of writes and improve performance?
To reduce the amount of writes and improve performance, you can mount desired mount points as tmpfs.
/tmp
and /var/tmp
as tmpfs in /etc/fstab
# temporal mountpoints on tmpfs
tmpfs /tmp tmpfs size=16G,noatime 0 0
tmpfs /var/tmp tmpfs size=1G,noatime 0 0
What does systemd do automatically with /tmp
?
With /tmp
, systemd automatically mounts it as tmpfs by default.
What should you make sure of when mounting /var/tmp
as tmpfs and why?
When mounting /var/tmp
as tmpfs, you should make sure that /var/tmp
is appropriately sized because Portage uses it and there will be build errors if the size is too small.
What is the alternative to tmpfs on modern, fast systems?
On modern, fast systems, the alternative to tmpfs is zram.
What programs often make frequent writes to cache?
Programs that often make frequent writes to cache include many programs that run with the X Window System.
What specification does the location of the cache directory usually adhere to?
The specification that the location of the cache directory usually adheres to is the XDG Base Directory Specification.
What is the name of the environment variable that determines the location of the cache directory under the XDG Base Directory Specification?
The name of the environment variable that determines the location of the cache directory under the XDG Base Directory Specification isXDG_CACHE_HOME
.What is the default cache location under the XDG Base Directory Specification?
The default cache location under the XDG Base Directory Specification is~/.cache
.
How do you remap the cache directory location so that it's mounted under a tmpfs?
To remap the cache directory location so that it's mounted under a tmpfs, create a script at /etc/profile.d/xdg_cache_home.sh
which exports the directory under run like so:
if [ ${LOGNAME} ]; then
export XDG_CACHE_HOME="/run/user/${UID}/cache"
fi
What utility can you use to relocate web browser profiles and cache to a tmpfs?
The utility you can use to relocate web browser profiles and cache to a tmpfs is www-misc/profile-sync-daemon
.
...
How do you set up profile-sync-daemon
for systems with OpenRC?
To setup profile-sync-daemon
for systems with OpenRC:
/etc/psd.conf
by adding or changing the variable USERS
to be ="usernames..."
. This variable determines which users on the system are going to have their browser profiles symlinked to a tmpfs.rc-update add psd default
.rc-service psd start
.How do you view all symlinks created by
profile-sync-daemon
?
To view all symlinks created byprofile-sync-daemon
, run:psd p
...