2

Why is BTRFS so grossly misquoting the size of small files on my filesystem?

[pi@rpi scipy]% cat __init__.py | wc -c            # literal byte count
4729
[pi@rpi scipy]% du --apparent-size -h __init__.py  # size on filesystem (same)
4.7K    __init__.py
[pi@rpi scipy]% du -h __init__.py                  # reported size to ls
1.0M    __init__.py
  • Completely stock options (defaults, plain mkfs.btrfs)
  • Linux Kernel 3.18
  • RAID1

Okay, so it appaears that BTRFS is rounding files up to 1MB at some threshold. That 1MB is exactly 1048576 (or 2²⁰) bytes.

More surprisingly, cat __init__.py > __init__2.py makes a new file of the correct size. Does this have something to do with the fact that I created these files over samba?

Newly created files also have the correct size.

2
  • Third file is __init__.pyc. The first two seem correct. Commented Jun 1, 2015 at 21:56
  • Sure, but all small files in the filesystem weigh in at 1.0M, so that's unfortunately not the issue.
    – PythonNut
    Commented Jun 1, 2015 at 21:56

1 Answer 1

1

Turns out just rewriting all of the files in-place:

find . -type f -exec /usr/bin/echo {} \; -exec sed -i '' {} \;

Correctly shrank the files. I haven't seen it happen again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .