From nobody Fri Jan 14 03:19:36 2022 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 8E95E193CC42 for ; Fri, 14 Jan 2022 03:19:38 +0000 (UTC) (envelope-from kpn@neutralgood.org) Received: from gunsight1.neutralgood.org (gunsight1.neutralgood.org [IPv6:2607:f758:2280:1:d6be:d9ff:feac:a1e9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "gunsight1.neutralgood.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JZmkK4xtPz4lRv; Fri, 14 Jan 2022 03:19:37 +0000 (UTC) (envelope-from kpn@neutralgood.org) Received: from gunsight1.neutralgood.org (localhost [127.0.0.1]) by gunsight1.neutralgood.org (8.16.1/8.15.2) with ESMTPS id 20E3Jamm045429 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 13 Jan 2022 22:19:37 -0500 (EST) (envelope-from kpn@gunsight1.neutralgood.org) Received: (from kpn@localhost) by gunsight1.neutralgood.org (8.16.1/8.15.2/Submit) id 20E3JaxG045426; Thu, 13 Jan 2022 22:19:36 -0500 (EST) (envelope-from kpn) Date: Thu, 13 Jan 2022 22:19:36 -0500 From: "Kevin P. Neal" To: "Greg 'groggy' Lehey" Cc: David Christensen , freebsd-questions@freebsd.org Subject: Re: zero filling a storage device (was: dd and mbr) Message-ID: References: <77680665-7ddb-23c5-e866-05d112339b60@holgerdanske.com> <20220114023002.GP61872@eureka.lemis.com> List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220114023002.GP61872@eureka.lemis.com> X-No-archive: Yes X-Rspamd-Queue-Id: 4JZmkK4xtPz4lRv X-Spamd-Bar: ++ Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of kpn@neutralgood.org designates 2607:f758:2280:1:d6be:d9ff:feac:a1e9 as permitted sender) smtp.mailfrom=kpn@neutralgood.org X-Spamd-Result: default: False [2.70 / 15.00]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_SPF_ALLOW(-0.20)[+mx:c]; NEURAL_SPAM_SHORT(1.00)[0.999]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[neutralgood.org]; TO_DN_SOME(0.00)[]; NEURAL_SPAM_MEDIUM(1.00)[1.000]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_SPAM_LONG(1.00)[1.000]; MLMMJ_DEST(0.00)[freebsd-questions]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:13649, ipnet:2607:f758::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N 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