The Wanderer (12023-02-16):
> filesystems et cetera aligned to physical blocks, because physical block
> size defines the minimum size that can be erased (and, therefore,
> overwritten) in any given operation,

This is true. Note: erased, not written.

>                                       and therefore impacts both wear
> rates and write speeds in what is potentially a very serious way.

This is not a logical consequence.

You are assuming that if a block of flash memory contains B sectors,
then the block number b will contain the sectors from number B×b
included to number B×(b+1) excluded.

          0                   1                   2
┌───────────────────┬───────────────────┬───────────────────┐
┌────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐
   0    1    2    3    4    6    7    8    9   10   11   12

This is how it works for physical / logical sectors, but not for blocks
of flash memory.

With flash memory, if you want to rewrite a sector, you can only write a
blank sector.

So: you read the whole block, blank it, then re-write all the other
sectors and your updated sector? No, definitely not, that would be
terrible.

What happens is, very schematically: the controller finds an unused
sector in a blank block (either one that has never been used or one that
has been recently erased), it writes the new data there, then updates
its remapping table to mark the old data obsolete and where the new data
is.

I do not know how the remapping table is kept; probably some kind of
journal with RAM caching. And of course, there are optimizations and
trade-offs: if a block contains only obsolete sectors except for a few
ones, it might make sense to move these non-obsolete sectors to a new
block to have the old one ready for erasure. I suspect constructors keep
what they do exactly as trade secrets.

But the short of it is that it does not make sense to worry about
alignment, because even if you do, there is no guarantee that the first
sector of your partition will be the first sector of its block, and even
if it is it might not be tomorrow after it has been rewritten by the OS,
i.e. reallocated by the controller.

Regards,

-- 
  Nicolas George

Reply via email to