From nobody Fri Jan 14 02:30:02 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 40B6B1942DD1 for ; Fri, 14 Jan 2022 02:30:12 +0000 (UTC) (envelope-from grog@lemis.com) Received: from lax.lemis.com (www.lemis.com [45.32.70.18]) by mx1.freebsd.org (Postfix) with ESMTP id 4JZldG6d2Gz3tss for ; Fri, 14 Jan 2022 02:30:10 +0000 (UTC) (envelope-from grog@lemis.com) Received: from eureka.lemis.com (121-200-11-253.79c80b.mel.nbn.aussiebb.net [121.200.11.253]) by lax.lemis.com (Postfix) with ESMTP id 59C0128083; Fri, 14 Jan 2022 02:30:03 +0000 (UTC) Received: by eureka.lemis.com (Postfix, from userid 1004) id A23CC2635C0; Fri, 14 Jan 2022 13:30:02 +1100 (AEDT) Date: Fri, 14 Jan 2022 13:30:02 +1100 From: Greg 'groggy' Lehey To: David Christensen Cc: freebsd-questions@freebsd.org Subject: Re: zero filling a storage device (was: dd and mbr) Message-ID: <20220114023002.GP61872@eureka.lemis.com> References: <77680665-7ddb-23c5-e866-05d112339b60@holgerdanske.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: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DBUa/BSa4z6QPQv1" Content-Disposition: inline In-Reply-To: <77680665-7ddb-23c5-e866-05d112339b60@holgerdanske.com> Organization: The FreeBSD Project Phone: +61-3-5309-0418 Mobile: +61-490-494-038. Use only as instructed. WWW-Home-Page: https://www.FreeBSD X-PGP-Fingerprint: 9A1B 8202 BCCE B846 F92F 09AC 22E6 F290 507A 4223 User-Agent: Mutt/1.6.1 (2016-04-27) X-Rspamd-Queue-Id: 4JZldG6d2Gz3tss X-Spamd-Bar: ++ Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of grog@lemis.com has no SPF policy when checking 45.32.70.18) smtp.mailfrom=grog@lemis.com X-Spamd-Result: default: False [2.20 / 15.00]; R_SPF_NA(0.00)[no SPF record]; ARC_NA(0.00)[]; FREEFALL_USER(0.00)[grog]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_SPAM_SHORT(1.00)[0.999]; MIME_GOOD(-0.20)[multipart/signed,text/plain]; DMARC_NA(0.00)[FreeBSD.org]; AUTH_NA(1.00)[]; NEURAL_SPAM_MEDIUM(1.00)[1.000]; HAS_ORG_HEADER(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_SPAM_LONG(1.00)[1.000]; MLMMJ_DEST(0.00)[freebsd-questions]; FORGED_SENDER(0.30)[grog@FreeBSD.org,grog@lemis.com]; RCVD_NO_TLS_LAST(0.10)[]; SIGNED_PGP(-2.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ASN(0.00)[asn:20473, ipnet:45.32.64.0/19, country:US]; FROM_NEQ_ENVFROM(0.00)[grog@FreeBSD.org,grog@lemis.com]; RCVD_COUNT_TWO(0.00)[2] X-ThisMailContainsUnwantedMimeParts: N --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--