I experienced the same problem with the mke2fs utility hanging at the point where it makes the ioctl call to perform the BLKDISCARD. With my situation, the ioctl call never returns. I verified this by letting it sit for 15 hours (overnight) and it never completed the BLKDISCARD operation. For comparison, if I fill up the device with all zeros, by cat'ing "/dev/zero" into it, it only takes 24 minutes to complete.
Here are some details about by environment:
Processor: i.MX6 Quad Core
DDR: 2GB
Kernel version: 3.0.35
OS: Android JellyBean 4.2.2
Our system is setup to load the bootloaders from NAND and then everything else from an 8GB eMMC chip (attached to SD1). We also use a removable micro SD card (attached to SD2) as a mass storage device. The SD card is a Kingston 16GB micro SD card with a rating of 45 MB/sec read and 10-12 MB/sec write.
So far, I haven't had any problem formatting the partitions on the eMMC chip. And I didn't used to have any problems formatting the partitions on the SD card with an older batch of the Kingston 16GB SD cards. The problem only started to happen with the latest batch of Kingston 16GB SD cards that we purchased.
NOTE: The newer Kingston 16GB SD cards are slightly smaller in size (15.7 GB) than the older 16GB cards (which were 16.0 GB).
I've noticed 2 seemingly unusual factors involved in whether I experience the hang in the BLKDISCARD operation:
1) I have 2 partitions on the device and I only experience the hang when formatting the 2nd partition.
We partition our SD card into 2 partitions. The first partition is 2GB and the second takes up the remainder of the space (roughly 14GB). And we format both partitions as ext4 using the mke2fs utility. I was originally using the default options for mke2fs with the exception of using "-T" to specify an ext4 filesystem and "-L" to specify a volume label.
I find it odd that the 1st partition would not also experience the problem. It might have made some sense if the 2nd partition was larger than it had been on the older SD cards. Because, then, it might have been related to some sort of size limit. But, with the newer SD cards, the 2nd partition is actually smaller.
2) If I wipe the master boot record (first 512 bytes) on the SD card, prior to partitioning and formatting it, then I don't experience the hang when using mke2fs.
By wiping the first 512 bytes, I wind up losing the original disk configuration and so a default configuration winds up getting assigned. The following shows the difference between the original disk configuration and the default disk configuration:
---------------------------
Original disk configuration
---------------------------
root@android:/ # fdisk -l /dev/block/mmcblk1
Disk /dev/block/mmcblk1: 15.7 GB, 15720251392 bytes
255 heads, 63 sectors/track, 1911 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/block/mmcblk1p1 1 250 2008093+ 83 Linux
/dev/block/mmcblk1p2 251 1911 13341982+ 83 Linux
---------------------------------------
Disk configuration after wiping the MBR
---------------------------------------
root@android:/ # fdisk -l /dev/block/mmcblk1
Disk /dev/block/mmcblk1: 15.7 GB, 15720251392 bytes
4 heads, 16 sectors/track, 479744 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Device Boot Start End Blocks Id System
/dev/block/mmcblk1p1 1 62501 2000024 83 Linux
/dev/block/mmcblk1p2 62502 479744 13351776 83 Linux
You can see that wiping the MBR causes the number of heads, sectors per track, and cylinder size to change. After these changes, I no longer experience the hang while doing the BLKDISCARD.
CONCLUSION:
The recommended work-around, of passing the "-E nodiscard" option to the mke2fs command, is working for me.
I imagine it is less interesting to everyone else that I am encountering this problem with JellyBean 4.2.2 and the 3.0.35 kernel. However, we are looking at moving to a newer BSP (newer version of Android and the kernel). So I am wondering if there is a definitive answer on which kernel version provides the fix for this problem.
Holger mentioned that it is fixed in the 3.16 kernel but it is not clear which SUBLEVEL (minor) version of the kernel has the fix since his original problem statement reports states that he was running 3.16.3.
I imagine it is possible that Holger was actually having the problem on an older kernel version and later realized that 3.16.3 didn't have the problem. If that is the case, then does anyone know if the 3.10.53 kernel might also have the fix?