Date: Thu, 13 Jan 2022 22:19:36 -0500 From: "Kevin P. Neal" <kpn@neutralgood.org> To: "Greg 'groggy' Lehey" <grog@freebsd.org> Cc: David Christensen <dpchrist@holgerdanske.com>, freebsd-questions@freebsd.org Subject: Re: zero filling a storage device (was: dd and mbr) Message-ID: <YeDryNdYe1S20wd2@neutralgood.org> In-Reply-To: <20220114023002.GP61872@eureka.lemis.com> References: <77680665-7ddb-23c5-e866-05d112339b60@holgerdanske.com> <20220114023002.GP61872@eureka.lemis.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jan 14, 2022 at 01:30:02PM +1100, Greg 'groggy' Lehey wrote: > 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. Are we certain that an SSD won't at least track that there is nothing written to a logical block and therefore it must be all zeros? I'm not 100% that an SSD will always keep a logical block assigned to a physical block. And I'm not 100% certain that an SSD won't notice that all zeros are being written to a block and just optimize out the write. -- Kevin P. Neal http://www.pobox.com/~kpn/ "What is mathematics? The age-old answer is, of course, that mathematics is what mathematicians do." - Donald Knuth
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YeDryNdYe1S20wd2>