Rob Browning <
r...@defaultvalue.org> writes:
> Greg Troxel <
g...@lexort.com> writes:
>
>> I had a dim memory of this, so I rewrote a separable test case. This
>> run is on NetBSD 10.
>>
>> $ sh -x _test
>> + rm -rf DIR
>> + mkdir DIR
>> + du -k DIR
>> 1 DIR
>> + dd if=/dev/zero of=DIR/SPARSE bs=1k count=8 seek=1024
>> 8+0 records in
>> 8+0 records out
>> 8192 bytes transferred in 0.001 secs (8192000 bytes/sec)
>> + du -k DIR
>> 1 DIR
>> + sync
>> + sleep 30
>> + du -k DIR
>> 131 DIR
>
> Hmm, why check the size of DIR and not just SPARSE?
No good reason, and I don't think it will matter because it's just
adding the dir size to the file size.
> To date when working on sparseness, I've only been concerned with
> individual files' "apparent size" (for GNU du, --apparent-size, and
> presumably also ls -l or stat's value) vs "device usage" (du's normal
> result).
I suggest avoiding assuming du is GNU du. But ls -l and stat should
match.
>> I believe we have a "if zfs, wait" stanza someplace else already for
>> maybe this very reason.
>
> We do, after earlier experiences with zfs, in an attempt to accommodate
> the behavior there.
OK, great.
> And overall, were you just saying that you saw sparseness with your
> system and zfs?
Yes, I am saying that. I fixed my test program to run du directly on
the sparse file.
I am writing 8 1k blocks, 8192 blocks into the file. So there are 8
blocks used of actual data, plus blocks used to store pointers and
information about the hole, in a FS-dependent, can't say it's wrong from
outside, kind of way.
~/SPARSE > sh -x _test
+ rm -rf DIR
+ mkdir DIR
+ cd DIR
+ dd if=/dev/zero of=SPARSE bs=1k count=8 seek=8192
8+0 records in
8+0 records out
8192 bytes transferred in 0.001 secs (8192000 bytes/sec)
+ ls -l
total 1
-rw-r--r-- 1 gdt users 8396800 Aug 13 19:16 SPARSE
+ du -k SPARSE
1 SPARSE
+ sync
+ sleep 30
+ ls -l
total 131
-rw-r--r-- 1 gdt users 8396800 Aug 13 19:16 SPARSE
+ du -k SPARSE
131 SPARSE
~/SPARSE > dc
10k
8396800 1024/p
8200.0000000000
Size: The file takes up 8200 * 1024 bytes, but uses 131 1K blocks of
storage, says du.
Timeliness: Somehow, after writing the file, but before sync, du says it
takes 1 block. That's probably because there is an uncommitted journal
entry (well, committed to the journal) for the new bits, and du may
operate on the committed fs, and then when a new root pointer is written
to commit the journal to the fs, du sees that. A deep zfs mystery
lurks, but the bottom line for bup testing is:
need to wait after writing, before du reflects the values that it will
have long term. (minutes later, it remains 131)
du on UFS or extN (?) may only reflect data blocks and not indirect
blocks, and du on zfs may be different. We could either have a "< 150
is pass" for now, or we could have a table of fs type and values.
NetBSD's tmpfs does not do sparse. Same test, du -k says 8200 blocks.
NetBSD's UFS2 (ffs) does sparse. Same test, 48, so 8 for the manifest
zeros and 40 for ?, probably indirect blocks and lists of block numbers
that code for fictitious-zero-block.
$ sh ~/SPARSE/_test
8+0 records in
8+0 records out
8192 bytes transferred in 0.001 secs (8192000 bytes/sec)
total 48
-rw-r--r-- 1 gdt wheel 8396800 Aug 13 19:24 SPARSE
48 SPARSE
total 48
-rw-r--r-- 1 gdt wheel 8396800 Aug 13 19:24 SPARSE
48 SPARSE