TRIM doesn't operate on files. GC does not work on files. The SSD doesn't operate on files. Your hard drive does not operate on files.
True, it works on sectors. The OS however sends sector info based on files deleted.
And the FS works on files. So when a file is deleted all its sectors are marked as junk in the FS and then the SSD can read it and find that with GC.
Or when a file is deleted the OS immediately sends the drive a TRIM command for all the sectors it used (it always sends the command, HDDs ignore it as unrecognized command, SSDs utilize it if capable)
So to clarify, when you delete a file, the FS marks the sectors that file occupied as junk in its master file table. I phrased it poorly there.
Most typically, today, what you are worried about are 4K blocks. Your OS works with 4K as the smallest logical memory size, your filesystem defaults to a 4K cluster size, and the SSD works on 4K logical blocks* (there is a historical causal correlation, there). Those 4K blocks are arbitrary data.
4k Sectors not blocks since we are all about terminology here.
The controllers can be tweaked for FS structures and access patterns of certain FSes (SD cards are probably the most infamous for it), but that is in no way necessary for garbage collection. Garbage collection requires: (1) externally-visible memory locations that are mapped to internal locations by an active translation layer, (2) more internal locations available than are allowed to be mapped (if it reaches 1:1, there will be no garbage to work with), (2) a method to determine what mapped locations are dead (garbage), and (3) a method to reclaim dead locations (collection). Any such implementation is generally referred to as garbage collecting.
The problem is #(2) a method to determine what mapped locations are dead (garbage)
As I said, THIS IS IMPOSSIBLE without the drive controller being aware of the OS. Garbage sectors are not marked in the MBR, are not marked individually, are not marked in any way. The only place that keeps track of it is the FS' mfaster file table. Something unique to each FS.
GC is now useful only for legacy OS where TRIM is not supported.
No, GC goes on and does its thing with any OS.
If the OS has TRIM then GC does nothing useful at all.
Oh, it (probably) runs... but it doesn't get to ever mark a single sector as garbage, since the OS sends the TRIM command for all sectors used by a file the moment said file is deleted.
TRIM allows space known free by the OS to be considered recyclable by the SSD, adding to the available blocks to use as it sees fit.
That is what I said, yes.
Yes, there is. All OS-visible space is assumed to be not junk. When an OS-visible chunk of data is overwritten, it is written to a new physical location, the old location(s) is/are now considered garbage. It's not ideal, but it works, and works pretty well. Consumer drives typically have just over 7% of their total capacity, or more, that only the drive knows about, to enable this.
You just described the absolute worst case scenario. The one where the drive only finds out data is garbage when it is told to overwrite it. Until that moment it has been preserving the data despite it being garbage, unknowingly, causing write amplification.
This doesn't work "well", it works very VERY poorly. This is explicitly what TRIM & GC were created to combat. When I said there is no way I meant clearly "there is no way except the worst case scenario which TRIM&GC were created to avoid which btw requires the OS to notify the drive of that status".
The 3 methods which could notify a drive of data being garbage:
1. The OS tells it to overwrite this data (absolute worst case scenario, the thing TRIM and GC were made to avoid)
2. The OS tells it the data is junk (TRIM command) as soon as it becomes junk.
3. The SSD scans the FS contained within (requires FS specific support) and marks sectors as junk based on what sectors are marked as junk in the FS itself (which occurs on deletion).
There is no magical 4th way for it to know. It is not in the MBR, it is not in a magic toggle for each sector. It just doesn't exist.
If it existed then TRIM would have never been created and never been needed and never would have been so useful.
No, TRIM exists for the same reason that file caching exists: free space should be put to good use, not wasted. Instead of the drive only being able to use its over-provisioned space, it may use that space and the space given by TRIM, allowing for the benefits of higher over-provisioning, while there is free space, without restricting the maximum space available to the user, as over-provisioning does.
With TRIM disabled, you can do the same on an SSD, and for the same reason. Without TRIM, the data stays there, just like on a HDD.
* not necessarily the physical size; many use 8k
Actually, with neither TRIM nor GC all space except over provisioned space is considered "not junk" by the controller. This leads to atrocious write amplification that causes your performance to tank AND eats up your drive's lifespan rapidly. Over-provisioning helps a lot, but we are talking write amplification in the few dozen compared to the maximum possible write amplifcation of 128x.
With TRIM you can have write amplification around the 1x since junk data is never preserved.
With GC you can have the somewhere in between TRIM and nothing, based on how long it had to search the drive since last write (did it have time to find all the new junk and mark it)