Skip to content

Unexpected writes using sparse + sparing #5

Description

@crass

Here's an example using 0.97 (also exhibited on debian's 0.95) on a BTRFS filesystem.

# ddpt if=/dev/urandom of=test seek=17,3,21,3,63,1
Assume logical block size of 512 bytes for both input and output
7+0 records in
7+0 records out
time to transfer data: 0.000213 secs at 16.83 MB/sec
# cp --reflink=always -a test{,.ssp}; ddpt if=test of=test.ssp bpt=512,1 bs=512 conv=sparse oflag=sparing
64+0 records in
7+0 records out
57 bypassed records out
time to transfer data: 0.271519 secs at 120.7 KB/sec
# filefrag -v test
Filesystem type is: 9123683e
File size of test is 32768 (8 blocks of 4096 bytes)
 ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        2..       2:    6298878..   6298878:      1:          2:
   1:        7..       7:    7504901..   7504901:      1:    6298883: last,eof
test: 2 extents found
# filefrag -v test.ssp
Filesystem type is: 9123683e
File size of test.ssp is 32768 (8 blocks of 4096 bytes)
 ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        2..       2:    7504902..   7504902:      1:          2:
   1:        7..       7:    7504903..   7504903:      1:             last,eof
test.ssp: 1 extent found

Here it can be seen that test.ssp contains differing extents from test, meaning that the extents that had been reflinked were written to. The files contents are identical so sparing appears to not be adhered to. If conv=sparse is removed, no writes are done.

Only on the website there is this documentation with respect to using sparse and sparing together:

It seems unlikely that it would be useful to have both sparse writes and write sparing active on the same OFILE. If they are both given (i.e. 'oflag=sparing,sparse') then sparse writes are checked first and if zeros are found, the check for write sparing is bypassed on that segment.

However, this only applies to when the input block is all zeroes. This implies that when a block not of all zeroes is found that the check for sparing is not skipped. What appears to be happening in this case is that the sparse check is failing, but the sparing check is not being done. Because if the sparing check had been done, no writes should occur.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions