Is TRIM enabled on my Ubuntu 18.04 installation?How to enable TRIM?It is necessary make some extra configuration to install Ubuntu 18.04 on a ssd?How to properly TRIM an ssd (18.04)Enable TRIM on secondary, encrypted ssdWill be TRIM enabled by default?Disable TRIM to avoid file system corruptionIs TRIM enabled/supported for this eMMC?LVM encrypted LUKS on SSD - issue reverting to snapshotsOn Ubuntu 16.04, with Samsung 850 EVO SSD, is any post configuration needed?Lights on TRIM in 14.04.5How to properly TRIM an ssd (18.04)
Is there a simpler way to write the limit I need?
Where is the Windows license key on win 10?
Could a technologically advanced society exist as a feudal monarchy?
How can an employer better accommodate workers on the autism-spectrum to reduce absence from work?
Learn university maths or train for high school competitions: which is better?
Controlling a robot blindfolded on a 9x9 grid
How do you remove an xz extension?
Debian not showing all cores?
How to move directory into a directory with the same name?
How many times, are they multiples?
Is Bitlocker secure enough for portable storage devices?
Is it possible for a moon to have a higher gravity than the planet it is attached to?
CE amplifier non-sinusoidal signals
Why is the risk premium always positive for risk averse individuals?
What does this "ICAgICAg…" mean in public key certificates and messages?
Is the "p" in "spin" really a "b"?
Shall I disable triggers in testing data setup phase?
Does an action-reaction pair always contain the same kind of force?
How to participate in group conversations as an outsider?
tikz: how not to draw border of a shape?
Why is the 'anti' in 'anti-semitism'?
Correct word for "the law does not allow for that"
What happens if bite wound abscesses in cats left untreated?
How would a cephalopod-like race breathe outside of water?
Is TRIM enabled on my Ubuntu 18.04 installation?
How to enable TRIM?It is necessary make some extra configuration to install Ubuntu 18.04 on a ssd?How to properly TRIM an ssd (18.04)Enable TRIM on secondary, encrypted ssdWill be TRIM enabled by default?Disable TRIM to avoid file system corruptionIs TRIM enabled/supported for this eMMC?LVM encrypted LUKS on SSD - issue reverting to snapshotsOn Ubuntu 16.04, with Samsung 850 EVO SSD, is any post configuration needed?Lights on TRIM in 14.04.5How to properly TRIM an ssd (18.04)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I know that weekly TRIM is enabled by default from 14.10 onwards. Source: How to enable TRIM?
But running sudo nano /etc/cron.weekly/fstrim
returns an empty file. Also tail -n1 /etc/cron.weekly/fstrim
says that this file does not exist.
Running lsblk -D
returns non zero values for DISC-GRAN
and DISC-MAX
so TRIM is supported on my SSD. Is weekly TRIM actually enabled for my SSD or not?
I am using a Kingston SSD
18.04 ssd trim
add a comment
|
I know that weekly TRIM is enabled by default from 14.10 onwards. Source: How to enable TRIM?
But running sudo nano /etc/cron.weekly/fstrim
returns an empty file. Also tail -n1 /etc/cron.weekly/fstrim
says that this file does not exist.
Running lsblk -D
returns non zero values for DISC-GRAN
and DISC-MAX
so TRIM is supported on my SSD. Is weekly TRIM actually enabled for my SSD or not?
I am using a Kingston SSD
18.04 ssd trim
add a comment
|
I know that weekly TRIM is enabled by default from 14.10 onwards. Source: How to enable TRIM?
But running sudo nano /etc/cron.weekly/fstrim
returns an empty file. Also tail -n1 /etc/cron.weekly/fstrim
says that this file does not exist.
Running lsblk -D
returns non zero values for DISC-GRAN
and DISC-MAX
so TRIM is supported on my SSD. Is weekly TRIM actually enabled for my SSD or not?
I am using a Kingston SSD
18.04 ssd trim
I know that weekly TRIM is enabled by default from 14.10 onwards. Source: How to enable TRIM?
But running sudo nano /etc/cron.weekly/fstrim
returns an empty file. Also tail -n1 /etc/cron.weekly/fstrim
says that this file does not exist.
Running lsblk -D
returns non zero values for DISC-GRAN
and DISC-MAX
so TRIM is supported on my SSD. Is weekly TRIM actually enabled for my SSD or not?
I am using a Kingston SSD
18.04 ssd trim
18.04 ssd trim
edited Mar 21 at 9:22
woohoo
1859 bronze badges
1859 bronze badges
asked May 9 '18 at 18:11
m.umarm.umar
4951 gold badge4 silver badges7 bronze badges
4951 gold badge4 silver badges7 bronze badges
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
Trim (fstrim/discard) is enabled to run weekly by default in 18.04.
It is set to run for all mounted filesystems on devices that support the discard operation.
It is a systemd
service managed via systemctl
, not CRON.
View fstrim.timer status:
$ systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
Loaded: loaded (/lib/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Thu 2018-07-05 05:45:11 BST; 4h 42min ago
Trigger: Mon 2018-07-09 00:00:00 BST; 3 days left
Docs: man:fstrim
Start/Stop/Restart fstrim.timer:
(does not change startup status)
$ sudo systemctl [start/stop/restart] fstrim.timer
Enable/Disable fstrim.timer:
(add to/remove from startup, does not change current active status)
$ sudo systemctl [enable/disable] fstrim.timer
View fstrim.timer configuration:
$ systemctl cat fstrim.timer
# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.target
View fstrim.service configuration:
$ systemctl cat fstrim.service
# /lib/systemd/system/fstrim.service
[Unit]
Description=Discard unused blocks
[Service]
Type=oneshot
ExecStart=/sbin/fstrim -av
Note: ExecStart=/sbin/fstrim -av
Where:
-a, Trim all mounted filesystems on devices that support the discard operation.
-v, Verbose execution. Output the number of bytes passed from the filesystem down the block stack to the device for potential discard.
View related systemd journal entries:
$ journalctl -u fstrim.timer
Jul 04 14:18:41 user-laptop systemd[1]: Started Discard unused blocks once a week.
Jul 04 21:59:26 user-laptop systemd[1]: Stopped Discard unused blocks once a week.
etc...
$ journalctl -u fstrim.service
Jun 25 10:59:44 user-laptop systemd[1]: Starting Discard unused blocks...
Jun 25 10:59:48 user-laptop fstrim[955]: /: 92.5 GiB (99335237632 bytes) trimmed
Jun 25 10:59:48 user-laptop systemd[1]: Started Discard unused blocks.
-- Reboot --
Jul 02 04:27:41 user-laptop systemd[1]: Starting Discard unused blocks...
Jul 02 04:27:46 user-laptop fstrim[1032]: /: 92.3 GiB (99150807040 bytes) trimmed
Jul 02 04:27:46 user-laptop systemd[1]: Started Discard unused blocks.
etc...
2
For reference, the when is controlled by/lib/systemd/system/fstrim.timer
(OnCalendar=weekly
) and the what by/lib/systemd/system/fstrim.service
(ExecStart=/sbin/fstrim -av
).
– Moilleadóir
Jul 5 '18 at 8:46
1
Fine post! I suggest you change the "cat" commands by the dedicated systemctl commands: cat /lib/systemd/system/fstrim.timer -> systemctl cat fstrim.timer. In general, that command shows the version of the service that is in effect. That might be the one under /lib/systemd, but it might also be a modified version under /etc/systemd.
– vanadium
Jul 14 '18 at 6:15
When it is active, does it do it for all drivers? For example, I have ubuntu installed in one SSD but have another SSD mounted as an ext4 partition. Will it trim both automatically? (status says it is active)
– Eduardo
Apr 30 at 21:15
how to activate it on demand? (for example now, i want to go for a lunch)
– razor
Oct 11 at 9:02
You can manually start/stop/restart any systemd service with: $ sudo systemctl [start/stop/restart] [service name].service
– Broadsworde
Oct 11 at 11:56
add a comment
|
Edit: Please read the comments, this answer mixes up two mechanisms!
Old answer
there is an important point which needs to be added to the answer of @Broadsworde to make it complete.
While on my laptop all the timers and services were enabled, the fstrim log entry was missing (only: starting… stopping… reboot… starting…
etc.).
Missing step
You might need to mark the file systems as discardable. If a file system is not marked as discardable, the trim will skip it[1].
To mark a filesystem as discardable, you have two options:
1. Option: tune2fs
sudo tune2fs -o discard /dev/mapper/ubuntu--vg-root
This will set the discard option as default for my ext4 device. If you don't use encryption, try /dev/sda
instead.
2. Option: /etc/fstab
Make sure to prepend or append the option discard
to your existing mount options. For example like this:
/dev/mapper/ubuntu--vg-root / ext4 discard,relatime,errors=remount-ro 0 1
Only after this the timer service will really do something.
Footnotes
- [1] actually, the device needs to support the
TRIM
operation. But on linux, this is a file system flag. Still, the device the file system is running on needs to support theTRIM
operation. To see if your device supports it, use:sudo hdparm -I /dev/sda | grep -i TRIM
.
In my installation (originally 18.10; later upgraded to 19.04) the filesystems did not have the discard option enabled. I use only SSD in my system; and it never had any mechanical HD. I enabled them with tune2fs. Any idea or explanation of why the system did not enabled them by default?
– FedonKadifeli
May 1 at 9:19
1
I don't think this is correct. The discard option trims blocks when the files are deleted from the file system. The systemd service trims the unused blocks periodically on the file system. These are different things. The discard option can negatively impact performance on some systems, so the periodic one is arguably better.
– xioxox
May 31 at 10:58
1
@xioxox is right. Recentmount
's man page states that «The discard function issues frequent commands to let the block device reclaim space freed by the filesystem. [...] may have a significant performance impact. (The fstrim command is also available to initiate batch trims from userspace.)»
– Fabio A.
Jul 19 at 12:58
Thanks, I edited the answer acoordingly. Please do not continue to downvote this answer: I want to keep it as your comments are valuable!
– Ben
Jul 21 at 11:19
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1034169%2fis-trim-enabled-on-my-ubuntu-18-04-installation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Trim (fstrim/discard) is enabled to run weekly by default in 18.04.
It is set to run for all mounted filesystems on devices that support the discard operation.
It is a systemd
service managed via systemctl
, not CRON.
View fstrim.timer status:
$ systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
Loaded: loaded (/lib/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Thu 2018-07-05 05:45:11 BST; 4h 42min ago
Trigger: Mon 2018-07-09 00:00:00 BST; 3 days left
Docs: man:fstrim
Start/Stop/Restart fstrim.timer:
(does not change startup status)
$ sudo systemctl [start/stop/restart] fstrim.timer
Enable/Disable fstrim.timer:
(add to/remove from startup, does not change current active status)
$ sudo systemctl [enable/disable] fstrim.timer
View fstrim.timer configuration:
$ systemctl cat fstrim.timer
# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.target
View fstrim.service configuration:
$ systemctl cat fstrim.service
# /lib/systemd/system/fstrim.service
[Unit]
Description=Discard unused blocks
[Service]
Type=oneshot
ExecStart=/sbin/fstrim -av
Note: ExecStart=/sbin/fstrim -av
Where:
-a, Trim all mounted filesystems on devices that support the discard operation.
-v, Verbose execution. Output the number of bytes passed from the filesystem down the block stack to the device for potential discard.
View related systemd journal entries:
$ journalctl -u fstrim.timer
Jul 04 14:18:41 user-laptop systemd[1]: Started Discard unused blocks once a week.
Jul 04 21:59:26 user-laptop systemd[1]: Stopped Discard unused blocks once a week.
etc...
$ journalctl -u fstrim.service
Jun 25 10:59:44 user-laptop systemd[1]: Starting Discard unused blocks...
Jun 25 10:59:48 user-laptop fstrim[955]: /: 92.5 GiB (99335237632 bytes) trimmed
Jun 25 10:59:48 user-laptop systemd[1]: Started Discard unused blocks.
-- Reboot --
Jul 02 04:27:41 user-laptop systemd[1]: Starting Discard unused blocks...
Jul 02 04:27:46 user-laptop fstrim[1032]: /: 92.3 GiB (99150807040 bytes) trimmed
Jul 02 04:27:46 user-laptop systemd[1]: Started Discard unused blocks.
etc...
2
For reference, the when is controlled by/lib/systemd/system/fstrim.timer
(OnCalendar=weekly
) and the what by/lib/systemd/system/fstrim.service
(ExecStart=/sbin/fstrim -av
).
– Moilleadóir
Jul 5 '18 at 8:46
1
Fine post! I suggest you change the "cat" commands by the dedicated systemctl commands: cat /lib/systemd/system/fstrim.timer -> systemctl cat fstrim.timer. In general, that command shows the version of the service that is in effect. That might be the one under /lib/systemd, but it might also be a modified version under /etc/systemd.
– vanadium
Jul 14 '18 at 6:15
When it is active, does it do it for all drivers? For example, I have ubuntu installed in one SSD but have another SSD mounted as an ext4 partition. Will it trim both automatically? (status says it is active)
– Eduardo
Apr 30 at 21:15
how to activate it on demand? (for example now, i want to go for a lunch)
– razor
Oct 11 at 9:02
You can manually start/stop/restart any systemd service with: $ sudo systemctl [start/stop/restart] [service name].service
– Broadsworde
Oct 11 at 11:56
add a comment
|
Trim (fstrim/discard) is enabled to run weekly by default in 18.04.
It is set to run for all mounted filesystems on devices that support the discard operation.
It is a systemd
service managed via systemctl
, not CRON.
View fstrim.timer status:
$ systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
Loaded: loaded (/lib/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Thu 2018-07-05 05:45:11 BST; 4h 42min ago
Trigger: Mon 2018-07-09 00:00:00 BST; 3 days left
Docs: man:fstrim
Start/Stop/Restart fstrim.timer:
(does not change startup status)
$ sudo systemctl [start/stop/restart] fstrim.timer
Enable/Disable fstrim.timer:
(add to/remove from startup, does not change current active status)
$ sudo systemctl [enable/disable] fstrim.timer
View fstrim.timer configuration:
$ systemctl cat fstrim.timer
# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.target
View fstrim.service configuration:
$ systemctl cat fstrim.service
# /lib/systemd/system/fstrim.service
[Unit]
Description=Discard unused blocks
[Service]
Type=oneshot
ExecStart=/sbin/fstrim -av
Note: ExecStart=/sbin/fstrim -av
Where:
-a, Trim all mounted filesystems on devices that support the discard operation.
-v, Verbose execution. Output the number of bytes passed from the filesystem down the block stack to the device for potential discard.
View related systemd journal entries:
$ journalctl -u fstrim.timer
Jul 04 14:18:41 user-laptop systemd[1]: Started Discard unused blocks once a week.
Jul 04 21:59:26 user-laptop systemd[1]: Stopped Discard unused blocks once a week.
etc...
$ journalctl -u fstrim.service
Jun 25 10:59:44 user-laptop systemd[1]: Starting Discard unused blocks...
Jun 25 10:59:48 user-laptop fstrim[955]: /: 92.5 GiB (99335237632 bytes) trimmed
Jun 25 10:59:48 user-laptop systemd[1]: Started Discard unused blocks.
-- Reboot --
Jul 02 04:27:41 user-laptop systemd[1]: Starting Discard unused blocks...
Jul 02 04:27:46 user-laptop fstrim[1032]: /: 92.3 GiB (99150807040 bytes) trimmed
Jul 02 04:27:46 user-laptop systemd[1]: Started Discard unused blocks.
etc...
2
For reference, the when is controlled by/lib/systemd/system/fstrim.timer
(OnCalendar=weekly
) and the what by/lib/systemd/system/fstrim.service
(ExecStart=/sbin/fstrim -av
).
– Moilleadóir
Jul 5 '18 at 8:46
1
Fine post! I suggest you change the "cat" commands by the dedicated systemctl commands: cat /lib/systemd/system/fstrim.timer -> systemctl cat fstrim.timer. In general, that command shows the version of the service that is in effect. That might be the one under /lib/systemd, but it might also be a modified version under /etc/systemd.
– vanadium
Jul 14 '18 at 6:15
When it is active, does it do it for all drivers? For example, I have ubuntu installed in one SSD but have another SSD mounted as an ext4 partition. Will it trim both automatically? (status says it is active)
– Eduardo
Apr 30 at 21:15
how to activate it on demand? (for example now, i want to go for a lunch)
– razor
Oct 11 at 9:02
You can manually start/stop/restart any systemd service with: $ sudo systemctl [start/stop/restart] [service name].service
– Broadsworde
Oct 11 at 11:56
add a comment
|
Trim (fstrim/discard) is enabled to run weekly by default in 18.04.
It is set to run for all mounted filesystems on devices that support the discard operation.
It is a systemd
service managed via systemctl
, not CRON.
View fstrim.timer status:
$ systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
Loaded: loaded (/lib/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Thu 2018-07-05 05:45:11 BST; 4h 42min ago
Trigger: Mon 2018-07-09 00:00:00 BST; 3 days left
Docs: man:fstrim
Start/Stop/Restart fstrim.timer:
(does not change startup status)
$ sudo systemctl [start/stop/restart] fstrim.timer
Enable/Disable fstrim.timer:
(add to/remove from startup, does not change current active status)
$ sudo systemctl [enable/disable] fstrim.timer
View fstrim.timer configuration:
$ systemctl cat fstrim.timer
# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.target
View fstrim.service configuration:
$ systemctl cat fstrim.service
# /lib/systemd/system/fstrim.service
[Unit]
Description=Discard unused blocks
[Service]
Type=oneshot
ExecStart=/sbin/fstrim -av
Note: ExecStart=/sbin/fstrim -av
Where:
-a, Trim all mounted filesystems on devices that support the discard operation.
-v, Verbose execution. Output the number of bytes passed from the filesystem down the block stack to the device for potential discard.
View related systemd journal entries:
$ journalctl -u fstrim.timer
Jul 04 14:18:41 user-laptop systemd[1]: Started Discard unused blocks once a week.
Jul 04 21:59:26 user-laptop systemd[1]: Stopped Discard unused blocks once a week.
etc...
$ journalctl -u fstrim.service
Jun 25 10:59:44 user-laptop systemd[1]: Starting Discard unused blocks...
Jun 25 10:59:48 user-laptop fstrim[955]: /: 92.5 GiB (99335237632 bytes) trimmed
Jun 25 10:59:48 user-laptop systemd[1]: Started Discard unused blocks.
-- Reboot --
Jul 02 04:27:41 user-laptop systemd[1]: Starting Discard unused blocks...
Jul 02 04:27:46 user-laptop fstrim[1032]: /: 92.3 GiB (99150807040 bytes) trimmed
Jul 02 04:27:46 user-laptop systemd[1]: Started Discard unused blocks.
etc...
Trim (fstrim/discard) is enabled to run weekly by default in 18.04.
It is set to run for all mounted filesystems on devices that support the discard operation.
It is a systemd
service managed via systemctl
, not CRON.
View fstrim.timer status:
$ systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
Loaded: loaded (/lib/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Thu 2018-07-05 05:45:11 BST; 4h 42min ago
Trigger: Mon 2018-07-09 00:00:00 BST; 3 days left
Docs: man:fstrim
Start/Stop/Restart fstrim.timer:
(does not change startup status)
$ sudo systemctl [start/stop/restart] fstrim.timer
Enable/Disable fstrim.timer:
(add to/remove from startup, does not change current active status)
$ sudo systemctl [enable/disable] fstrim.timer
View fstrim.timer configuration:
$ systemctl cat fstrim.timer
# /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.target
View fstrim.service configuration:
$ systemctl cat fstrim.service
# /lib/systemd/system/fstrim.service
[Unit]
Description=Discard unused blocks
[Service]
Type=oneshot
ExecStart=/sbin/fstrim -av
Note: ExecStart=/sbin/fstrim -av
Where:
-a, Trim all mounted filesystems on devices that support the discard operation.
-v, Verbose execution. Output the number of bytes passed from the filesystem down the block stack to the device for potential discard.
View related systemd journal entries:
$ journalctl -u fstrim.timer
Jul 04 14:18:41 user-laptop systemd[1]: Started Discard unused blocks once a week.
Jul 04 21:59:26 user-laptop systemd[1]: Stopped Discard unused blocks once a week.
etc...
$ journalctl -u fstrim.service
Jun 25 10:59:44 user-laptop systemd[1]: Starting Discard unused blocks...
Jun 25 10:59:48 user-laptop fstrim[955]: /: 92.5 GiB (99335237632 bytes) trimmed
Jun 25 10:59:48 user-laptop systemd[1]: Started Discard unused blocks.
-- Reboot --
Jul 02 04:27:41 user-laptop systemd[1]: Starting Discard unused blocks...
Jul 02 04:27:46 user-laptop fstrim[1032]: /: 92.3 GiB (99150807040 bytes) trimmed
Jul 02 04:27:46 user-laptop systemd[1]: Started Discard unused blocks.
etc...
edited Sep 26 at 10:33
answered May 9 '18 at 18:33
BroadswordeBroadsworde
1,7752 gold badges11 silver badges26 bronze badges
1,7752 gold badges11 silver badges26 bronze badges
2
For reference, the when is controlled by/lib/systemd/system/fstrim.timer
(OnCalendar=weekly
) and the what by/lib/systemd/system/fstrim.service
(ExecStart=/sbin/fstrim -av
).
– Moilleadóir
Jul 5 '18 at 8:46
1
Fine post! I suggest you change the "cat" commands by the dedicated systemctl commands: cat /lib/systemd/system/fstrim.timer -> systemctl cat fstrim.timer. In general, that command shows the version of the service that is in effect. That might be the one under /lib/systemd, but it might also be a modified version under /etc/systemd.
– vanadium
Jul 14 '18 at 6:15
When it is active, does it do it for all drivers? For example, I have ubuntu installed in one SSD but have another SSD mounted as an ext4 partition. Will it trim both automatically? (status says it is active)
– Eduardo
Apr 30 at 21:15
how to activate it on demand? (for example now, i want to go for a lunch)
– razor
Oct 11 at 9:02
You can manually start/stop/restart any systemd service with: $ sudo systemctl [start/stop/restart] [service name].service
– Broadsworde
Oct 11 at 11:56
add a comment
|
2
For reference, the when is controlled by/lib/systemd/system/fstrim.timer
(OnCalendar=weekly
) and the what by/lib/systemd/system/fstrim.service
(ExecStart=/sbin/fstrim -av
).
– Moilleadóir
Jul 5 '18 at 8:46
1
Fine post! I suggest you change the "cat" commands by the dedicated systemctl commands: cat /lib/systemd/system/fstrim.timer -> systemctl cat fstrim.timer. In general, that command shows the version of the service that is in effect. That might be the one under /lib/systemd, but it might also be a modified version under /etc/systemd.
– vanadium
Jul 14 '18 at 6:15
When it is active, does it do it for all drivers? For example, I have ubuntu installed in one SSD but have another SSD mounted as an ext4 partition. Will it trim both automatically? (status says it is active)
– Eduardo
Apr 30 at 21:15
how to activate it on demand? (for example now, i want to go for a lunch)
– razor
Oct 11 at 9:02
You can manually start/stop/restart any systemd service with: $ sudo systemctl [start/stop/restart] [service name].service
– Broadsworde
Oct 11 at 11:56
2
2
For reference, the when is controlled by
/lib/systemd/system/fstrim.timer
(OnCalendar=weekly
) and the what by /lib/systemd/system/fstrim.service
(ExecStart=/sbin/fstrim -av
).– Moilleadóir
Jul 5 '18 at 8:46
For reference, the when is controlled by
/lib/systemd/system/fstrim.timer
(OnCalendar=weekly
) and the what by /lib/systemd/system/fstrim.service
(ExecStart=/sbin/fstrim -av
).– Moilleadóir
Jul 5 '18 at 8:46
1
1
Fine post! I suggest you change the "cat" commands by the dedicated systemctl commands: cat /lib/systemd/system/fstrim.timer -> systemctl cat fstrim.timer. In general, that command shows the version of the service that is in effect. That might be the one under /lib/systemd, but it might also be a modified version under /etc/systemd.
– vanadium
Jul 14 '18 at 6:15
Fine post! I suggest you change the "cat" commands by the dedicated systemctl commands: cat /lib/systemd/system/fstrim.timer -> systemctl cat fstrim.timer. In general, that command shows the version of the service that is in effect. That might be the one under /lib/systemd, but it might also be a modified version under /etc/systemd.
– vanadium
Jul 14 '18 at 6:15
When it is active, does it do it for all drivers? For example, I have ubuntu installed in one SSD but have another SSD mounted as an ext4 partition. Will it trim both automatically? (status says it is active)
– Eduardo
Apr 30 at 21:15
When it is active, does it do it for all drivers? For example, I have ubuntu installed in one SSD but have another SSD mounted as an ext4 partition. Will it trim both automatically? (status says it is active)
– Eduardo
Apr 30 at 21:15
how to activate it on demand? (for example now, i want to go for a lunch)
– razor
Oct 11 at 9:02
how to activate it on demand? (for example now, i want to go for a lunch)
– razor
Oct 11 at 9:02
You can manually start/stop/restart any systemd service with: $ sudo systemctl [start/stop/restart] [service name].service
– Broadsworde
Oct 11 at 11:56
You can manually start/stop/restart any systemd service with: $ sudo systemctl [start/stop/restart] [service name].service
– Broadsworde
Oct 11 at 11:56
add a comment
|
Edit: Please read the comments, this answer mixes up two mechanisms!
Old answer
there is an important point which needs to be added to the answer of @Broadsworde to make it complete.
While on my laptop all the timers and services were enabled, the fstrim log entry was missing (only: starting… stopping… reboot… starting…
etc.).
Missing step
You might need to mark the file systems as discardable. If a file system is not marked as discardable, the trim will skip it[1].
To mark a filesystem as discardable, you have two options:
1. Option: tune2fs
sudo tune2fs -o discard /dev/mapper/ubuntu--vg-root
This will set the discard option as default for my ext4 device. If you don't use encryption, try /dev/sda
instead.
2. Option: /etc/fstab
Make sure to prepend or append the option discard
to your existing mount options. For example like this:
/dev/mapper/ubuntu--vg-root / ext4 discard,relatime,errors=remount-ro 0 1
Only after this the timer service will really do something.
Footnotes
- [1] actually, the device needs to support the
TRIM
operation. But on linux, this is a file system flag. Still, the device the file system is running on needs to support theTRIM
operation. To see if your device supports it, use:sudo hdparm -I /dev/sda | grep -i TRIM
.
In my installation (originally 18.10; later upgraded to 19.04) the filesystems did not have the discard option enabled. I use only SSD in my system; and it never had any mechanical HD. I enabled them with tune2fs. Any idea or explanation of why the system did not enabled them by default?
– FedonKadifeli
May 1 at 9:19
1
I don't think this is correct. The discard option trims blocks when the files are deleted from the file system. The systemd service trims the unused blocks periodically on the file system. These are different things. The discard option can negatively impact performance on some systems, so the periodic one is arguably better.
– xioxox
May 31 at 10:58
1
@xioxox is right. Recentmount
's man page states that «The discard function issues frequent commands to let the block device reclaim space freed by the filesystem. [...] may have a significant performance impact. (The fstrim command is also available to initiate batch trims from userspace.)»
– Fabio A.
Jul 19 at 12:58
Thanks, I edited the answer acoordingly. Please do not continue to downvote this answer: I want to keep it as your comments are valuable!
– Ben
Jul 21 at 11:19
add a comment
|
Edit: Please read the comments, this answer mixes up two mechanisms!
Old answer
there is an important point which needs to be added to the answer of @Broadsworde to make it complete.
While on my laptop all the timers and services were enabled, the fstrim log entry was missing (only: starting… stopping… reboot… starting…
etc.).
Missing step
You might need to mark the file systems as discardable. If a file system is not marked as discardable, the trim will skip it[1].
To mark a filesystem as discardable, you have two options:
1. Option: tune2fs
sudo tune2fs -o discard /dev/mapper/ubuntu--vg-root
This will set the discard option as default for my ext4 device. If you don't use encryption, try /dev/sda
instead.
2. Option: /etc/fstab
Make sure to prepend or append the option discard
to your existing mount options. For example like this:
/dev/mapper/ubuntu--vg-root / ext4 discard,relatime,errors=remount-ro 0 1
Only after this the timer service will really do something.
Footnotes
- [1] actually, the device needs to support the
TRIM
operation. But on linux, this is a file system flag. Still, the device the file system is running on needs to support theTRIM
operation. To see if your device supports it, use:sudo hdparm -I /dev/sda | grep -i TRIM
.
In my installation (originally 18.10; later upgraded to 19.04) the filesystems did not have the discard option enabled. I use only SSD in my system; and it never had any mechanical HD. I enabled them with tune2fs. Any idea or explanation of why the system did not enabled them by default?
– FedonKadifeli
May 1 at 9:19
1
I don't think this is correct. The discard option trims blocks when the files are deleted from the file system. The systemd service trims the unused blocks periodically on the file system. These are different things. The discard option can negatively impact performance on some systems, so the periodic one is arguably better.
– xioxox
May 31 at 10:58
1
@xioxox is right. Recentmount
's man page states that «The discard function issues frequent commands to let the block device reclaim space freed by the filesystem. [...] may have a significant performance impact. (The fstrim command is also available to initiate batch trims from userspace.)»
– Fabio A.
Jul 19 at 12:58
Thanks, I edited the answer acoordingly. Please do not continue to downvote this answer: I want to keep it as your comments are valuable!
– Ben
Jul 21 at 11:19
add a comment
|
Edit: Please read the comments, this answer mixes up two mechanisms!
Old answer
there is an important point which needs to be added to the answer of @Broadsworde to make it complete.
While on my laptop all the timers and services were enabled, the fstrim log entry was missing (only: starting… stopping… reboot… starting…
etc.).
Missing step
You might need to mark the file systems as discardable. If a file system is not marked as discardable, the trim will skip it[1].
To mark a filesystem as discardable, you have two options:
1. Option: tune2fs
sudo tune2fs -o discard /dev/mapper/ubuntu--vg-root
This will set the discard option as default for my ext4 device. If you don't use encryption, try /dev/sda
instead.
2. Option: /etc/fstab
Make sure to prepend or append the option discard
to your existing mount options. For example like this:
/dev/mapper/ubuntu--vg-root / ext4 discard,relatime,errors=remount-ro 0 1
Only after this the timer service will really do something.
Footnotes
- [1] actually, the device needs to support the
TRIM
operation. But on linux, this is a file system flag. Still, the device the file system is running on needs to support theTRIM
operation. To see if your device supports it, use:sudo hdparm -I /dev/sda | grep -i TRIM
.
Edit: Please read the comments, this answer mixes up two mechanisms!
Old answer
there is an important point which needs to be added to the answer of @Broadsworde to make it complete.
While on my laptop all the timers and services were enabled, the fstrim log entry was missing (only: starting… stopping… reboot… starting…
etc.).
Missing step
You might need to mark the file systems as discardable. If a file system is not marked as discardable, the trim will skip it[1].
To mark a filesystem as discardable, you have two options:
1. Option: tune2fs
sudo tune2fs -o discard /dev/mapper/ubuntu--vg-root
This will set the discard option as default for my ext4 device. If you don't use encryption, try /dev/sda
instead.
2. Option: /etc/fstab
Make sure to prepend or append the option discard
to your existing mount options. For example like this:
/dev/mapper/ubuntu--vg-root / ext4 discard,relatime,errors=remount-ro 0 1
Only after this the timer service will really do something.
Footnotes
- [1] actually, the device needs to support the
TRIM
operation. But on linux, this is a file system flag. Still, the device the file system is running on needs to support theTRIM
operation. To see if your device supports it, use:sudo hdparm -I /dev/sda | grep -i TRIM
.
edited Jul 21 at 11:19
answered Apr 3 at 7:55
BenBen
3802 silver badges15 bronze badges
3802 silver badges15 bronze badges
In my installation (originally 18.10; later upgraded to 19.04) the filesystems did not have the discard option enabled. I use only SSD in my system; and it never had any mechanical HD. I enabled them with tune2fs. Any idea or explanation of why the system did not enabled them by default?
– FedonKadifeli
May 1 at 9:19
1
I don't think this is correct. The discard option trims blocks when the files are deleted from the file system. The systemd service trims the unused blocks periodically on the file system. These are different things. The discard option can negatively impact performance on some systems, so the periodic one is arguably better.
– xioxox
May 31 at 10:58
1
@xioxox is right. Recentmount
's man page states that «The discard function issues frequent commands to let the block device reclaim space freed by the filesystem. [...] may have a significant performance impact. (The fstrim command is also available to initiate batch trims from userspace.)»
– Fabio A.
Jul 19 at 12:58
Thanks, I edited the answer acoordingly. Please do not continue to downvote this answer: I want to keep it as your comments are valuable!
– Ben
Jul 21 at 11:19
add a comment
|
In my installation (originally 18.10; later upgraded to 19.04) the filesystems did not have the discard option enabled. I use only SSD in my system; and it never had any mechanical HD. I enabled them with tune2fs. Any idea or explanation of why the system did not enabled them by default?
– FedonKadifeli
May 1 at 9:19
1
I don't think this is correct. The discard option trims blocks when the files are deleted from the file system. The systemd service trims the unused blocks periodically on the file system. These are different things. The discard option can negatively impact performance on some systems, so the periodic one is arguably better.
– xioxox
May 31 at 10:58
1
@xioxox is right. Recentmount
's man page states that «The discard function issues frequent commands to let the block device reclaim space freed by the filesystem. [...] may have a significant performance impact. (The fstrim command is also available to initiate batch trims from userspace.)»
– Fabio A.
Jul 19 at 12:58
Thanks, I edited the answer acoordingly. Please do not continue to downvote this answer: I want to keep it as your comments are valuable!
– Ben
Jul 21 at 11:19
In my installation (originally 18.10; later upgraded to 19.04) the filesystems did not have the discard option enabled. I use only SSD in my system; and it never had any mechanical HD. I enabled them with tune2fs. Any idea or explanation of why the system did not enabled them by default?
– FedonKadifeli
May 1 at 9:19
In my installation (originally 18.10; later upgraded to 19.04) the filesystems did not have the discard option enabled. I use only SSD in my system; and it never had any mechanical HD. I enabled them with tune2fs. Any idea or explanation of why the system did not enabled them by default?
– FedonKadifeli
May 1 at 9:19
1
1
I don't think this is correct. The discard option trims blocks when the files are deleted from the file system. The systemd service trims the unused blocks periodically on the file system. These are different things. The discard option can negatively impact performance on some systems, so the periodic one is arguably better.
– xioxox
May 31 at 10:58
I don't think this is correct. The discard option trims blocks when the files are deleted from the file system. The systemd service trims the unused blocks periodically on the file system. These are different things. The discard option can negatively impact performance on some systems, so the periodic one is arguably better.
– xioxox
May 31 at 10:58
1
1
@xioxox is right. Recent
mount
's man page states that «The discard function issues frequent commands to let the block device reclaim space freed by the filesystem. [...] may have a significant performance impact. (The fstrim command is also available to initiate batch trims from userspace.)»– Fabio A.
Jul 19 at 12:58
@xioxox is right. Recent
mount
's man page states that «The discard function issues frequent commands to let the block device reclaim space freed by the filesystem. [...] may have a significant performance impact. (The fstrim command is also available to initiate batch trims from userspace.)»– Fabio A.
Jul 19 at 12:58
Thanks, I edited the answer acoordingly. Please do not continue to downvote this answer: I want to keep it as your comments are valuable!
– Ben
Jul 21 at 11:19
Thanks, I edited the answer acoordingly. Please do not continue to downvote this answer: I want to keep it as your comments are valuable!
– Ben
Jul 21 at 11:19
add a comment
|
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1034169%2fis-trim-enabled-on-my-ubuntu-18-04-installation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown