ArticleslgStudy

computer science

Trim (computing)

Trim (computing) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Trim (computing) rather than just read about it. In short: A trim command (known as TRIM in the ATA command set, and UNMAP in the SCSI command set) allows an operating system to inform a storage medium which blocks of data are no longer considered to be "in use" and therefore can be erased internally. TRIM is primarily used on solid-state drives (SSDs), but is also used on some shingled magnetic recording (SMR) hard drives.

Key takeaways

  • Trim (computing) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Trim (computing) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Trim (computing) from memory before moving on to harder problems.

Reference excerpt

A trim command (known as TRIM in the ATA command set, and UNMAP in the SCSI command set) allows an operating system to inform a storage medium which blocks of data are no longer considered to be "in use" and therefore can be erased internally. TRIM is primarily used on solid-state drives (SSDs), but is also used on some shingled magnetic recording (SMR) hard drives. Trim commands were introduced soon after SSDs. Because SSDs use different technology from earlier magnetic hard drives, the preexisting techniques for storing data caused early SSDs to become slower as they were used more. With trimming, the SSD can efficiently clear unneeded data that would otherwise slow future write operations. Although tools to "reset" some drives to a fresh state were already available before the introduction of trimming, they also delete all data on the drive, which makes them impractical to use for ongoing optimization. As of 2010, many SSDs and many flash removable storage devices had internal garbage collection mechanisms for certain filesystem(s) (such as FAT and NTFS) that worked independently of trimming. Although this successfully maintained their lifetime even under operating systems that did not support trim, it had the associated drawbacks of increased write amplification and wear of the flash cells, as well as decreased write performance of flash cells.

Background Many file systems handle delete operations by flagging data blocks as "not in use". As a result, storage media devices generally do not know which sectors/pages are truly in use and which can be considered free space. Contrary to (for example) an overwrite operation, a delete will not involve writing to the sectors that contained the data. Since a common SSD has no knowledge of the file system structures, including the list of unused blocks/sectors, the storage medium remains unaware that the blocks have become available. This allows undelete tools to recover (parts of) files from electromechanical hard disks, despite the files being reported as "deleted" by the operating system. But it also means that when the operating system later performs a write operation to one of the sectors, which it considers free space, it effectively becomes an overwrite operation from the point of view of the storage medium. For magnetic disks, an overwrite of existing data is no different from writing into an empty sector, but because of how some SSDs function at the lowest level, an overwrite produces significant overhead compared to writing data into an empty page, potentially crippling write performance. SSDs store data in flash memory cells that are grouped into pages typically of 4 to 16 KiB, grouped together into blocks of typically 128 to 512 pages, for example 512 kiB blocks that group 128 pages of 4 kiB each. NAND flash memory cells can be directly written to only when they are empty. If they happen to contain data, the contents must be erased before a write operation. An SSD write operation can be done to a single page but, due to hardware limitations, erase commands always affect entire blocks. Consequently, writing data to empty pages on an SSD is very fast, but slows down considerably once previously written pages need to be overwritten. Since an erase of the cells in the page is needed before it can be written to again, but only entire blocks can be erased, an overwrite will initiate a read-erase-modify-write cycle: the contents of the entire block are stored in cache, then the entire block is erased from the SSD, then the overwritten page(s) is written into the cached block, and only then can the entire updated block be written to the flash medium. This phenomenon is known as write amplification.

Operation The TRIM command enables an operating system to notify the drive of pages which no longer contain valid data. For a file deletion operation, the operating system will mark the file's sectors as free for new data, then send a TRIM command to the drive. After trimming, the drive will not preserve any contents of the block when writing new data to a page of flash memory, resulting in less write amplification (fewer writes), higher write throughput (no need for a read-erase-modify sequence), thus increasing drive life. Different drives implement the command somewhat differently, so performance can vary. TRIM tells the drive to mark an LBA region as invalid and subsequent reads on the region will not return any meaningful data. For a very brief time, the data could still reside on the flash internally. After the TRIM command is issued and garbage collection has taken place, recovery of deleted or corrupted data can be difficult or impossible, depending on the drive's firmware implementation of the command.

Implementation

Operating system support The TRIM command is beneficial only if the drive implements it and the operating system requests it. The table below identifies each notable operating system and the first version supporting the command. Additionally, older solid-state drives designed before the addition of the TRIM command to the ATA standard will need firmware updates, otherwise the new command will be ignored. However, not every drive can be upgraded to support trimming. The support for TRIM also varies by what the particular filesystem driver on the operating system is capable of, since only a program with an understanding of what parts of the disk are free space can safely issue the command, and on the system level this ability tends to lie in the filesystem driver itself.

RAID issues As of January 2017, support for the TRIM command is not implemented in most hardware-based RAID technologies. However, software RAID implementations often do include support for TRIM.

Windows Windows 10 offers support for TRIM in SSD ID volumes using the "optimize drives" option when configuring a RAID volume.

macOS The macOS RAID driver does not support TRIM. This is true for all versions of Mac OS X from 10.7 through macOS 10.12.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Trim (computing)

Start with the simplest possible case. Write down what Trim (computing) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Trim (computing) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Trim (computing) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Trim (computing)

In research
Trim (computing) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Trim (computing) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Trim (computing) is common in secondary-school and first-year university syllabi. It links to neighbouring topics SCSI, Serial ATA, Solid-state computer storage, so understanding it makes those chapters shorter.
In everyday life
Look for Trim (computing) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Trim (computing)” →

How to study Trim (computing) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Trim (computing) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Trim (computing) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Trim (computing) in simple terms?

A trim command (known as TRIM in the ATA command set, and UNMAP in the SCSI command set) allows an operating system to inform a storage medium which blocks of data are no longer considered to be "in use" and therefore can be erased internally. TRIM is primarily used on solid-state drives (SSDs), bu…

Why does Trim (computing) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Trim (computing)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Trim (computing).

Tags

  • SCSI
  • Serial ATA
  • Solid-state computer storage

Keep exploring