On 2017/1/23 上午2:01, Avi Kivity wrote: > Hello, > > > On 11/27/2016 05:24 PM, Avi Kivity wrote: >> mkfs /dev/md0 can take a very long time, if /dev/md0 is a very large >> disk that supports TRIM/DISCARD (erase whichever is inappropriate). >> That is because mkfs issues a TRIM/DISCARD (erase whichever is >> inappropriate) for the entire partition. As far as I can tell, md >> converts the large TRIM/DISCARD (erase whichever is inappropriate) >> into a large number of TRIM/DISCARD (erase whichever is inappropriate) >> requests, one per chunk-size worth of disk, and issues them to the >> RAID components individually. >> >> >> It seems to me that md can convert the large TRIM/DISCARD (erase >> whichever is inappropriate) request it gets into one TRIM/DISCARD >> (erase whichever is inappropriate) per RAID component, converting an >> O(disk size / chunk size) operation into an O(number of RAID >> components) operation, which is much faster. >> >> >> I observed this with mkfs.xfs on a RAID0 of four 3TB NVMe devices, >> with the operation taking about a quarter of an hour, continuously >> pushing half-megabyte TRIM/DISCARD (erase whichever is inappropriate) >> requests to the disk. Linux 4.1.12. >> > > Did anyone pick this up by any chance? The only thing I could find is > more people complaining about the same issue. Hi Avi, I proposed a POC patch, Shaohua and Neil provide review comments, suggest me to simplify this patch. If you notice, there is a patch I sent out on Dec 9, 2016, in this email thread. This patch works, but not the final version to be accepted by upstream. I quote the performance number here, β€œ On 4x3TB NVMe raid0, format it with mkfs.xfs. Current upstream kernel spends 306 seconds, the patched kernel spends 15 seconds. I see average request size increases from 1 chunk (1024 sectors) to 2048 chunks (2097152 sectors).” I call this patch as RFC v2 patch, and attach it again in this email. Now I am working on a new version by the suggestion from Shaohua and Neil, but any testing feed back of RFC v2 patch is welcome. It works, just too complex to review. Thanks. Coly