Date: Fri, 14 Jan 2022 13:30:02 +1100 From: Greg 'groggy' Lehey <grog@FreeBSD.org> To: David Christensen <dpchrist@holgerdanske.com> Cc: freebsd-questions@freebsd.org Subject: Re: zero filling a storage device (was: dd and mbr) Message-ID: <20220114023002.GP61872@eureka.lemis.com> In-Reply-To: <77680665-7ddb-23c5-e866-05d112339b60@holgerdanske.com> References: <77680665-7ddb-23c5-e866-05d112339b60@holgerdanske.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--DBUa/BSa4z6QPQv1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thursday, 13 January 2022 at 17:26:12 -0800, David Christensen wrote: > On 1/11/22 2:02 AM, Roderick wrote: >> dd if=/dev/zero of=/dev/da0 > > > On 1/13/22 12:32 AM, Roderick wrote: >> >> On Thu, 13 Jan 2022, Greg 'groggy' Lehey wrote: >> >>> As others have suggested, use bs=64k. Otherwise dd does an IO for >>> every single sector. The speedup is really in the order of 100x. >> >> I used bs=1m. I hope that was also OK. In any case faster than >> without it. Yes, that's fine. If the block size is larger than the maximum that the disk can handle, the system divides it into smaller transfers. > Suppose I have a storage device with M blocks of size B bytes each. > Some of the blocks contain non-zero bytes and other blocks contain only > zero bytes. > > Suppose I have a program with a memory buffer of N blocks filled with > zero bytes, where N < M. > > If the program writes the buffer to the storage device starting at > block-aligned location P, where P + N * B <= M * B, will the storage > device write zero bytes to the storage device blocks that already > contain only zero bytes? Yes. The storage device doesn't know the current contents of the disk. To do so it would first have to read them, which takes far too long. > Is the answer different for a HDD, an SSD, a USB flash drive, an SD > card, a compact flash card, etc.? No. It's also not different for other operating systems. Greg -- When replying to this message, please copy the original recipients. If you don't, I may ignore the reply or reply to the original recipients. For more information, see http://www.lemis.com/questions.html Sent from my desktop computer. See complete headers for address and phone numbers. This message is digitally signed. If your Microsoft mail program reports problems, please read http://lemis.com/broken-MUA.php --DBUa/BSa4z6QPQv1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iEYEARECAAYFAmHg4CoACgkQIubykFB6QiPe2gCdG3qtOJAGYQBDFQk+XPn18UMC Bg0AmgN0C6sJgB4USoepKq9oK9BYwJZO =xfus -----END PGP SIGNATURE----- --DBUa/BSa4z6QPQv1--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20220114023002.GP61872>