Gentoo Archives: gentoo-user

From: Fernando Rodriguez <frodriguez.developer@×××××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] [OT]: Optimal formatting a SDcard (64GB) with partions of diffent sizes and filesystems?
Date: Fri, 07 Aug 2015 21:20:20
Message-Id: BLU436-SMTP1764EEA015F58D7925774D78D730@phx.gbl
In Reply to: Re: [gentoo-user] [OT]: Optimal formatting a SDcard (64GB) with partions of diffent sizes and filesystems? by Mick
1 On Friday, August 07, 2015 7:01:29 PM Mick wrote:
2 > On Friday 07 Aug 2015 04:27:15 Fernando Rodriguez wrote:
3 > > On Thursday, August 06, 2015 6:18:59 PM Meino.Cramer@×××.de wrote:
4 > > > Hi,
5 > > >
6 > > > for my tablet PC I used a used 32GB FAT32 formatted SDcard. The
7 > > > formatting was already done by the manufacturer.
8 > > > Then I screwed it up and had to do the partioning and formatting
9 > > > myself again. "No big deal", I thought -- and was wrong.
10 > > > Yes, the "thing" I got could be read and written. But it was
11 > > > DAMN slow in comparison to the original formatting.
12 > > >
13 > > > I googled and found a description, which described exactly,
14 > > > what I wanted: An optimal formatting for one big FAT32 partion.
15 > > > I did it again ;) and: TADA! The speed was back.
16 > > > LINK:http://zero1-st.blogspot.de/2012/05/formatting-fat32-volumes-larger-> > than.html
17 > > >
18 > > > Now I need the something identical but explained in a way
19 > > > that it can be successfully applied to any partion layout
20 > > > and any SDcard size.
21 > > > Currently the new SDcard has 64GB (yes, the tablet eats that size
22 > > > well :) and needs at least two partions: One FAT32 and one ext4.
23 > > > May be that I need a different layout later.
24 > > >
25 > > > To what aspect and "logic" do I have to keep my eyes on, when
26 > > > it comes partioning/formatting any SDcard size with any partion
27 > > > layout and any filesystem?
28 > > >
29 > > > Thank you very much in advance for any help!
30 > > > Best regards,
31 > > > Meino
32 > >
33 > > I wrote a long reply to this and it appears to have been swallowed by
34 > > /dev/null.
35 > >
36 > > SD cards don't have 128K blocks. Except for the very early ones (standard
37 > > capacity), they are divided in allocation units (AU) that are 1MB to 4MB
38 > > for SDHC and even larger for SDXC. The only way to get that value is by
39 > > reading a register in the card (so you can't do it in usermode on linux).
40 > >
41 > > The AUs are divided into Recording Units (RUs). The size of these can be
42 > > deduced from the card speed class (that's the number inside the C on the
43 > > label), and the card capacity. For class 2 and 4 if the card is less than
44 > > 1GB it's 16KB, otherwise it's 32KB. For class 6 it is 64KB, and for class
45 > > 10 it's 512KB.
46 > >
47 > > After an AU is erased you can write to any of the free RUs in any order in
48 > > blocks of 512 bytes sequentially (the block size is configurable by the
49 > > driver but 512 is the most common). But if you write to a nonfree RU then
50 > > all non- free RU get copied to a new AU. So the performance hit depends on
51 > > how many non-free RUs are in the AU when this happens.
52 > >
53 > > So to get the best performance you need to align the first FAT cluster on
54 > > an AU boundary and that the RUs used by the reserved sectors after the FAT
55 > > are free. This is not so easy from usermode because you can't get the AU
56 > > size and you can't erase the AU to make sure reserved sectors are free.
57 > > The Windows 7 and later format utility will do it if you don't partition
58 > > the card. The next best thing is to align it to an RU which should be
59 > > pretty easy.
60 > >
61 > > You could guess the AU size by writting blocks of RU size from the start
62 of
63 > > the card and timing it. Every time you hit the AU boundary there will be a
64 > > longer delay.
65 > >
66 > > For more details see the SD specification (chapter 4.13).
67 > >
68 > > https://www.sdcard.org/downloads/pls/
69 > >
70 > > They also have formatter tools for Windows and OSX. I tried the Windows
71 > > version years ago but had problems with it (can't remember what).
72 >
73 > Excellent information Fernando, thank you!
74 >
75 > So there is no tool for me to use to read the AU/RU on the chip?
76 >
77 >
78
79 The RU can be calculated from the card size and speed class, that's the number
80 printed on the card label inside the C. I don't know of any tools to get the
81 AU and it looks like it's not exported to userspace so any such tool would
82 have to guess it. However, if you want to hack your kernel all it takes is one
83 line on /usr/src/linux/drivers/mmc/core/debugfs.c. Add the following towards
84 the end of mmc_ios_show before the return statement:
85
86 seq_printf(s, "au (sectors):\t%u\n", host->card->ssr.au);
87
88 then you can do:
89
90 cat /sys/kernel/debug/mmc0/ios
91
92 Multiply the value by 512 to get the size in bytes. It can be up to 64MB.
93
94
95
96 --
97 Fernando Rodriguez

Replies