From nobody Fri Nov 08 01:08:45 2024 X-Original-To: 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 4Xl16X2wCPz5cyW2 for ; Fri, 08 Nov 2024 01:08:52 +0000 (UTC) (envelope-from grog@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xl16X0kNMz4WvS; Fri, 8 Nov 2024 01:08:52 +0000 (UTC) (envelope-from grog@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731028132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OfgpP9fvDTmIi2IqA9PDqSKgq0aM2XnAQqWj2j1J4Uc=; b=uMWpEUSgYTPo8o+1WrTqxjNAunTLnSyQ7A24eOAijrniVnoWSjbpA1Y6ySbl+5IdsML7gU RJWrNwyH5j+leirGuU95ks8pqv/NJL3Zg15V6oPAHBqO/AJ0Z7npcGHgxpb8IuiyhI/7DU 2Eu/VEWayYPEAE4ilIq4vAYj4ZyqWtOwZ0eMngZltw7vX72kuDEn0sMyjn/kFjk0IRt1AW pyJqVpbxvrj6IgW4iyMhEafPauzBiyr43QSKW+EcPHTpcj6kS6mwS1Vmmqhj1OGM/rFC6f 15f1veuO1y/yOAjY/nS5RHcfjmDFVCSMp6w62MVXCfXiEErs7Fz+F3/GVojunA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731028132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OfgpP9fvDTmIi2IqA9PDqSKgq0aM2XnAQqWj2j1J4Uc=; b=k9YW6pj4zEMR0y+bBJiuc5KCaSvOqn2yICS91j0LaPXXR8ibNCKj4zIO46lrp8+2J7PtCZ V5hgzNCLh24mRNHxz849ma5Gk9sI86N8pi7RsoQgvpv0T6eAVI+9bFhuZicQlcDOXMe7aO xKYH8OdJgGbSl7/SnkbuUzsbkQmd1XRC6rY3DiIvU5oC/cv1UrJpBTJZ5Js4/Ec7gERUgD AEaVGpT0ttpzwnqJvI+OfDjlXvEUD8J2ilqfCOjmwJEChNX/eUjRh8Rs++koj+Q/UrVQj2 Gx75UXLIBO0jjvBGEwqUPJxn9o+F1AMCj/hC4x2ympfBor83AqpVEOmOezTOMg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731028132; a=rsa-sha256; cv=none; b=A1zBSRdBvYsVuz5AJIxlivsBAtMXvTx+lzi8GPi2luIET0oH3GXAg9wQG6SvV7ZUzvW0Qv zS9gI53PkV6NyGFBtgiWACHXAgGHPJ0Ikayuy1BsXFpDmjQYziTH7VnFCwb7HxhXgvP4t9 wP7mNmVWPj85YReRj8kWVWS942TqTFDUxfMqdlE4kreGBRln/kX+F51f6FZqwO0oPbcgan N6RWci5yYehiYzrHmAuZ8xRSBCrHCEi4p7KXKHtCU0At2GBTdEZT6XSe9dIBWKDRvND2Kd bLKc9ssQHBp6EpdPsJ1f5RtFBLjjhfmlMZ8kNgRweu86kyNHWveZnekllDgcOA== Received: from hydra.lemis.com (121-200-11-253.79c80b.mel.nbn.aussiebb.net [121.200.11.253]) (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 did not present a certificate) (Authenticated sender: grog/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4Xl16V6PplzMVc; Fri, 8 Nov 2024 01:08:50 +0000 (UTC) (envelope-from grog@freebsd.org) Date: Fri, 8 Nov 2024 12:08:45 +1100 From: Greg 'groggy' Lehey To: Dewayne Geraghty Cc: questions@freebsd.org Subject: Re: du measures in 4K blocks resulting in inaccuracies Message-ID: References: <8a3381ec-d67c-4e51-85d9-e323ec3465fe@heuristicsystems.com.au> List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: freebsd-questions@freebsd.org Sender: owner-freebsd-questions@FreeBSD.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="TD+sozSl5JphGD4d" 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 --TD+sozSl5JphGD4d Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thursday, 7 November 2024 at 15:46:09 +1100, Dewayne Geraghty wrote: > On 7/11/2024 12:24 pm, Greg 'groggy' Lehey wrote: >> On Thursday, 7 November 2024 at 12:01:36 +1100, Dewayne Geraghty wrote: >>> What am I missing? Should the doc reflect the minimum reporting size is 4K? >> >> No, du is reporting correctly. From the man page: ... Oh. Yes, I missed the 4.1k instead of 4.0K, along with this in the original message: > but even --si gives > 4.1k /projectx/adm/README # <<< 4.1K??! > 4.1k /projectx/adm/gen_pw.sh "Even" --si. I had never heard of it. It doesn't look BSD-like at all, and I see it was added in August 2017. Maybe it's a Linuxism. In any case, the man page is your friend there too: --si "Human-readable" output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte based on powers of 1000. And that works as described: === grog@hydra (/dev/pts/11) /var/tmp 558 -> echo foo > bar === grog@hydra (/dev/pts/11) /var/tmp 559 -> ls -l bar -rw-r--r-- 1 grog wheel 4 8 Nov 10:34 bar === grog@hydra (/dev/pts/11) /var/tmp 560 -> du -sk bar 4 bar === grog@hydra (/dev/pts/11) /var/tmp 561 -> du --s bar 4.1k bar Note the distinction between k (1000 bytes) and K (1024 bytes). > Large files are a bit confusing: > The file ./src-ports-migration.tar.xz is 11787028, but > du reports as 11552 while > 11787028 / 1024 = 11510. > > I think I need to read the code to understand, perhaps the inode > occupies 42? Interesting. No, the inode is not counted in the du output (and it's 512 bytes long). But it seems that the indirect blocks are, and I can't find that documented anywhere. Consider: === grog@hydra (/dev/pts/35) /var/tmp 3 -> dd if=/dev/zero of=baz bs=384k count=1; ls -l baz; du -sk baz 393216 bytes transferred in 0.000208 secs (1893921588 bytes/sec) -rw-r--r-- 1 grog wheel 393216 8 Nov 11:59 baz 384 baz === grog@hydra (/dev/pts/35) /var/tmp 4 -> dd if=/dev/zero of=baz bs=385k count=1; ls -l baz; du -sk baz 394240 bytes transferred in 0.000375 secs (1052038886 bytes/sec) -rw-r--r-- 1 grog wheel 394240 8 Nov 11:59 baz 448 baz The first 12 block pointers (to data blocks of 32 kB each) are in the inode. Beyond that they're in indirect blocks. So a 385 kB file has 13 data blocks (416 kB) and one indirect block (32 kB). This continues for all larger files, though at some point second and third level indirect blocks are assigned, giving steps of 64 or 96 kB. Thanks for bringing this to my attention. I'll try to find a way to document it. 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 --TD+sozSl5JphGD4d Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQSaG4ICvM64RvkvCawi5vKQUHpCIwUCZy1knQAKCRAi5vKQUHpC I5AYAJ9mCFV9ZSxk5Q6JRQ9Udgb5T7FxHACfWIFwme4xASDyFIvGZWAEFKbkqGw= =oY0/ -----END PGP SIGNATURE----- --TD+sozSl5JphGD4d--