From nobody Fri Jan 14 04:55:58 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 883FC195E1C6 for ; Fri, 14 Jan 2022 04:56:01 +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 4JZpsX3xFFz3vD9 for ; Fri, 14 Jan 2022 04:56:00 +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 48359280EB; Fri, 14 Jan 2022 04:55:59 +0000 (UTC) Received: by eureka.lemis.com (Postfix, from userid 1004) id 95EFB2635C0; Fri, 14 Jan 2022 15:55:58 +1100 (AEDT) Date: Fri, 14 Jan 2022 15:55:58 +1100 From: Greg 'groggy' Lehey To: "Kevin P. Neal" Cc: David Christensen , freebsd-questions@freebsd.org Subject: Re: zero filling a storage device (was: dd and mbr) Message-ID: <20220114045558.GQ61872@eureka.lemis.com> 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: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="eLe8FOcWSbbyMVJD" Content-Disposition: inline In-Reply-To: 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: 4JZpsX3xFFz3vD9 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)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; NEURAL_SPAM_SHORT(1.00)[1.000]; 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)[]; 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 --eLe8FOcWSbbyMVJD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thursday, 13 January 2022 at 22:19:36 -0500, Kevin P. Neal wrote: > 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: >>> 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? We're talking about physical blocks here. I have to guess that you're thinking about the block remapping that SSDs do, but I've never heard them called "logical" and "physical". Writing all zeroes to a physical block and writing nothing to a physical block are two very different things. Writing nothing doesn't change anything. Writing zeroes to a block with content will change it. > 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. If I understand what you mean here, you're suggesting that SSDs may keep a list of zeroed-out blocks and just optimize them away? It's possible, though I haven't heard of it. I don't know how often blocks are completely zeroed out, but I suspect that it wouldn't be worth it. If they did, it would be a good advertisement, because it would indirectly increase the storage capacity of the SSD. Until proof of the contrary, I'd say "no, this doesn't happen". Greg -- 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 --eLe8FOcWSbbyMVJD Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iEYEARECAAYFAmHhAl4ACgkQIubykFB6QiNTegCgr3Bdv5rOqnlJ0KrHf161+0BQ f/wAmwRj3IisjZhhcyCNvpB1l85PIrvp =cgVs -----END PGP SIGNATURE----- --eLe8FOcWSbbyMVJD--