How does the filesystem (ext4) “store” TRIM information?
Clash Royale CLAN TAG#URR8PPP
It is recommended to enable a TRIM cron job which run once every week.
When the fstrim command is called the filesystem will sent TRIM information to the drive to discard deleted data (I hope I get it right)
So far so good, this is described many places.
But I cannot find any information about how/where those TRIM information are "stored" in the filesystem between the fstrim commands?
And can those TRIM information be "cleared" in some way so the SSD will not get the information of all the pages/blocks that has to be discarded?
Or will the fstrim command compare the filesystem and the SSD in regards to which data is actually deleted?
ssd trim
add a comment |
It is recommended to enable a TRIM cron job which run once every week.
When the fstrim command is called the filesystem will sent TRIM information to the drive to discard deleted data (I hope I get it right)
So far so good, this is described many places.
But I cannot find any information about how/where those TRIM information are "stored" in the filesystem between the fstrim commands?
And can those TRIM information be "cleared" in some way so the SSD will not get the information of all the pages/blocks that has to be discarded?
Or will the fstrim command compare the filesystem and the SSD in regards to which data is actually deleted?
ssd trim
1
TRIM doesn't have information stored in the filesystem, it simply told SSD which LBA are useless anymore. The driver stores a LBA-PBA mapping table somewhere in the disk but that part of storage is completely transparent to OS.
– 炸鱼薯条德里克
Feb 8 at 23:58
add a comment |
It is recommended to enable a TRIM cron job which run once every week.
When the fstrim command is called the filesystem will sent TRIM information to the drive to discard deleted data (I hope I get it right)
So far so good, this is described many places.
But I cannot find any information about how/where those TRIM information are "stored" in the filesystem between the fstrim commands?
And can those TRIM information be "cleared" in some way so the SSD will not get the information of all the pages/blocks that has to be discarded?
Or will the fstrim command compare the filesystem and the SSD in regards to which data is actually deleted?
ssd trim
It is recommended to enable a TRIM cron job which run once every week.
When the fstrim command is called the filesystem will sent TRIM information to the drive to discard deleted data (I hope I get it right)
So far so good, this is described many places.
But I cannot find any information about how/where those TRIM information are "stored" in the filesystem between the fstrim commands?
And can those TRIM information be "cleared" in some way so the SSD will not get the information of all the pages/blocks that has to be discarded?
Or will the fstrim command compare the filesystem and the SSD in regards to which data is actually deleted?
ssd trim
ssd trim
asked Feb 8 at 23:10
MrCalvinMrCalvin
1204
1204
1
TRIM doesn't have information stored in the filesystem, it simply told SSD which LBA are useless anymore. The driver stores a LBA-PBA mapping table somewhere in the disk but that part of storage is completely transparent to OS.
– 炸鱼薯条德里克
Feb 8 at 23:58
add a comment |
1
TRIM doesn't have information stored in the filesystem, it simply told SSD which LBA are useless anymore. The driver stores a LBA-PBA mapping table somewhere in the disk but that part of storage is completely transparent to OS.
– 炸鱼薯条德里克
Feb 8 at 23:58
1
1
TRIM doesn't have information stored in the filesystem, it simply told SSD which LBA are useless anymore. The driver stores a LBA-PBA mapping table somewhere in the disk but that part of storage is completely transparent to OS.
– 炸鱼薯条德里克
Feb 8 at 23:58
TRIM doesn't have information stored in the filesystem, it simply told SSD which LBA are useless anymore. The driver stores a LBA-PBA mapping table somewhere in the disk but that part of storage is completely transparent to OS.
– 炸鱼薯条德里克
Feb 8 at 23:58
add a comment |
1 Answer
1
active
oldest
votes
I don't know if ext4 actually stores it anywhere. Other filesystems certainly don't.
ext4 avoids what it already trimmed in the current session only - while it's still mounted. Once you reboot or re-mount the filesystem, it just TRIMs empty space all over again.
So this could be an in-memory structure that isn't stored at all. I didn't dive into the very fine source code to find out.
A little test:
# truncate -s 1G /dev/shm/foobar.img
# losetup --find --show /dev/shm/foobar.img
/dev/loop9
# mkfs.ext4 /dev/loop9
# mkdir /mnt/loop
Given a 1G filesystem, let's mount and trim it:
# mount /dev/loop9 /mnt/loop/
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
# fstrim -v /mnt/loop
/mnt/loop: 0 B (0 bytes) trimmed
So it first trims all... that alone is already suspicious, after all: mkfs already trimmed too (ouch), so it should know it's still empty and trimmed, right? Well, if it knows, it doesn't care:
# umount /mnt/loop
# mount /dev/loop9 /mnt/loop
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
So after re-mount, it just trims all free space again.
When creating and deleting files, it's not pinpoint precision either:
# dd bs=1M count=10 if=/dev/zero of=/mnt/loop/zerofile
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0124641 s, 841 MB/s
# sync
# rm /mnt/loop/zerofile
# fstrim -v /mnt/loop
/mnt/loop: 117.5 MiB (123203584 bytes) trimmed
So, writing 10M causes a re-trim of 117M. It just doesn't mean anything.
Only the SSD itself really knows what's currently trimmed and what not, and when asked to trim an already trimmed area, it should simply do nothing. So no harm done and no need to really store this information in the filesystem.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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/3.0/"u003ecc by-sa 3.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%2funix.stackexchange.com%2fquestions%2f499577%2fhow-does-the-filesystem-ext4-store-trim-information%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I don't know if ext4 actually stores it anywhere. Other filesystems certainly don't.
ext4 avoids what it already trimmed in the current session only - while it's still mounted. Once you reboot or re-mount the filesystem, it just TRIMs empty space all over again.
So this could be an in-memory structure that isn't stored at all. I didn't dive into the very fine source code to find out.
A little test:
# truncate -s 1G /dev/shm/foobar.img
# losetup --find --show /dev/shm/foobar.img
/dev/loop9
# mkfs.ext4 /dev/loop9
# mkdir /mnt/loop
Given a 1G filesystem, let's mount and trim it:
# mount /dev/loop9 /mnt/loop/
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
# fstrim -v /mnt/loop
/mnt/loop: 0 B (0 bytes) trimmed
So it first trims all... that alone is already suspicious, after all: mkfs already trimmed too (ouch), so it should know it's still empty and trimmed, right? Well, if it knows, it doesn't care:
# umount /mnt/loop
# mount /dev/loop9 /mnt/loop
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
So after re-mount, it just trims all free space again.
When creating and deleting files, it's not pinpoint precision either:
# dd bs=1M count=10 if=/dev/zero of=/mnt/loop/zerofile
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0124641 s, 841 MB/s
# sync
# rm /mnt/loop/zerofile
# fstrim -v /mnt/loop
/mnt/loop: 117.5 MiB (123203584 bytes) trimmed
So, writing 10M causes a re-trim of 117M. It just doesn't mean anything.
Only the SSD itself really knows what's currently trimmed and what not, and when asked to trim an already trimmed area, it should simply do nothing. So no harm done and no need to really store this information in the filesystem.
add a comment |
I don't know if ext4 actually stores it anywhere. Other filesystems certainly don't.
ext4 avoids what it already trimmed in the current session only - while it's still mounted. Once you reboot or re-mount the filesystem, it just TRIMs empty space all over again.
So this could be an in-memory structure that isn't stored at all. I didn't dive into the very fine source code to find out.
A little test:
# truncate -s 1G /dev/shm/foobar.img
# losetup --find --show /dev/shm/foobar.img
/dev/loop9
# mkfs.ext4 /dev/loop9
# mkdir /mnt/loop
Given a 1G filesystem, let's mount and trim it:
# mount /dev/loop9 /mnt/loop/
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
# fstrim -v /mnt/loop
/mnt/loop: 0 B (0 bytes) trimmed
So it first trims all... that alone is already suspicious, after all: mkfs already trimmed too (ouch), so it should know it's still empty and trimmed, right? Well, if it knows, it doesn't care:
# umount /mnt/loop
# mount /dev/loop9 /mnt/loop
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
So after re-mount, it just trims all free space again.
When creating and deleting files, it's not pinpoint precision either:
# dd bs=1M count=10 if=/dev/zero of=/mnt/loop/zerofile
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0124641 s, 841 MB/s
# sync
# rm /mnt/loop/zerofile
# fstrim -v /mnt/loop
/mnt/loop: 117.5 MiB (123203584 bytes) trimmed
So, writing 10M causes a re-trim of 117M. It just doesn't mean anything.
Only the SSD itself really knows what's currently trimmed and what not, and when asked to trim an already trimmed area, it should simply do nothing. So no harm done and no need to really store this information in the filesystem.
add a comment |
I don't know if ext4 actually stores it anywhere. Other filesystems certainly don't.
ext4 avoids what it already trimmed in the current session only - while it's still mounted. Once you reboot or re-mount the filesystem, it just TRIMs empty space all over again.
So this could be an in-memory structure that isn't stored at all. I didn't dive into the very fine source code to find out.
A little test:
# truncate -s 1G /dev/shm/foobar.img
# losetup --find --show /dev/shm/foobar.img
/dev/loop9
# mkfs.ext4 /dev/loop9
# mkdir /mnt/loop
Given a 1G filesystem, let's mount and trim it:
# mount /dev/loop9 /mnt/loop/
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
# fstrim -v /mnt/loop
/mnt/loop: 0 B (0 bytes) trimmed
So it first trims all... that alone is already suspicious, after all: mkfs already trimmed too (ouch), so it should know it's still empty and trimmed, right? Well, if it knows, it doesn't care:
# umount /mnt/loop
# mount /dev/loop9 /mnt/loop
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
So after re-mount, it just trims all free space again.
When creating and deleting files, it's not pinpoint precision either:
# dd bs=1M count=10 if=/dev/zero of=/mnt/loop/zerofile
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0124641 s, 841 MB/s
# sync
# rm /mnt/loop/zerofile
# fstrim -v /mnt/loop
/mnt/loop: 117.5 MiB (123203584 bytes) trimmed
So, writing 10M causes a re-trim of 117M. It just doesn't mean anything.
Only the SSD itself really knows what's currently trimmed and what not, and when asked to trim an already trimmed area, it should simply do nothing. So no harm done and no need to really store this information in the filesystem.
I don't know if ext4 actually stores it anywhere. Other filesystems certainly don't.
ext4 avoids what it already trimmed in the current session only - while it's still mounted. Once you reboot or re-mount the filesystem, it just TRIMs empty space all over again.
So this could be an in-memory structure that isn't stored at all. I didn't dive into the very fine source code to find out.
A little test:
# truncate -s 1G /dev/shm/foobar.img
# losetup --find --show /dev/shm/foobar.img
/dev/loop9
# mkfs.ext4 /dev/loop9
# mkdir /mnt/loop
Given a 1G filesystem, let's mount and trim it:
# mount /dev/loop9 /mnt/loop/
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
# fstrim -v /mnt/loop
/mnt/loop: 0 B (0 bytes) trimmed
So it first trims all... that alone is already suspicious, after all: mkfs already trimmed too (ouch), so it should know it's still empty and trimmed, right? Well, if it knows, it doesn't care:
# umount /mnt/loop
# mount /dev/loop9 /mnt/loop
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
So after re-mount, it just trims all free space again.
When creating and deleting files, it's not pinpoint precision either:
# dd bs=1M count=10 if=/dev/zero of=/mnt/loop/zerofile
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0124641 s, 841 MB/s
# sync
# rm /mnt/loop/zerofile
# fstrim -v /mnt/loop
/mnt/loop: 117.5 MiB (123203584 bytes) trimmed
So, writing 10M causes a re-trim of 117M. It just doesn't mean anything.
Only the SSD itself really knows what's currently trimmed and what not, and when asked to trim an already trimmed area, it should simply do nothing. So no harm done and no need to really store this information in the filesystem.
edited Feb 8 at 23:48
answered Feb 8 at 23:42
frostschutzfrostschutz
27.3k15586
27.3k15586
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f499577%2fhow-does-the-filesystem-ext4-store-trim-information%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
1
TRIM doesn't have information stored in the filesystem, it simply told SSD which LBA are useless anymore. The driver stores a LBA-PBA mapping table somewhere in the disk but that part of storage is completely transparent to OS.
– 炸鱼薯条德里克
Feb 8 at 23:58