5

Let's assume that I want to begin my partitions with an offset on flash drives because of:

Although it is usually possible to write single pages, the data cannot be overwritten without being erased first, and erasing is only possible in much larger units, typically between 128KB and 2MB. The controllers group these erase blocks into even larger segments, called "erase block groups," "allocation units," or simply "segments." The most common size for these segments is 4MB for drives in the multi-gigabyte class, and all operations on the drive happen in these units; in particular, the drive will never erase any unit smaller than a segment.Optimizing Linux with cheap flash drives

I want to align every single partition corresponding to the above, but it is not that easy to determine the numbers. 24MiB is quite large, but according to the flashbench mailing list there are flash drives with 6 MiB or 12 MiB erase block sizes. I want to make sure that at least my partitions are aligned without always performing a test with flashbench.

So, if I begin my first partition on the 49152nd + 1 (so it begins right at the "second 24MiB part") 512-byte sector, than is that partition also aligned to 1,2,4,6,8 and 12 MiB? (And so forth, for example to 128k, because (24*1024)/128 is an integer number)

1
  • 1
    Sounds like that is how it should work according to basic math and what I know about partitioning, but I've never actually tried this, so there may be some hidden complexity.
    – David
    Commented Nov 13, 2013 at 18:46

2 Answers 2

5
+50

Although I have no first-hand knowledge of flash card electronics, let me try to detail my understanding of the subject.

First, aligning to 24 MB does align to all its sub-multiples. But whether this is useful is another question.

Second, aligning the partitions to the erase block may make you feel better, but what is important is actually the alignment of the files within the file-system. As the file-system starts with its own internal tables, one has to force them to take up a multiple of the size of the erase block, which is a far from a trivial exercise. Aligning the file-system is therefore your next task after aligning the partition.

For example, read the struggle of Theodore Ts'o to achieve this for his SSD disk :
Aligning filesystems to an SSD’s erase block size.

Third, the term of "erase block" and its applicability to any particular flash drive is in reverse proportion to the intelligence of the flash disk controller. Modern flash controllers are getting smarter and even using compression, so the idea that the operating system does know what is going on under the hood with that drive may be just a fiction that may rather apply to the cheaper or older drives.

Fourth, block sizes are a function of the fabrication technology. The AnandTech article Micron Announces 16nm 128Gb MLC NAND, SSDs in 2014 has this interesting summary table, where block size goes from 512KB up to 8MB :

image

Fifth, some memory technologies use N-state "bits" called cells, so that one physical cell may contain 1.5 or 2 logical bits or more. The controller, again, does the job of translating this to terms that the operating system can understand, which is of course pure fiction.

The article Flash memory card design has this to say :

In all SLC and MLC flash, the erase block size is a power-of-two size. In TLC flash (Also known as MLC3, three-bit MLC, 8LC, or eight-level cell), there are two possible layouts: An erase block can have either three power-of-two sections, resulting in a total size of e.g. 1.5MB or 3 MB, or it can have a non-power-of-two number of pages for each level, 43+43+42 pages for a total of 128 pages per erase block.

Read this article to find out more about how flash disks report to the operating system information that is basically false.

Conclusion: In the current jungle of evolving technologies there is no way to reliably compute the real size of the erase block. Tools like flashbench may be the only reliable way around for calculating that value, but the results may be false for more evolved flash disks. Imagine for example flashbench writing a block of 64MB zeroes that the flash controller compresses into a few KBs, therefore flashbench actually really measuring the transfer rate to the device.

In my own opinion, as partition alignment is counted as a "good" thing to do, 4 MB is enough (8 MB may be better for newer disks by the end of 2014), and I wouldn't bother myself with more. If in doubt, use flashbench, but keep an open mind as to the validity of the results. Weird sizes reported by flashbench are probably the result of translations and optimizations done by the flash controller on the flash disk.

0
1

Yes, every whole number is an integer multiple of all it's dividers.

24 MiB = 24 ⋅ 220 B = 2 ⋅ 4 ⋅ 3 * 224 B = 3 ⋅ 227 B = 3 ⋅ 218 ⋅ 512 B

There are your prime dividers for 24 MiB split into units of 512 bytes. More specifically, every block beginning at a multiple of 24 MiB will also begin at a multiple of 12 MiB, 8 MiB, 6 MiB, 4 MiB, 2 Mib, 1 MiB and 512 KiB.

Now for your exemplary question: 49152 = 3 ⋅ 214, which divides 3 ⋅ 218. Therefore my above statement applies for the 49152th block of 512 bytes.

Edit: I only did some math here. As you can see from the other answer(s), the technical side of your problem is a lot more complicated.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .